Skip to content
Advertisement

How do you get the place name from a mapbox gl js returned queryRenderedFeatures?

Sample Code

  const features = map.queryRenderedFeatures(
        [point1,point2],
        {layers: ['national-park']}
    );
  console.log(features)

Lets say my bounding box is around long/lat [-155.4694, 19.8230], //Mauna Kea

My queryRenderedFeatures returns four results which is correct because my bounding box contain 4 national-parks. However I cannot find the place name in the geojson even though all of the national-park names are showing correctly on the map. Example place name would be Mauna Kea which is a national park.

Advertisement

Answer

You haven’t provided quite enough detail, but I’m guessing the reason is that the names of the national parks are in a separate layer, perhaps national-park-labels or similar.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement