You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use the closetlayer function to find the closest point on a geoJson file but keep getting a "Cannot read properties of null (reading 'lat')" error. May geojson file is a linestring. Any ideas on what I may be doing wrong?
var geojsonLayer = new L.GeoJSON.AJAX("XXX.geojson", {
style: {color: 'red',
weight: 4}
});
geojsonLayer.addTo(map);
const coordinates_array = geojsonLayer.getLayers().map(l => l.feature.geometry.coordinates)
markerClosestPolyline1 = null
map.on('click', function(e) {
const coordinates_array = geojsonLayer.getLayers().map(l => l.feature.geometry.coordinates)
let closest_latlng = L.GeometryUtil.closestLayer(map, coordinates_array, e.latlng)
markerClosestPolyline1 = L.marker(closest_latlng).addTo(map).bindPopup('Closest point on polyline1');
})
The error is pointing me to this portion of the code (Im guessing its an error related to the way im loading my geojson file)
project: function (latlng) {
var d = Math.PI / 180,
max = this.MAX_LATITUDE,
lat = Math.max(Math.min(max, latlng.lat), -max),
sin = Math.sin(lat * d);
The text was updated successfully, but these errors were encountered:
I am trying to use the closetlayer function to find the closest point on a geoJson file but keep getting a "Cannot read properties of null (reading 'lat')" error. May geojson file is a linestring. Any ideas on what I may be doing wrong?
The error is pointing me to this portion of the code (Im guessing its an error related to the way im loading my geojson file)
The text was updated successfully, but these errors were encountered: