OpenLayers 3 Defining axis ordering

我与影子孤独终老i 提交于 2019-12-11 10:16:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!