Skip to content

Commit

Permalink
Merge branch 'hedges_precision'
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Nov 28, 2024
2 parents e2c7661 + 3c0de2a commit d35aa12
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


class HedgeData(models.Model):
Expand All @@ -60,10 +60,10 @@ 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()))
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 d35aa12

Please sign in to comment.