标记显示在错误的位置/无法在 Leaflet 中设置中心点
Markers showing on wrong place / can not set center point in Leaflet
我使用 Leaflet markercluster 插件:https://github.com/Leaflet/Leaflet.markercluster
当我将标记的默认坐标更改为其他坐标时,标记位置错误。
此问题的示例:https://jsfiddle.net/allu1/nbv17oqc/5/
在“geoJsonData”标签下方,第一个标记坐标已更改,但标记完全错误。
而且我也无法设置地图的中心点。我已经尝试了所有这些,但没有任何效果:
var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
var centermap = L.latLng(64.299791, 27.182384);
var map = L.map('map')
.setView(centermap, 5)
.addLayer(tiles);
和
var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}),
latlng = L.latLng(64.299791, 27.182384);
var map = L.map('map', {center: latlng, zoom: 5.5,
fullscreenControl: true,
}).addLayer(tiles);
和
var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
var map = L.map('map', {
center: L.latLng(64.299791, 27.182384),
zoom: 4})
.addLayer(tiles);
我用过Leaflet全屏插件:https://github.com/Leaflet/Leaflet.fullscreen
全屏选项显示良好,但地图的中心点不起作用。主要是中心点会起作用。
如果需要,我会提供更多信息。感谢您的回答!
看来您混淆了东距和北距。我不确定您希望您的积分最终归于何处,但是 (N64, E27) 在芬兰,而 (N27, E64) 在巴基斯坦。
在 Leaflet 中,您指定一个坐标,如 var latlng = L.latLng(latitude, longitude);
(参见 the docs)。
在 GeoJSON 中(请参阅 RFC7946 了解规范),情况正好相反。坐标以 "coordinates": [longitude, latitude]
格式指定。你可以从你的 JSFiddle 代码中的新西兰点看到它是这样的,因为 175° 作为纬度是无效的。
我从你的 JSFiddle 中看不出为什么地图居中不起作用。但是,这可能是因为您在脚本末尾使用了 map.fitBounds(markers.getBounds());
。这将使地图居中于标记簇的中心,over-riding 无论您最初设置为中心点是什么。由于您的测试坐标相距甚远(一个在巴基斯坦,另一个在新西兰),JSFiddle 中的代码将中心点设置为婆罗洲附近的某个地方。
我使用 Leaflet markercluster 插件:https://github.com/Leaflet/Leaflet.markercluster
当我将标记的默认坐标更改为其他坐标时,标记位置错误。 此问题的示例:https://jsfiddle.net/allu1/nbv17oqc/5/
在“geoJsonData”标签下方,第一个标记坐标已更改,但标记完全错误。
而且我也无法设置地图的中心点。我已经尝试了所有这些,但没有任何效果:
var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
var centermap = L.latLng(64.299791, 27.182384);
var map = L.map('map')
.setView(centermap, 5)
.addLayer(tiles);
和
var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}),
latlng = L.latLng(64.299791, 27.182384);
var map = L.map('map', {center: latlng, zoom: 5.5,
fullscreenControl: true,
}).addLayer(tiles);
和
var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
var map = L.map('map', {
center: L.latLng(64.299791, 27.182384),
zoom: 4})
.addLayer(tiles);
我用过Leaflet全屏插件:https://github.com/Leaflet/Leaflet.fullscreen 全屏选项显示良好,但地图的中心点不起作用。主要是中心点会起作用。
如果需要,我会提供更多信息。感谢您的回答!
看来您混淆了东距和北距。我不确定您希望您的积分最终归于何处,但是 (N64, E27) 在芬兰,而 (N27, E64) 在巴基斯坦。
在 Leaflet 中,您指定一个坐标,如 var latlng = L.latLng(latitude, longitude);
(参见 the docs)。
在 GeoJSON 中(请参阅 RFC7946 了解规范),情况正好相反。坐标以 "coordinates": [longitude, latitude]
格式指定。你可以从你的 JSFiddle 代码中的新西兰点看到它是这样的,因为 175° 作为纬度是无效的。
我从你的 JSFiddle 中看不出为什么地图居中不起作用。但是,这可能是因为您在脚本末尾使用了 map.fitBounds(markers.getBounds());
。这将使地图居中于标记簇的中心,over-riding 无论您最初设置为中心点是什么。由于您的测试坐标相距甚远(一个在巴基斯坦,另一个在新西兰),JSFiddle 中的代码将中心点设置为婆罗洲附近的某个地方。