Skip to content

Instantly share code, notes, and snippets.

@dfrho
Created October 20, 2017 19:48
Show Gist options
  • Save dfrho/48155b306b4fc068c8d8c84e6b012947 to your computer and use it in GitHub Desktop.
Save dfrho/48155b306b4fc068c8d8c84e6b012947 to your computer and use it in GitHub Desktop.
queryRenderedFeatures mapbox gl-js
// set curser to pointer on icon mousehover
map.on("mousemove", function (e) {
var iconsUnderMouse = map.queryRenderedFeatures(e.point, {
layers: ["nycparks-ad16j1"]
});
map.getCanvas().style.cursor = iconsUnderMouse.length ? "pointer" : "";
});
// select icon if clicked on
map.on("click", function (e) {
var dogIconsClicked = map.queryRenderedFeatures(e.point, {
layers: ["nycparks-ad16j1"]
});
if (!dogIconsClicked.length) return;
// reset active UI shading on sidebar listing
var activeItem = document.getElementsByClassName("active");
if (activeItem[0]) {
activeItem[0].classList.remove("active");
}
var location = dogIconsClicked[0];
var listing = document.getElementById(
"listing-" + location.properties.Prop_ID
);
listing.classList.add("active");
// fly camera to location and spawn popup
flyToRun(location);
createPopUp(location);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment