leafletmapzen

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


Solution

  • 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);
    });