Mapzen Search - Zoom to Search Pin

114 Views Asked by At

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

2

There are 2 best solutions below

3
On BEST ANSWER

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);
});
1
On

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/