Search code examples
leafletangular-leaflet-directivedc.leaflet.js

How to calculate pixels on latlng base: leaflet


I am working with the leaflet api.Where User draw a polyline and latlongs saved in variables.

I been looking for a leaflet function which suppose to take latlongs and calculate pixels.Found the layerPoint function but as i have low understanding of leaflet, can't use the function.

I have used 2 variables to store two latlng parameter, but didn't understand how to use them in layerPoint function.

Script

var polyline = new L.Polyline([]);
            var aa;
            var bb;
            function getDist(e) {
                // New marker on coordinate, add it to the map
                // Add coordinate to the polyline
                polyline.addLatLng(e.latlng).addTo(map).bindPopup();
                var ccc = prompt('1st or 2nd');
                if (ccc == '1') { aa = e.latlng}
                else if (ccc == '2') { bb = e.latlng; convertIt();
                }
            }

            function convertIt(e)
            {
                var getit = e.latLngToPoint(latlng, map.getZoom());
            }

If someone can help, please do help.thanks for your time


Solution

  • latLngToPoint is a method on L.Map. You need to pass a latLng as a parameter to your convertIt function, then return map.latLngToPoint(e), assuming you keep e as the parameter name for convertIt.