React-mapbox-gl: How to highlight line in <GeoJSONLayer/>

Created on 24 Sep 2018  路  5Comments  路  Source: alex3165/react-mapbox-gl

I have this code, Lines are drawn. But I want to highlight a line when hovered or clicked.

        {Object.keys(this.props.pavements).length > 0 && (
          <GeoJSONLayer
            data={this.props.pavements}
            linePaint={{
              'line-color': ['get', 'color'],
              'line-width': 10,
            }}
            lineLayout={{
              'line-cap': 'round',
            }}
            lineOnClick={e => this.populateInfobox(e)}
            lineOnMouseEnter={e => this.populateInfobox(e)}
          />
        )}

What can I do in lineOnClick to change the color of the clicked line?

All 5 comments

+1

You can use React state to provide a different line-color property after the click or provide a different color property on the clicked feature.

I did it by saving the color property of GeoJson in redux and changing the color of the selected feature

I assume this can then be considered closed.

The "Mapbox" way of doing this would be to use setFeatureState but that's not possible at the moment, see https://github.com/alex3165/react-mapbox-gl/issues/652

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ricardo-C-Oliveira picture Ricardo-C-Oliveira  路  4Comments

faiq picture faiq  路  4Comments

jonheslop picture jonheslop  路  4Comments

spybaby1 picture spybaby1  路  4Comments

kn0ll picture kn0ll  路  3Comments