标记显示在错误的位置/无法在传单中设置中心点

我使用 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: '&copy; <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: '&copy; <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: '&copy; <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 并且全屏选项显示良好,但地图的中心点不起作用。最主要的是中心点可以工作。


如果需要的话,我会提供更多信息。感谢您的回答!


三国纷争
浏览 133回答 1
1回答

饮歌长啸

看来您混淆了东向和北向。我不确定您希望积分最终在哪里,但 (N64, E27) 在芬兰,而 (N27, E64) 在巴基斯坦。在 Leaflet 中,您可以指定一个坐标var latlng = L.latLng(latitude, longitude);在 GeoJSON(参见RFC7946规范)中,情况正好相反。坐标以格式指定"coordinates": [longitude, latitude]。您可以从 JSFiddle 代码中的新西兰点看到它是这样的,因为 175° 不是有效的纬度。我从你的 JSFiddle 中看不出为什么地图居中不起作用。map.fitBounds(markers.getBounds());但是,这可能是因为您在脚本末尾使用了。这将使地图居中于标记簇的中心,从而覆盖您最初设置为中心点的任何内容。由于您的测试坐标相距很远(一个在巴基斯坦,另一个在新西兰),JSFiddle 中的代码将中心点设置为婆罗洲附近的某个位置。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript