React-mapbox-gl: Clicking on Feature to open a Popup only works properly the first time

Created on 15 Feb 2018  路  3Comments  路  Source: alex3165/react-mapbox-gl

I originally thought this was the onClick being finicky, #532 . However, it appears to be something else. onClick works for the area of the image, but not all the time. I can click the feature once, onClick populates a state variable with the data to be loaded into the popup. The popup displays because the state variable is no longer null.

Clicking on the popup set the state variable to null and closes the popup. However, clicking on the feature icon image no longer works. This seems to be resolved by scrolling the mouse wheel and zooming in a bit and trying again a few times.

<Map ref={(e) => { this.map = e; }}
    style="mapbox://styles/mapbox/streets-v9"
    containerStyle={{
    height: "100%",
    width: "100%",
    }}
    center={this.state.center}
    zoom={this.state.zoom}>

    <Layer
        type="symbol"
        layout={{ "icon-image": 'mapMarker', 'icon-anchor': "bottom", "icon-size": 0.6}}
        images={[mapMarker[0], mapMarker[1]]}>
        {this.state.markers}
    </Layer>
        {active ?
        (<Popup coordinates={[active.lon, active.lat] }
            anchor={'bottom-left'}
            offset={[0, -86]}
            onClick={() => {
                this.setState({active: null});
                }}>
<popup html stuff>
           </Popup>) : null 
    }
</Map>

this.state.markers is an array of features. It looks like this:

                markers.push(                    
                        <Feature key={item.id}  coordinates={[item.lon, item.lat]}
                         onClick={() => this.handleClick(item)} />
                );

With my handleClick having console logging to make things visible (in case there was something wrong with my popup code but there wasn't)

    handleClick(item) {
        this.setState({active: item});
        console.log("Fucking clicked");
    }

Any ideas?

Bug

Most helpful comment

@alex3165 is this a mapbox-gl or react-mapbox-gl issue?

All 3 comments

Hey @edv4rd0 , I tried a bit and managed to reproduce it, I will spend some time on it asap to understand if it is a mapbox-gl or react-mapbox-gl issue.

Thank you :-) I'm pretty impressed at how active you are on this project.

@alex3165 is this a mapbox-gl or react-mapbox-gl issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

laithalzyoud picture laithalzyoud  路  4Comments

stereobooster picture stereobooster  路  4Comments

loverdeveloper picture loverdeveloper  路  3Comments

JoshuaVulcan picture JoshuaVulcan  路  4Comments

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