react-mapbox-gl
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
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.
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 executethis.createLayer('line');
...
I would be happy to merge this PR if you could make this change 👍
Hello! Will this be merged soon? Thanks for all your work!
anyone going to bother merging this?