Created
October 20, 2017 19:48
-
-
Save dfrho/48155b306b4fc068c8d8c84e6b012947 to your computer and use it in GitHub Desktop.
queryRenderedFeatures mapbox gl-js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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