Skip to content

Commit

Permalink
Modifying drawOnMouseMove to handle new topology system
Browse files Browse the repository at this point in the history
  • Loading branch information
JustineFricou committed Apr 24, 2024
1 parent 1d158e4 commit 631d886
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions geotrek/core/static/core/multipath.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ L.Handler.MultiPath = L.Handler.extend({
var self = this;
(function() {
function dragstart(e) {
var next_step_idx = self.draggable_marker.group_layer.step_idx + 1;
//var next_step_idx = self.draggable_marker.group_layer.step_idx + 1;
self.addViaStep(self.draggable_marker, next_step_idx);
}
function dragend(e) {
Expand Down Expand Up @@ -770,10 +770,10 @@ L.Handler.MultiPath = L.Handler.extend({

onComputedPaths: function(data) {
var self = this;
var topology = Geotrek.TopologyHelper.buildTopologyFromComputedPath(this.idToLayer, data);
var topology = data.geojson // Geotrek.TopologyHelper.buildTopologyFromComputedPath(this.idToLayer, data);
//this.fire('computed_topology', {topology:topology.serialized});

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


// ## ONCE ##
Expand Down Expand Up @@ -805,32 +805,39 @@ L.Handler.MultiPath = L.Handler.extend({
}
}

var MIN_DIST = 30;

var layerPoint = a.layerPoint
, min_dist = Number.MAX_VALUE
, closest_point = null
, matching_group_layer = null;

topology.layer && topology.layer.eachLayer(function(group_layer) {
group_layer.eachLayer(function(layer) {
var p = layer.closestLayerPoint(layerPoint);
if (p && p.distance < min_dist && p.distance < MIN_DIST) {
min_dist = p.distance;
closest_point = p;
matching_group_layer = group_layer;
}
});
});

if (closest_point) {
self.draggable_marker.setLatLng(self.map.layerPointToLatLng(closest_point));
self.draggable_marker.addTo(self.map);
L.DomUtil.addClass(self.draggable_marker._icon, self.draggable_marker.classname);
self.draggable_marker._removeShadow();
self.draggable_marker.group_layer = matching_group_layer;
} else {
self.draggable_marker && self.map.removeLayer(self.draggable_marker);
// var MIN_DIST = 30;

// var layerPoint = a.layerPoint
// , min_dist = Number.MAX_VALUE
// , closest_point = null
// , matching_group_layer = null;

// topology && topology.eachLayer(function(group_layer) {
// console.log(group_layer)
// group_layer.eachLayer(function(layer) {
// var p = layer.closestLayerPoint(layerPoint);
// if (p && p.distance < min_dist && p.distance < MIN_DIST) {
// min_dist = p.distance;
// closest_point = p;
// matching_group_layer = group_layer;
// }
// });
// });

if (this.pathLayer) {
console.log('type(this.pathLayer)', typeof this.pathLayer)
var closest_point = this.pathLayer.closestLayerPoint(a.layerPoint);
console.log('closest_point', closest_point)

if (closest_point) {
self.draggable_marker.setLatLng(self.map.layerPointToLatLng(closest_point));
self.draggable_marker.addTo(self.map);
L.DomUtil.addClass(self.draggable_marker._icon, self.draggable_marker.classname);
self.draggable_marker._removeShadow();
//self.draggable_marker.group_layer = matching_group_layer;
} else {
self.draggable_marker && self.map.removeLayer(self.draggable_marker);
}
}
};

Expand Down

0 comments on commit 631d886

Please sign in to comment.