地图框标记在使用“图标允许重叠”时闪烁



我有一个地图,它使用mapboxgl-js根据某些条件隐藏或显示地图标记。

隐藏标记

按预期工作,但是当我希望标记再次显示时,它们会闪烁几毫秒,然后再次消失,而地图会在底层图层上隐藏标签(街道名称等(,然后再再次出现。

观看此视频:https://streamable.com/debcp

请参阅此代码笔:https://codepen.io/jakobfuchs/details/VRRgJO

我得出的结论是,这是由于在标记符号图层上设置'icon-allow-overlap': true引起的。

任何建议如何保持该设置并避免闪烁?

奇怪的是,这不是100%的时间,而是~95%的时间。

代码示例:

标记层:

  map.addLayer({
    id: 'property-layer',
    type: 'symbol',
    source: 'properties',
    filter: ['!has', 'point_count'],
    layout: {
      'symbol-placement': 'point',
      'icon-image': 'marker',
      'icon-size': 1,
      'icon-anchor': 'bottom',
      'icon-allow-overlap': true,
    }
  });

过滤器代码:

  const filterToggle = document.getElementById('filterToggle');
  filterToggle.addEventListener('change', function(e) {
    if (openPopup) {
      openPopup.remove();
      openPopup = '';
    }
    let properties;
    if (this.checked) {
      properties = {
        type: "FeatureCollection",
        features: features.features.filter((property) => property.properties.availability === 'Available')
      }
    } else {
      properties = features;
    }
    map.getSource('properties').setData(properties);
  });

我遇到了同样的问题,我的解决方案是使用图标忽略放置而不是图标允许重叠,它仍然没有任何问题

您可以在此处找到该文档:https://docs.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-icon-ignore-placement

希望这会有所帮助,谢谢!

最新更新