我在 html 页面中有一张传单地图(我将代码放在下面)。当我在 Chrome 浏览器中打开它并单击地图时,它会将图钉放置在我单击的位置以外的位置。但在FF浏览器中运行正常。
var map = L.map('map').setView({lon: 51.66509977740657, lat: 32.622378058018654}, 16);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 19}).addTo(map);
L.control.scale({imperial: true, metric: true}).addTo(map);
map.on('click',function(e) {
lat = Number(e.latlng.lat.toFixed(6));
lon = Number(e.latlng.lng.toFixed(6));
popup
.setLatLng(e.latlng)
.setContent("You Clicked Lat: " + lat+" & Lon: "+lon)
.openOn(map);
if (theMarker != undefined) {
map.removeLayer(theMarker);
};
theMarker = L.marker([lat,lon]).addTo(map);
有什么想法吗?
我用谷歌搜索了很多这个问题,但找不到解决方案。
您的 if 语句/ onClick 函数缺少关闭手镯:
var map = L.map('map').setView({lon: 51.66509977740657, lat: 32.622378058018654}, 16);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 19}).addTo(map);
L.control.scale({imperial: true, metric: true}).addTo(map);
map.on('click',function(e) {
lat = Number(e.latlng.lat.toFixed(6));
lon = Number(e.latlng.lng.toFixed(6));
popup
.setLatLng(e.latlng)
.setContent("You Clicked Lat: " + lat+" & Lon: "+lon)
.openOn(map);
if (theMarker != undefined) {
map.removeLayer(theMarker);
} // this was missing
};
theMarker = L.marker([lat,lon]).addTo(map);
我发现问题了。这是对我的引导模板的干扰,该模板用于侧栏,其中显示宽度小于 1200px,内容更改为 85%,这将使引脚位于其他地方。