Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapbox markers flashing when using `icon-allow-overlap`

I have a map that's using mapboxgl-js to hide or show map markers based on some criteria.

Hiding the markers is working as expected, but when I want the markers to show again they flash for some milliseconds then disappear again while the map hides labels (street names etc.) on the underlying layer before they show up again.

See this video: https://streamable.com/debcp

See this codepen: https://codepen.io/jakobfuchs/details/VRRgJO

I came to the conclusion that this is caused by setting 'icon-allow-overlap': true on the marker symbol layer.

Any suggestions how I can keep that setting and avoid the flashing?

The strange thing is that this does not happen 100% of the time but ~95% of the time.

Code samples:

Marker layer:

  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,
    }
  });

Filter code:

  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);
  });
like image 938
Jakob Fuchs Avatar asked May 22 '26 13:05

Jakob Fuchs


1 Answers

I have faced with the same issue and my solution is use the icon-ignore-placement instead of icon-allow-overlap, and it's still not have any issues

You can find the document here: https://docs.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-icon-ignore-placement

Hope this will help, thanks!

like image 166
An Ha Avatar answered May 24 '26 03:05

An Ha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!