Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions atlas/atlasAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ def get_observations_area_api(id_area):
connection, str(id_area)
)
else:
observations = vmObservationsRepository.getObservationsByArea(
connection, id_area, limit
)
observations = vmObservationsRepository.getObservationsByArea(connection, id_area, limit)

connection.close()
return jsonify(observations)
Expand Down
5 changes: 4 additions & 1 deletion atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ def index():

# si AFFICHAGE_TERRITOIRE_OBS on charge les données en AJAX
# si AFFICHAGE_DERNIERES_OBS = False, on ne charge pas les obs
if current_app.config["AFFICHAGE_TERRITOIRE_OBS"] or not current_app.config["AFFICHAGE_DERNIERES_OBS"]:
if (
current_app.config["AFFICHAGE_TERRITOIRE_OBS"]
or not current_app.config["AFFICHAGE_DERNIERES_OBS"]
):
observations = []
elif current_app.config["AFFICHAGE_DERNIERES_OBS"]:
if current_app.config["AFFICHAGE_MAILLE"]:
Expand Down
1 change: 1 addition & 0 deletions atlas/modeles/entities/vmObservations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class VmObservations(Base):
geojson_point = Column("geojson_point", Text)
cd_sensitivity = Column("cd_sensitivity", String(5))
id_dataset = Column("id_dataset", Integer)

def as_dict(self):
return {
"dateobs": str(self.dateobs),
Expand Down
17 changes: 12 additions & 5 deletions atlas/modeles/repositories/vmObservationsMaillesRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,30 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
session.query(
VmObservationsMailles.id_maille,
VmAreas.area_geojson,
func.max(extract("year", VmObservations.dateobs)).label("last_obs_year"),
func.count(VmObservations.id_observation).label("obs_nbr"),
VmObservationsMailles.type_code,
func.max(VmObservationsMailles.annee).label("last_obs_year"),
func.sum(VmObservationsMailles.nbr).label("obs_nbr"),
)
.join(
VmObservations,
VmObservations.id_observation == any_(VmObservationsMailles.id_observations),
)
.join(
VmAreas,
VmAreas.id_area == VmObservationsMailles.id_maille,
)
.filter(VmObservationsMailles.cd_ref == any_(taxons_ids))
.filter(VmObservations.cd_ref == any_(taxons_ids))
.group_by(
VmObservationsMailles.id_maille,
VmAreas.area_geojson,
VmObservationsMailles.nbr,
VmObservationsMailles.type_code,
)
)
if year_min and year_max:
query = query.filter(VmObservationsMailles.annee.between(str(year_min), str(year_max)))
query = query.filter(
VmObservations.dateobs.between(str(year_min) + "-01-01", str(year_max) + "-12-31")
)

return FeatureCollection(
[
Expand All @@ -122,7 +129,7 @@ def territoryObservationsMailles(connection):
json_build_object(
'type', 'FeatureCollection',
'features', json_agg(ST_AsGeoJSON(features.*)::json)
) AS observations_features
)
FROM (
SELECT
COUNT(o.id_observation) AS nb_observations,
Expand Down
4 changes: 2 additions & 2 deletions atlas/modeles/repositories/vmObservationsRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def getObservationsByArea(connection, id_area, limit):
ORDER BY o.dateobs DESC """
if limit:
sql += "LIMIT :obsLimit"
observations = connection.execute(text(sql), {"obsLimit":limit, "id_area":id_area})

observations = connection.execute(text(sql), {"obsLimit": limit, "id_area": id_area})
obsList = list()
for o in observations:
temp = {
Expand Down
34 changes: 12 additions & 22 deletions atlas/static/mapAreas.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,9 @@ function displayObsTaxon(id_area, cd_ref) {
clearOverlays()
} else {
map.removeLayer(currentLayer);
if (configuration.AFFICHAGE_MAILLE) {
displayMailleLayerLastObs(observations);
clearOverlays()
} else {
map.removeLayer(currentLayer);
displayMarkerLayerPointArea(observations);
}
displayMarkerLayerPointArea(observations);
}
})
});
}

function displayObs(id_area) {
Expand Down Expand Up @@ -152,22 +146,18 @@ function displayObsTaxonMaille(areaCode, cd_ref) {
}

function refreshObsArea(elem) {
$("#taxonList ul").on("click", "#taxonListItem", function () {
document.querySelector("#taxonList .current")?.classList.remove("current")
elem.currentTarget.classList.add("current")
if (configuration.AFFICHAGE_MAILLE) {
displayObsTaxonMaille(this.getAttribute("area-code"), this.getAttribute("cdref"));
} else {
displayObsTaxon(this.getAttribute("area-code"), this.getAttribute("cdref"));
}
var name = $(this)
.find("#name")
.html();
$("#titleMap").fadeOut(500, function () {
$(this)
.html("Observations du taxon : " + name)
.fadeIn(500);
});
if (configuration.AFFICHAGE_MAILLE) {
displayObsTaxonMaille(elem.currentTarget.getAttribute("area-code"), elem.currentTarget.getAttribute("cdref"));
} else {
displayObsTaxon(elem.currentTarget.getAttribute("area-code"), elem.currentTarget.getAttribute("cdref"));
}
const name = elem.currentTarget.querySelector("#name").innerHTML;
$("#titleMap").fadeOut(500, function () {
$(this)
.html("Observations du taxon : " + name)
.fadeIn(500);
});
}

Expand Down
12 changes: 7 additions & 5 deletions atlas/static/mapHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function refreshTerritoryArea(elem) {


$(document).ready(function () {
$("#loaderSpinner").hide();
if (configuration.INTERACTIVE_MAP_LIST) {
$("#taxonList").on("click", "#taxonListItem", function (elem) {
refreshTerritoryArea(elem);
Expand All @@ -66,19 +67,20 @@ htmlLegend = configuration.AFFICHAGE_MAILLE ? htmlLegendMaille : htmlLegendPoint
generateLegende(htmlLegend);

// Add territory obs on map
if (configuration.AFFICHAGE_TERRITOIRE_OBS){
if (configuration.AFFICHAGE_TERRITOIRE_OBS){
$("#loaderSpinner").show();

// display maille layer
fetch(`/api/observationsMailleTerritory`)
.then(response => response.json())
.then(data => {
observations = data
.then(observations => {
displayMailleLayer(observations);
$("#loaderSpinner").hide();

})
.catch(error => {
console.log('Error fetching observations: ', error);
});

$("#loaderSpinner").hide();

// interaction list - map
$('.lastObslistItem').click(function(elem){
Expand Down
2 changes: 1 addition & 1 deletion atlas/templates/home/_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
url_limit_territory = "{{url_for('static', filename='custom/territoire.json') }}";
</script>
<script src="{{ url_for('static', filename='main.js') }}"></script>
{% if configuration.AFFICHAGE_DERNIERES_OBS %}
{% if configuration.AFFICHAGE_DERNIERES_OBS or configuration.AFFICHAGE_TERRITOIRE_OBS %}
<script src="{{ url_for('static', filename='custom/maps-custom.js') }}"></script>
<script src="{{ url_for('static', filename='mapGenerator.js') }}"></script>
<script src="{{ url_for('static', filename='mapHome.js') }}"></script>
Expand Down
Loading