Open 2803media opened 5 years ago
Here is a first attempt of this, still a bit messy... The trick is to check if the dist is display and if not try to add to the prev or next dist depending of the rotation information:
if (this._measurementOptions.showDistances && latLngs.length > 1) {
formatter = this._measurementOptions.formatDistance || L.bind(this.formatDistance, this);
var newArr = [];
for (var i = 1, len = latLngs.length; (isPolygon && i <= len) || i < len; i++) {
ll1 = latLngs[i - 1];
ll2 = latLngs[i % len];
dist = ll1.distanceTo(ll2);
totalDist += dist;
p1 = this._map.latLngToLayerPoint(ll1);
p2 = this._map.latLngToLayerPoint(ll2);
pixelDist = p1.distanceTo(p2);
if (pixelDist >= options.minPixelDistance) {
var chargeDetails = {
i : i,
dist : dist,
rotation : this._getRotation(ll1, ll2),
coords : this._map.layerPointToLatLng([(p1.x + p2.x) / 2, (p1.y + p2.y) / 2]),
measurementLayer : this._measurementLayer,
display : 1,
};
newArr.push(chargeDetails);
/*
L.marker.measurement(
this._map.layerPointToLatLng([(p1.x + p2.x) / 2, (p1.y + p2.y) / 2]),
formatter(dist), options.lang.segmentLength, this._getRotation(ll1, ll2), options)
.addTo(this._measurementLayer);
*/
} else {
var chargeDetails = {
i : i,
dist : dist,
rotation : this._getRotation(ll1, ll2),
coords : this._map.layerPointToLatLng([(p1.x + p2.x) / 2, (p1.y + p2.y) / 2]),
measurementLayer : this._measurementLayer,
display : 0,
};
newArr.push(chargeDetails);
//console.log('pixelDist',dist);
//console.log('rotation',this._getRotation(ll1, ll2));
}
}
console.log(newArr)
var newArr2 = [];
var k = 0;
jQuery.each(newArr, function( index, value ) {
//console.log('dist',value.dist);
if(value.display == 1){
var chargeDetails = {
i : value.i,
dist : value.dist,
rotation : value.rotation,
coords : value.coords,
measurementLayer : value.measurementLayer,
display : 1,
};
newArr2.push(chargeDetails);
var newdata = 0;
k = k+1;
} else {
if(typeof newArr2[k-1] != 'undefined'){
//console.log('value.dist',value.dist);
console.log('diffrot',value.rotation-newArr2[k-1].rotation)
console.log('dist',value.dist)
console.log('---');
if(value.rotation-newArr2[k-1].rotation<1 && value.rotation-newArr2[k-1].rotation>-1){
newArr2[k-1].dist = value.dist+newArr2[k-1].dist;
} else {
var chargeDetails = {
i : value.i,
dist : value.dist,
rotation : value.rotation,
coords : value.coords,
measurementLayer : value.measurementLayer,
display : 1,
};
newArr2.push(chargeDetails);
var newdata = 0;
k = k+1;
}
} else {
var chargeDetails = {
i : value.i,
dist : value.dist,
rotation : value.rotation,
coords : value.coords,
measurementLayer : value.measurementLayer,
display : 1,
};
newArr2.push(chargeDetails);
var newdata = 0;
k = k+1;
}
}
console.log('---');
});
console.log('newArr2',newArr2);
jQuery.each(newArr2, function( index, value ) {
if(value.display == 1){
L.marker.measurement(
value.coords,
formatter(value.dist), options.lang.segmentLength, value.rotation, options)
.addTo(value.measurementLayer);
}
});
Do you think it will possible to group distance number depending of the display of the number (based on zoom) because it can't create confusion for the user to read number and zoom in an discover other numbers....
Example of the problem: