【问题标题】:Leaflet.JS marker goes on coords on opposite map [duplicate]Leaflet.JS 标记在对面地图上继续坐标[重复]
【发布时间】:2021-01-10 18:16:44
【问题描述】:

不完全确定如何措辞,但是当我在(我相信)64 lat 标记以东放置一个传单标记时,它会出现在左侧的地图上。我想让所有的标记都在同一张地图上。

关于我在说什么的图片:

我想做到这一点,以便左侧的标记转到它们需要位于每个其他标记所在位置的纬度和经度标记。你可以看到我画了一个箭头来显示它在哪里

我尝试过的:

我找不到任何东西,所以我尝试将 worldCopyJump 设置为 false。然后我尝试了 true 并没有解决这个问题。

谢谢!

(哦,如果我放大它应该在它不出现的区域。)

代码:

HTML:

<div id="mapid" style="width: 100%; height: 950px;"></div>

JS

var mymap = L.map('mapid', {worldCopyJump: true}).setView([51.505, -0.09], 3);

        L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=api_key', {
        /*maxZoom: 7,*/
        attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, ' +
            'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
        id: 'mapbox/streets-v11',
        tileSize: 512,
        zoomOffset: -1,
        //set following lines to false
    }).addTo(mymap);

    

    var presentIcon = L.icon({
    iconUrl: 'giftmarker.png',

    iconSize:     [38, 60], // size of the icon
    iconAnchor:   [12, 57], // point of the icon which will correspond to marker's location

});

L.marker([65.585848, -171.011122], {icon: presentIcon}).addTo(mymap);

L.marker x60 次

【问题讨论】:

    标签: leaflet


    【解决方案1】:

    您需要将 360 添加到错误放置标记的Lng

    所以标记应该看起来像:L.marker([65.585848, 188.988878], {icon: presentIcon}).addTo(mymap);

    使用此代码,您可以更改所有现有标记。我在 -149 lng 休息一下,把标记换到另一边:

    map.eachLayer((layer) => {
        if (layer instanceof L.Marker) {
            if (layer.getLatLng().lng <= -149) {
                var latlng = layer.getLatLng();
                latlng.lng = latlng.lng + 360;
                layer.setLatLng(latlng);
            }
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2012-05-02
      • 1970-01-01
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      • 2022-12-10
      • 1970-01-01
      相关资源
      最近更新 更多