Sasha Nesteruk
Sasha Nesteruk

Reputation: 1

get coordinates of a marker symbol in mapbox-gl-js and center on it

I have this symbol on a map

map.addLayer({
    "id": "home",
    "type": "symbol",
    "source": "property",
    "interactive": true,
    "layout": {
        "icon-image": "rocket-15",
    }
});

I would like to zoom in to this marker and center on it.

So far I have tried this:

map.featuresIn({ layer: 'home' }, function(err, features) {
    console.log(features);
    map.flyTo({ center: features[0].geometry.coordinates,zoom: 11 });
});

I omit the coordinates argument, so I refer to it directly (as stated in API). However, the 'features' arrive empty and I can never fly

Upvotes: 0

Views: 2730

Answers (1)

Lucas Wojciechowski
Lucas Wojciechowski

Reputation: 3802

featuresIn does not return features' geometries by default. For that, you must include the includeGeometry: true parameter.

You will find this example helpful!

Upvotes: 1

Related Questions