Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to group distance number on zoom? #31

Open
2803media opened this issue Mar 28, 2019 · 1 comment
Open

Possible to group distance number on zoom? #31

2803media opened this issue Mar 28, 2019 · 1 comment

Comments

@2803media
Copy link

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:

Capture d’écran 2019-03-28 à 16 47 31
Capture d’écran 2019-03-28 à 16 47 24
Capture d’écran 2019-03-28 à 16 47 18

@2803media
Copy link
Author

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);
                  }
                });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant