map.setPaintProperty for circle-radius on mouseleave events causes other events to stop working
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
**mapbox-gl-js version**
:0.52.0
I have added a layer in the mapbox having 3 points.
On **click** of the point, I want to show a popup. For that, I have used the following code
`map.on('click', id, function (e) {
var coords = getMarkerLatLng(e, type);
new mapboxgl.Popup()
.setLngLat(coords)
.setHTML("Pooint Clicked")
.addTo(map);
})`
Then on hover of the point, I want to make the hovered point bigger by increasing the radius of the point.
After the mouse hover when the mouse leaves the point, the point should be back to its original size.
To increase the hovered point radius I use the following code
` map.on('mouseenter', id, function (e) {
if (e.features.length) {
map.getCanvas().style.cursor = "pointer";
//map.setPaintProperty(id, 'circle-color', ["case", ["==", ["id"], e.features[0].id], '#180C00', '#32CD32']);
map.setPaintProperty(id, 'circle-radius', ["case", ["==", ["id"], e.features[0].id], 12, 5])
}
})`
Then after the mouseleave event to make the point restore to its original size, I use the following code
`map.on('mouseleave', id, function (e) {
map.getCanvas().style.cursor = "";
//map.setPaintProperty(id, 'circle-color', '#32CD32');
map.setPaintProperty(id, 'circle-radius', 5);
})`
However, once I set the **circle-radius** in **mouseleave** event using map **setPaintProperty**, after that other event stop working. .i.e. **click** and **mouseenter** stop working. You can not **click** or **mouseenter** on a point
But, if you zoom in or zoom out, then the event start firing again.
If you change the point **cirlce-color** instead of the **circle-radius** on the **mouseenter** and **mouselaeve** event, all works fine.
So if you use the code
`map.on('mouseleave', id, function (e) {
map.getCanvas().style.cursor = "";
map.setPaintProperty(id, 'circle-radius', 5);
})`
Other event stops working.
However, if you use the code
` map.on('mouseleave', id, function (e) {
map.getCanvas().style.cursor = "";
map.setPaintProperty(id, 'circle-color', '#32CD32');
})
});`
all works fine
I have created 2 js fiddle for the demo
Mapbox point change circle-color working fine
https://jsfiddle.net/devsumitparkash/ak9L1g46/
Mapbox point set circle-radius change and giving the issue
https://jsfiddle.net/devsumitparkash/bvw379t0
I think in both cases the event should work the same.
So can anyone suggest is there a bug or i am doing something wrong.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the two JSFiddle reproductions and compare the mouseenter/mouseleave handlers that change circle-radius with those that change circle-color. Trace the layer event behavior after the radius reset; done means click and mouseenter continue firing without requiring a zoom.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100