Ich habe meine GeoJSON Format wie folgt aus:Wie man automatisch auf ein Polygon im Flugblatt zoomt?
statesData.features.push({
"type":"Feature",
"id":"AFG",
"properties":{
"name":"Afghanistan"
},
"geometry":{
"type":"Polygon",
"coordinates":[
[
[
61.210817,
35.650072
],
[
62.230651,
35.270664
],
[
62.984662,
35.404041
],
ich diese Koordinaten zu lesen versuche und sie als
var coord = statesData.features[0].geometry.coordinates;
lalo = L.GeoJSON.coordsToLatLng(coord);
map.setView(lalo, 18);
coordsToLatLng( coords) Function that will be used for converting GeoJSON coordinates to LatLng points (if not specified, coords will be assumed to be WGS84 — standard [longitude, latitude] values in degrees).
Aber ich erhalte diesen Fehler in der Konsole
Uncaught Error: Invalid LatLng object: (undefined, 61.210817,35.650072,62.230651,35.270664,62.984662,35.404041...
UPDATE
Die erste Antwort ist richtig, da es das Problem oben löst, ist es jedoch zoomt die Karte auf den ersten Satz von Koordinaten während dem, was ich wirklich zu erreichen versuchen, die Seite zu können, ist laden mit der Karte automatisch auf ein Polygon gezoomt (ich lade nur ein Polygon).
This example is the closest i could find
der Koordinaten ist ein Array von Koordinaten, innerhalb einer Anordnung, nach innen eine Anordnung. Ist das nicht mindestens ein Array zu viel? Kann 'setView()' mehr als eine Koordinate behandeln? – JJJ
@JJJ Ich versuche automatisch auf ein Polygon zu zoomen –
Es gibt auch eine ['coordsToLatLngs()'] (http://leafletjs.com/reference.html#geojson-coordstolatlngs) -Funktion (beachten Sie den Plural "s") das kann mit einem 'coordinates' Array umgehen (' [[[], [], ...], [[], [], ...]]). Die 'coordsToLatLng()' übersetzt nur eine Koordinate. Sie müssen eines der lat/lng-Paare in 'coordinates' auswählen. 'setView()' verwendet auch nur eine Koordinate (lat/lng). – Andreas