简体   繁体   English

TileMill MapBox地图可在没有任何标记的情况下平移到不同的世界

[英]TileMill MapBox map pans to different world without any markers

I have a map I exported from tilemill, made a mapbox map and threw some points on it. 我有一张从tilemill导出的地图,制作了一个mapbox地图,并在上面贴了一些点。 The view starts off looking at the US, with a marker somewhere in the middle. 该视图开始于美国,中间有一个标记。 If I pan left until the next time I see the US, the markers are gone. 如果我向左平移直到下次看到美国,标记将消失。 Here's the code minus the geoJson data. 这是减去geoJson数据的代码。

var map = L.mapbox.map('map', 'natecraft1.xdan61or').setView([-102, 39], 4);
map.markerLayer.on('layeradd', function(e) {
  var marker = e.layer;
  var feature = marker.feature;
  var image = feature.properties.images
  // var img = images

  // Create custom popup content
var popupContent = '<img class="pics" src="' + image + '" />'
  marker.bindPopup(popupContent,{
    closeButton: false,
    minWidth: 320,
    offset: [180, 20]
  });
});

map.markerLayer.setGeoJSON(geoJson);

map.markerLayer.on('click', function(e) {
  e.layer.openPopup(); 
var lat = e.layer.getLatLng().lat;
  var lng = e.layer.getLatLng().lng;

  map.panTo([lat+5, lng+5], 2);

});
  map.markerLayer.on('', function(e) {
  e.layer.closePopup();
});

Your tilelayer is wrapping around the globe for coordinates outside of the (-180, 180) range . 您的瓦工正在全球范围内寻找 -180,180 )范围之外的坐标。 Best option is to set the maxBounds option so users don't pan outside of that map and just get bounced back. 最好的选择是设置maxBounds选项,以使用户不会在该地图外平移,而只会被弹回。

var map = L.mapbox.map('map', 'examples.map-9ijuk24y').setView([0,0], 2);
var layer = L.mapbox.tileLayer('examples.map-9ijuk24y', {
  noWrap: true,
  minZoom: 3
}).addTo(map);
map.options.maxBounds = map.getBounds();

Here's a live demo of what that would look like 这是一个演示现场演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM