Skip to content

Commit

Permalink
Move reset of the path layer into the right method
Browse files Browse the repository at this point in the history
  • Loading branch information
JustineFricou committed Apr 24, 2024
1 parent ead43d1 commit a51d664
Showing 1 changed file with 15 additions and 36 deletions.
51 changes: 15 additions & 36 deletions geotrek/core/static/core/multipath.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,36 +688,21 @@ L.Handler.MultiPath = L.Handler.extend({
}
},

showPathGeom: function (layer) {
// This piece of code was moved from formfield.js, its place is here,
// not around control instantiation. Of course this is not very elegant.
var self = this;
if (!this.markPath)
this.markPath = (function() {
var current_path_layer = null;
return {
'updateGeom': function(new_path_layer) {
var prev_path_layer = current_path_layer;
current_path_layer = new_path_layer;

if (prev_path_layer) {
self.map.removeLayer(prev_path_layer);
}

if (new_path_layer) {
self.map.addLayer(new_path_layer);
new_path_layer.setStyle({'color': 'yellow', 'weight': 5, 'opacity': 0.8});
new_path_layer.eachLayer(function (l) {
if (typeof l.setText == 'function') {
l.setText('> ', {repeat: true, attributes: {'fill': '#FF5E00'}});
}
});
}
}
}
})();
showPathGeom: function (geojson) {

if (this.pathLayer != undefined)
this.map.removeLayer(this.pathLayer)

this.markPath.updateGeom(layer);
if (geojson) {
this.pathLayer = L.geoJson(geojson, {color:"blue", weight: 10})
this.pathLayer.addTo(this.map);
this.pathLayer.setStyle({'color': 'yellow', 'weight': 5, 'opacity': 0.8});
this.pathLayer.eachLayer(function (l) {
if (typeof l.setText == 'function') {
l.setText('> ', {repeat: true, attributes: {'fill': '#FF5E00'}});
}
});
}
},

getMarkers: function() {
Expand Down Expand Up @@ -787,14 +772,8 @@ L.Handler.MultiPath = L.Handler.extend({
var self = this;
var topology = Geotrek.TopologyHelper.buildTopologyFromComputedPath(this.idToLayer, data);

if (this.pathLayer != undefined)
this.map.removeLayer(this.pathLayer)

//this.showPathGeom(topology.layer);
this.showPathGeom(data.geojson);

this.pathLayer = L.geoJson(data.geojson, {color:"blue", weight: 10})
this.pathLayer.addTo(self.map);

//this.fire('computed_topology', {topology:topology.serialized});

// ## ONCE ##
Expand Down

0 comments on commit a51d664

Please sign in to comment.