Вопрос

I need to be able to center the leaflet map on a marker when the appropriate button is click.

<button onclick='getLoc(" + geojson.features[i].geometry.coordinates[0] + "," +     geojson.features[i].geometry.coordinates[1] + ")'>View</button>



function getLoc(c){
var c = L.GeoJSON([lng,lat]);
}

I'm stuck from here, any help to finish this would be greatly appreciated. Or if anyone else has a different way of doing it using JSON.

Это было полезно?

Решение 2

I managed to solve this problem

Here is the solution

<button onclick='getLoc(" + geojson.features[i].geometry.coordinates[0] + "," +     geojson.features[i].geometry.coordinates[1] + ")'>View</button>


function getLoc(lat, lng){
    map.setView(new L.LatLng(lat, lng), 12);
    }

Другие советы

I think what you're looking for is the setView method. Assuming that your map variable is called map, you can set the lat/lng of the map by calling the method like this:

map.setView([51.505, -0.09], 13); // ([lat, lng], zoom)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top