OpenLayers 3定义轴顺序 [英] OpenLayers 3 Defining axis ordering

查看:178
本文介绍了OpenLayers 3定义轴顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到一个问题,我的GeoJSON按照纬度/经度顺序返回坐标,但OpenLayers希望它们按照相反的顺序:经度/纬度。
我不能从服务器获取它们。
是否可以使用OL3来反转坐标,就像我发现了一些关于旧OL的东西,例如:

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 }

在OL3中有这样的功能吗?

Does something like this available in OL3?

推荐答案

简短的答案是否定的。 OL3只接受XY。如果您有可能在您的GeoJSON源代码中将其取消,请执行此操作。

The short answer is no. OL3 only accepts XY. If you have the possibility to reverse it in your GeoJSON source, do that.

    在ol3文档中,您应该有可能通过使用 applyTransform在你的几何体的每个几何体上,但是这种方法显然被删除了。

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        
});

这篇关于OpenLayers 3定义轴顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆