OpenLayers:为什么我的矢量功能标记放错了位置? [英] OpenLayers: Why are my Vectors Features Markers misplaced?

查看:85
本文介绍了OpenLayers:为什么我的矢量功能标记放错了位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先使用Markers编码(成功),然后意识到不再推荐使用它(尤其是用于聚类).

I first coded using Markers (with success) then realizing it was no more recommended (especially for clustering).

已阅读Openlayers文档和给出的示例. stackoverflow.com/questions/6026420/openlayers-vector-features-instead-of-markers>这个问题,我创建了我的Vector,添加了一些样式等...

Having read the examples given in Openlayers doc and this question, I've created my Vectors, added some style etc...

但是,它们全都放在LngLat(0,0)周围,而不是其正确的坐标上.

But, they are all put in around the LngLat(0,0) instead of their proper coordinates.

您可以看到它们的几何属性在下面.我不知道我在那儿想念什么.

You could see below their geometry properties are ok. I don't know what I'm missing there.

推荐答案

问题在于,尽管Google Maps投影为EPSG:900913,但矢量要素的坐标却位于EPSG:4326中.

The problem is that while Google Maps projection is EPSG:900913, coordinates of your vector features are in EPSG:4326.

因此,您必须在Google Maps投影中指定坐标,或使用OpenLayers在客户端上转换坐标.操作方法如下:

So you have to either specify coordinates in Google Maps projection or use OpenLayers to transform coordinates on the client side. Here's how you do it:

feature.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"))

变换要素后,您可以在地图上添加图层,并且该地图应正确显示要素.

Once you transformed features you can add layer to the map and it should display features correctly.

这篇关于OpenLayers:为什么我的矢量功能标记放错了位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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