Leaflet.js - LatLng to Pixels

不羁的心 提交于 2021-02-11 15:45:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!