Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layer event handlers are not being triggered as expected when using type raster #782

Open
laithalzyoud opened this issue Oct 4, 2019 · 4 comments

Comments

@laithalzyoud
Copy link

Hello everybody,

I'm trying to use the OnClick,OnMouseEnter,OnMouseLeave event handlers within the Layer component and they are not doing anything, i'm rendering images on the map using a source of type image and a layer of type raster and want to be able to click the image but when I click nothing happens! Here is how i'm implementing it:

const renderedImagesLayers = renderedImagesData.map((data) => 
            <Layer
            id={data.id}
            type={data.type}
            sourceId={data.sourceId}
            before={data.before}
            onMouseEnter={e => this.onToggleHover(e,'pointer')}
            onMouseLeave={e => this.onToggleHover(e,'')}
            onClick={e=>console.log(e)}
            ></Layer>
        )

I'm using the onClick method in the Map component as well, can this be causing the above issue?
I'm using the following versions:
react-mapbox-gl: "4.6.0"
react: "16.9.0",

@laithalzyoud laithalzyoud changed the title Layer even handlers not being triggered as expected when using type raster Oct 4, 2019
@Robert-OP
Copy link

Hello, I have the same issue, no event handlers trigger when using Layer component of type "raster"

      <Source
        id="source_id"
        tileJsonSource={RASTER_SOURCE_OPTIONS}
      />
      <Layer
        type="raster"
        id="layer_id"
        sourceId="source_id"
        onClick={() => console.log('layer click')}
      />
@jevy-wangfei
Copy link

jevy-wangfei commented Feb 13, 2020

Same here, Mouse enter/leave and click are not triggered:

<Source id="source_id" tileJsonSource={Image_SOURCE_OPTIONS} />
<Layer type="raster" id="layer_id" sourceId="source_id"
            onMouseEnter={(map) => console.log('mouse enter', map)}
            onMouseLeave ={(map) => console.log('mouse leave', map)}
            onClick ={(map) => console.log('onclick', map)}
 />
@jussirantala
Copy link

jussirantala commented Feb 21, 2020

I got the same problem with Layer and Feature when using heatmap type.

I use:
react-mapbox-gl @ 4.8.2
react @ 16.12.0
react-dom @ 16.12.0

@laithalzyoud
Copy link
Author

Here is a workaround I used to avoid this bug by using a transparent GeoJSONLayer over my raster with the same size:

const polygonGeoJSON = {
                "type": "FeatureCollection",
                "features": [{
                    "id": "ID",
                    "type": "Feature",
                    "properties": {
                        "sourceId": SOURCE_ID
                   },
                    "geometry": {
                        "type": "Polygon",
                        "coordinates": YOUR_COORDINATES
                    }
                }]
}
const fillLayout = { visibility: 'visible' };
const fillPaint = {
    'fill-color': '#FFFFFF',
    'fill-opacity': 0
};

<GeoJSONLayer
     id={'geojson-' + IMAGE_KEY.id}
     data={polygonGeoJSON}
     fillLayout={fillLayout}
     fillPaint={fillPaint}
     fillOnClick={YOU_FUNCTION}
     fillOnMouseEnter={e => this.onToggleHover(e, 'pointer')}
     fillOnMouseLeave={e => this.onToggleHover(e, '')}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants