mapbox / mapbox/mapbox-gl-js

How to stop cursor flickering over icons?

Open
#11,569 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs information :pray: needs investigation :mag:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

How do I stop cursor flicker over my mapbox icons? Here is the live site where you can see the problem when hovering over the marker icons: https://rustic-waters-group.thesparksite.com/lakes/

```

mapboxgl.accessToken = "pk.eyJ1IjoiZG1pdHJpbWFydGluIiwiYSI6ImNreHRobHRmcjVqM3cydmt5NWkxdWNibTcifQ.CuN5Dwc963TW-BKRcowxBA";
const map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/dmitrimartin/ckxtj5aur4fvv15mrhmihala8",
center: [-89.2, 44.33],
zoom: 9.2,
});

map.on("load", () => {
const popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false,
});

map.on("mouseenter", "lakes", (event) => {
map.getCanvas().style.cursor = "pointer";
const features = map.queryRenderedFeatures(event.point, {
layers: ["lakes"],
});
if (event.features.length === 0) return;
popup.setLngLat(features[0].geometry.coordinates);
popup.setHTML(
"

" + features[0].properties.title + "

"
);
popup.setMaxWidth("calc(100vw - 40px);");
popup.addTo(map);
});

map.on("mouseleave", "lakes", () => {
map.getCanvas().style.cursor = "";
popup.remove();
});

map.on("click", "lakes", (event) => {
const features = map.queryRenderedFeatures(event.point, {
layers: ["lakes"],
});
if (event.features.length === 0) return;
window.location.href = "/lakes/" + features[0].properties.url + "/";
});

document.getElementById("lakes-header").onmouseover = function () {
MyMouseOver();
};

function MyMouseOver() {
document.getElementById("wrapper").style.display = "none";
document.getElementById("lakes-header").style.display = "none";
}
});

```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked live site and the provided map.on("load") handlers, especially the "mouseenter" and "mouseleave" listeners for the "lakes" layer. Reproduce the cursor behavior over the icons, trace the popup and cursor changes, and confirm completion when hovering no longer produces flicker.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.