繁体   English   中英

mapbox-如何设置要素图层的弹出选项

[英]mapbox - how to set the popup options for a feature layer

我正在使用mapbox.js生成一个包含标记和弹出窗口的图层。 我以一定的时间间隔以编程方式缩放到该标记并显示弹出窗口。 但是,我想禁用弹出窗口的“ closeOnClick”功能,但是如果我在创建featureLayer之后对其进行设置,则它无效。 有人知道如何正确执行此操作吗? 这是我的代码:

eventMarkerLayer = L.mapbox.featureLayer({ //add the event marker
  type: 'Feature',
  geometry: {
      type: 'Point',
      coordinates: [eventPt.lng,eventPt.lat]
  },
  properties: {
    title:eventScenario.text,
    'marker-color': eventColor
  },
  options: {
    popupOptions: {
      closeOnClick: false //doesn't work
    }
  }
}).addTo(map);

eventMarkerLayer.options.popupOptions.closeOnClick = false; //doesn't work either

eventMarkerLayer.openPopup();

默认弹出窗口行为仅允许您一次打开一个功能,因此必须使用L.popup()手动添加弹出窗口:

eventMarkerLayer = L.mapbox.featureLayer({ //add the event marker
  type: 'Feature',
  geometry: {
      type: 'Point',
      coordinates: [eventPt.lng,eventPt.lat]
  },
  properties: {
    popupContent: eventScenario.text, // note -- change "title" to another name
    'marker-color': eventColor
  }
}).addTo(map);

eventMarkerLayer.eachLayer(function(layer) {
  var popup = L.popup({
      closeOnClick: false, // keeps popups open
      offset: L.point(0, -25) // offset so popup shows up above marker
    })
  .setLatLng([layer.feature.geometry.coordinates[1], layer.feature.geometry.coordinates[0]]) // L.popup takes [lat, lng]
  .setContent(layer.feature.properties.popupContent); // add content from feature
  map.addLayer(popup); // add to map
});

暂无
暂无

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

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