pixon
pixon

Reputation: 63

Is it possible to click on labels in Mapbox like on Google maps?

Is it possible to click on labels in Mapbox and highlight the city like on Google maps?

Example Screenshot

Upvotes: 2

Views: 992

Answers (1)

anneb
anneb

Reputation: 5768

All visible map elements, including labels, in a mapbox-gl map can be clicked.

see https://www.mapbox.com/mapbox-gl-js/example/queryrenderedfeatures/

In that example, instead of catching the mousemove event, catch the click event like this:

map.on('click', function (e) {
    var features = map.queryRenderedFeatures(e.point);
    document.getElementById('features').innerHTML = JSON.stringify(features, null, 2);
});

Upvotes: 0

Related Questions