x

OpenLayer - Polygon - geoJson - coordinates max 90 degrees?


Geschrieben von slart (Gast) am 30. September 2017 13:23:23: [flux]

Hallo,
habe gerade ein Problem mit dem openlayern eines Polygons mittels OpenLayer und geoJson sowie ein coordinates-Javascript.

Also, die coordinates für das geoJson werden von einem Javascript geliefert. Die Variable packe ich in geoJson bei coordinates in das OpenLayer-Script.

Simples Beispiel ohne Befüllung mit Variable funktioniert:

var␣geojsonObject␣=␣{
'type':␣'FeatureCollection',
'crs':␣{
'type':␣'name',
'properties':␣{
'name':␣'EPSG:4326'
}
},
'features':␣[{
'type':␣'Feature',
'geometry':␣{
'type':␣'Polygon',
'coordinates':␣[[[90,␣360.00000],[0,␣-80.00000],[15.00000,␣-80.00000],[15.00000,␣80.00000],[90,␣360.00000]]]
}
}]
};

Mit Befüllung per Variable funktioniert es nicht.

<script>
...
var␣daynightcoords␣=␣_compute();
var␣geojsonObject␣=␣{
'type':␣'FeatureCollection',
'crs':␣{
'type':␣'name',
'properties':␣{
'name':␣'EPSG:4326'
}
},
'features':␣[{
'type':␣'Feature',
'geometry':␣{
'type':␣'Polygon',
'coordinates':␣[[daynightcoords]]
}
}]
};
...
</script>

Die Variable "daynightcoords" gibt dies aus (getestet):

<div␣class="latalotadivbox"␣id="latalotadivbox"></div>
<script>
var␣daynightcoords␣=␣_compute();
document.getElementById("latalotadivbox").innerHTML␣=␣daynightcoords;
</script>

//Ausgabe: [90, -360],[87.01943164067522, -360],[87.01884377928964, -359],[87.01734860220394, -358],[87.01494383637005, -357],[87.01162582021618, -356],[87.00738949003994, -355],[87.00222836112842, -354],[86.99613450347368, -353],[86.98909851191414, -352],[86.98110947049153, -351],[86.97215491077074, -350],[86.96222076382345, -349],[86.95129130552789, -348],[86.93934909478364, -347] ...

Aber, das manuelle Befüllen mit den Werten der Variable funktioniert auch nicht, bzw. nur begrenzt:

<script>
var␣geojsonObject␣=␣{
'type':␣'FeatureCollection',
'crs':␣{
'type':␣'name',
'properties':␣{
'name':␣'EPSG:4326'
}
},
'features':␣[{
'type':␣'Feature',
'geometry':␣{
'type':␣'Polygon',
'coordinates':␣[[[-50.99759410853572,␣270],[-41.97588008988466,␣271],␣...␣[87.0174264018178,␣360],[90,␣360]]]
}
}]
};
...
</script>

Nun habe ich die Anzahl der Koordinaten gezählt, aber daran liegt es nicht.
Dann habe ich die Koordinaten in ihrer Anzahl gekürzt, von vorne nach hinten und bin bei Longitude 271 angelangt, bei der es noch funktioniert.
Also,
von 271 bis 360 funktioniert (89°).
Von 270 bis 360 funktioniert nicht (90°).
Von 270.5 bis 360 funktioniert (89.5°).

Funktioniert noch:

<script>
var␣geojsonObject␣=␣{
'type':␣'FeatureCollection',
'crs':␣{
'type':␣'name',
'properties':␣{
'name':␣'EPSG:4326'
}
},
'features':␣[{
'type':␣'Feature',
'geometry':␣{
'type':␣'Polygon',
'coordinates':␣[[[-50.99759410853572,␣270.5],[-41.97588008988466,␣271],␣...␣[87.0174264018178,␣360],[90,␣360]]]
}
}]
};
...
</script>

Was mache ich da jetzt?
Ich brauche das Polygon von ... bis:
[90, -360],[87.01943164067522, -360],[87.01884377928964, -359],[87.01734860220394, -358],[87.01494383637005, -357], ... [86.99128766305708, -8],[86.99804270624375, -7],[87.00385856551425, -6],[87.00874420435376, -5],[87.01270712055748, -4],[87.01575337441328, -3],[87.01788761136476, -2],[87.0191130793127, -1],[87.01943164067522, 0],[87.01884377928964, 1],[87.01734860220394, 2],[87.01494383637005, 3],[87.01162582021618, 4],[87.00738949003994, 5],[87.00222836112842, 6],[86.99613450347368, 7],[86.98909851191414, 8], ... [87.00874420435376, 355],[87.01270712055748, 356],[87.0157533744133, 357],[87.01788761136476, 358],[87.0191130793127, 359],[87.01943164067522, 360],[90, 360]
Also 360°.


Antworten: