问题
I run into a problem that my GeoJSON return coordinates in a latitude/longitude order, but OpenLayers wants them to be in reversed order: longitude/latitude. And I cant't get them another way from server. Is it possible to reverse coordinates using OL3, like I found something about old OL like this
formatOptions: { xy: false }
Does something like this available in OL3?
回答1:
The short answer is no. OL3 only accepts XY. If you have the possibility to reverse it in your GeoJSON source, do that.
In the ol3 documentation you should have the possiblity to make a custom transform by using the method "applyTransform" on each of your geometries in your featrures, but but this method is appearently removed.
Below is a suggestion to how you can reverse your coordinates.
$.ajax({
url: "http://www.myjsonsource.com",
timeout: 1000,
success: function(response) {
var layerJSONString = $.parseJSON(response);
var size=layerJSONString.features.length;
for (i = 0; i < size; i++){
layerJSONString.features[i].geometry.coordinates.reverse();
};
vectorSource.addFeatures(vectorSource.readFeatures(response));
},
error: loadError
});
来源:https://stackoverflow.com/questions/27122778/openlayers-3-defining-axis-ordering