Leaflet.js-LatLng转换为像素 [英] Leaflet.js - LatLng to Pixels
问题描述
所以我正在使用crs:L.CRS在我的Leaflet中使用Pixels.在我引用的所有坐标位置都简单且未投影,效果很好.
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.
但是我现在试图添加一个搜索栏,但我无法找到一行内容来说明如何使用像素而不是LatLng(它是从文件中提取像素坐标)
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);
}
这是标记=新的L.Marker(新的L.latLng(loc)行..我不知道如何在该行中取消投影以使其使用像素.尝试了100种不同的方法,但是...是的,我不是编码员,所以让我傻眼了.
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.
提前谢谢!
推荐答案
尝试 map.latLngToContainerPoint(latlng)
这会将latlng转换为您的容器点.
This converts the latlng to your container point.
https://leafletjs.com/reference-1.6.0.html#map-latlngtocontainerpoint
这篇关于Leaflet.js-LatLng转换为像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!