react-mapbox-gl icon indicating copy to clipboard operation
react-mapbox-gl copied to clipboard

Fix 652 and 603 by adding an id to the geojson feature for Layer component and prevent creating as many layers as there are layer types for geojsonLayer component

Open qlerebours opened this issue 5 years ago • 3 comments

As mentioned in #652 : An id was missing in the geojson features that was preventing to use this kind of feature: https://docs.mapbox.com/mapbox-gl-js/example/hover-styles/ I added the same id to the feature than the one that was added to the feature properties:

{
    type: 'Feature',
    geometry: this.geometry(props.coordinates),
    properties: { ...props.properties, id },
    id
}

The example code that were not working in the issue is now working fine

As mentioned in #603 : Passing layerOptions props with and id to the GeoJSONLayer component was not working. It was because in the initialize function, a layer was created for each layer type, even if it was stated that it should be one precise type:

this.createLayer('symbol');
this.createLayer('line');
this.createLayer('fill');
this.createLayer('fill-extrusion');
this.createLayer('circle');

I added a check to create the layer only if the layer type is the right one.

if (layerOptions && layerOptions.type && layerOptions.type !== type) {
      return;
}

Note that I also documented the id props of the GeoJSONLayer component that was missing.

qlerebours avatar Aug 25 '19 12:08 qlerebours

Hey @qlerebours sorry for the late reply and thank you for your PR, I agree with the ID fix although for the layer type fix I am not sure this is going to work. The problem is that layerOptions is an optional parameter, one might use GeoJsonLayer without passing layerOptions and expect his layer to be created. An alternative check could have the following logic:

  • If any prop received in component is in LineProps (interface) then execute this.createLayer('line'); ...

I would be happy to merge this PR if you could make this change 👍

alex3165 avatar Oct 20 '19 13:10 alex3165

Hello! Will this be merged soon? Thanks for all your work!

sebastian-ch avatar Jun 10 '20 13:06 sebastian-ch

anyone going to bother merging this?

solarstar101 avatar Oct 25 '20 04:10 solarstar101