如何在 OpenLayers 中混合具有不同坐标系的图层?
我正在使用 OpenLayers 地图,我想在其中使用不同的地图服务器,它们使用不同的坐标系。 OpenLayers可以将其集成在同一个地图中并自动转换坐标系吗?
I'm using an OpenLayers-map and I want to use in it different mapservers, that use different coordinate systems. Can OpenLayers integrate it in the same map and automatically converts coordinate-systems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据图层的不同,您始终会拥有某种无法真正转换的基础图层(地图)。 如果您想在该地图上添加数据(标记、地理 json 内容等),您必须将其转换为基础层正在使用的投影。
对于标记,可以通过以下方式轻松完成:
查看有关将位置从一个系统转换到另一个系统的 Openlayers 文档。
Depending on the layers, you will always have some sort of baselayer (the map) wich you can't really convert. If you want to add data (markers, geo json stuff, etc) on that map you will have to convert it to the projection the baselayer is using.
For markers this can easyly be done by:
Check out the Openlayers documentation about transforming location from one system to another.
如果地图服务器提供不同的栅格,那么您可能会运气不好。
但是,如果他们提供矢量(例如 KML 文件)或 JavaScript 编写的地图对象(例如 Dre 的答案),那么您可以在不同的投影之间进行转换,以便所有数据都显示在与底图相同的投影和坐标系上。 OpenLayers 有此功能的钩子(请参阅 Dre 的答案),但您可能必须包含提供该功能的 Proj4JS 库。
或者您可以自己使用 Proj4JS 在绘图之前转换坐标。
If the map servers are providing different rasters then you may be out of luck.
However, if they are providing vectors (eg. KML files) or JavaScript-written map objects (eg. Dre's answer) then you can transform between different projections, so that all the data appears on the same projection and coordinate system as the base map. OpenLayers has the hooks for this (see Dre's answer) but you will probably have to include the Proj4JS library which provides the functionality.
Or you could use Proj4JS yourself to transform the coordinates before plotting.
这是一个老问题,但我在搜索中发现了这个问题,并认为我可能会插话,以防这对其他人有帮助。
这可能与所提出的问题所面临的情况有所不同,但我最近遇到了类似的情况。 就我而言,我需要在一张地图上显示两个不同 WMS 提供商的输出。 一个在 EPSG:900913 中提供服务,另一个在 EPSG:3857 中提供服务。 知道这些在功能上是等效的,我想我是否可以以这样的方式请求它们:使服务正常工作,地图能够与输出一起工作。 我的地图位于 900913(因此其他服务默认请求使用此投影)。
我如何正确请求其他服务的方法如下(填写您的信息):
通常将
?request=getCapability
附加到服务 URL 将允许您查看可从以下位置获得哪些投影所需层的 CRS 标签中的服务。This is an old question, but I came across this from a search and thought I might chime in in case this is helpful to others.
This may vary from the situation faced in the question posed, but I ran into a similar situation recently. In my case, I needed to show the output from two different WMS providers on one map. One provided their services in EPSG:900913, the other in EPSG:3857. Knowing that these are functionally equivalent, I figured if I could just request them in a way that made the services work, that the map would be able to work with the output. My map is in 900913 (and the other services therefore request using this projection by default).
How I was able get the other service to be requested correctly was as follows (with your information filled in):
Usually appending
?request=getCapabilities
to the service URL will allow you to see what projections are available from the service in the CRS tags of a desired layer.