NickCTL
NickCTL

Reputation: 11

Mapzen Search - Zoom to Search Pin

I am developing a Leaflet map that includes a MapZen address search. I cant find any information on how to zoom in on the search pin after an address is selected and the map pans to the pin. Does anyone know how to do this?

Thank you,

Nick

Upvotes: 0

Views: 115

Answers (2)

Hanbyul Jo
Hanbyul Jo

Reputation: 16

Mapzen Leaflet Geocoder (which is part of mapzen.js) doesn't offer zoom level change by default when the result's geometry type is point. However, you can listen to the events that Geocoder element fires, execute setZoom. You can check all the events that Mapzen Leaflet Geocoder fires here: https://github.com/mapzen/leaflet-geocoder#events

This is the example snippet listening to select event, change the zoom level of the map.

var map = L.Mapzen.map('map');
map.setView([0,0], 13);

var geocoder = L.Mapzen.geocoder();
geocoder.addTo(map);

var desiredZoomLevel = 17;

wgeocoder.on('select', function (e) {
map.setZoom(desiredZoomLevel);
});

Upvotes: 0

John Oram
John Oram

Reputation: 1

Have you taken a look at mapzen.js? It's a Leaflet extension that provides a search box that autozooms to the selected result.

https://mapzen.com/documentation/mapzen-js/

https://mapzen.com/documentation/mapzen-js/search/

Upvotes: 0

Related Questions