Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/hedges-stats-…
Browse files Browse the repository at this point in the history
…display
  • Loading branch information
pyDez committed Nov 29, 2024
2 parents 8a609c1 + d35aa12 commit 3729928
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions envergo/hedges/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def hedges_to_plant(self, obj):
return len(obj.hedges_to_plant())

def length_to_plant(self, obj):
return sum(h.length for h in obj.hedges_to_plant())
return obj.length_to_plant()

def hedges_to_remove(self, obj):
return len(obj.hedges_to_remove())

def length_to_remove(self, obj):
return sum(h.length for h in obj.hedges_to_remove())
return obj.length_to_remove()
6 changes: 3 additions & 3 deletions envergo/hedges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def length(self):

geod = Geod(ellps="WGS84")
length = geod.geometry_length(self.geometry)
return int(length)
return length

@property
def is_on_pac(self):
Expand Down Expand Up @@ -68,13 +68,13 @@ def hedges_to_plant(self):
return [Hedge(**h) for h in self.data if h["type"] == TO_PLANT]

def length_to_plant(self):
return sum(h.length for h in self.hedges_to_plant())
return round(sum(h.length for h in self.hedges_to_plant()))

def hedges_to_remove(self):
return [Hedge(**h) for h in self.data if h["type"] == TO_REMOVE]

def length_to_remove(self):
return sum(h.length for h in self.hedges_to_remove())
return round(sum(h.length for h in self.hedges_to_remove()))

def lineaire_detruit_pac(self):
return sum(
Expand Down
15 changes: 13 additions & 2 deletions envergo/hedges/static/hedge_input/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,14 @@ createApp({
doubleClickZoom: false,
zoomControl: false,
layers: [satelliteLayer]
}).setView([43.6861, 3.5911], 14);
});

L.control.layers(baseMaps, null, { position: 'bottomleft' }).addTo(map);

L.control.zoom({
position: 'bottomright'
}).addTo(map);


// Zoom on the selected address
window.addEventListener('EnvErgo:citycode_selected', function (event) {
const coordinates = event.detail.coordinates;
Expand All @@ -414,7 +413,19 @@ createApp({
map.setView(latLng, zoomLevel);
});

// Here, we want to restore existing hedges
// If there are any, set view to see them all
// Otherwise, set a default view with a zoom level of 14
// There is a catch though. If we set a zoom level of 14 in the
// first `setView` call, it triggers a bug with hedges polylines middle
// markers that are displayed outside of the actual line. That's because
// the marker positions are calculated with a precision that is dependant
// on the zoom level.
// So we have to set the view with a zoom maxed out, restore the markers,
// then zoom out.
map.setView([43.6861, 3.5911], 22);
restoreHedges();
map.setZoom(14);
zoomOut();
});

Expand Down

0 comments on commit 3729928

Please sign in to comment.