mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.2k stars 2.22k forks source link

identify location on an extrusion on click #9885

Open stepanchvatik opened 4 years ago

stepanchvatik commented 4 years ago

mapbox-gl-js version: 1.11.1

browser: Chrome

Create extruded polygon, then add listener on click, using queryRenderedFeatures. But when I click forexample corner of roof of high building, the gps I get is from map point I clicked, not from the base of that building. The marker moves to the point that I click

Snímek obrazovky 2020-07-21 v 12 02 33 Snímek obrazovky 2020-07-21 v 12 02 43
danvk commented 3 years ago

It's pretty elaborate, but I got this to work! Here's a codepen demo

The general approach is:

If you open the console in the codepen and click around, you'll see that it has the right properties. Clicking up a wall increases the altitude without changing that (lng, lat). And clicking along the top of a wall changes the (lng, lat) without changing the altitude. This could also be used to get the distance to the feature, solving #9729.

One unfortunate bit is that you have to hard-code the base_height and height properties because of this bug: #9632