mapbox / mapbox/mapbox-gl-js

Return original geometry for GeoJSON features in queryRenderedFeatures

Open
#11,591 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

## Motivation

Consider https://jsfiddle.net/w9bs8jot/. A GeoJSON Line feature is cut into multiple tiles and makes it impossible to query the entire line feature. A customer recently flagged this issue because they wanted users to be able to click on a line feature and get its start and/or end points.

## Design Alternatives

There's a potential workaround.

```
const selectedFeatures = map.queryRenderedFeatures(point);
selectedFeatures.forEach(feature => {
const source = map.getSource(feature.source);
// filter for the feature's original coordinates in the source
console.log('source data: ', source._data.features[0].geometry.coordinates);
})
```

## Design

We could add the original geometry to the features in a GeoJSON vector tile, although this may not be performant enough with large GeoJSON features.

Alternatively, queryRenderedFeatures needs a way to retrieve the original geometry for the feature.

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 JSFiddle and the queryRenderedFeatures API behavior described in the issue. Investigate how GeoJSON Line features are split across vector tiles and determine a design that lets callers retrieve the original geometry; done means a queried feature exposes the complete source geometry without making large features impractical.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.