问题
So I am using Pixels in my Leaflet using crs: L.CRS.Simple and unproject in all the places I reference coordinates, it is working great.
However I am now trying to add a search bar and there is one line that I cannot figure out how to make it use pixels instead of LatLng (it's pulling pixel coords from a file)
var title = data.newsroom, //value searched
loc = [data.latitude, data.longitude] //position found
marker = new L.Marker(new L.latLng(loc), {title: title, icon:icon} );//se property searched
marker.bindPopup("<strong style='color: #84b819'>" + title + "</strong><br>" + data.company + " | " + data.city + "<br>Head: " + data.head);
markersLayer.addLayer(marker);
}
It's the marker = new L.Marker(new L.latLng(loc) line..I can't figure out how to unproject in that line to make it use pixels. Tried 100 different things but...yeah, I am not a coder so It has me dumbfounded.
Thanks in advance!
回答1:
Try map.latLngToContainerPoint(latlng)
This converts the latlng to your container point.
https://leafletjs.com/reference-1.6.0.html#map-latlngtocontainerpoint
来源:https://stackoverflow.com/questions/61248633/leaflet-js-latlng-to-pixels