如何在 OpenLayers 中混合具有不同坐标系的图层?

发布于 2024-07-18 03:56:45 字数 89 浏览 11 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

追星践月 2024-07-25 03:56:45

根据图层的不同,您始终会拥有某种无法真正转换的基础图层(地图)。 如果您想在该地图上添加数据(标记、地理 json 内容等),您必须将其转换为基础层正在使用的投影。

对于标记,可以通过以下方式轻松完成:

// defining our coordinate systems
var google = new OpenLayers.Projection("EPSG:900913"),
    latlon = new OpenLayers.Projection("EPSG:4326");

// transforming the location to the right coordinate system
var location = new OpenLayers.LonLat( 10, 10 ).transform( latlon, google );

// assuming you made an icon and marker layer
var marker = new OpenLayers.Marker( location, icon );     

markerLayer.addMarker( marker );

查看有关将位置从一个系统转换到另一个系统的 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:

// defining our coordinate systems
var google = new OpenLayers.Projection("EPSG:900913"),
    latlon = new OpenLayers.Projection("EPSG:4326");

// transforming the location to the right coordinate system
var location = new OpenLayers.LonLat( 10, 10 ).transform( latlon, google );

// assuming you made an icon and marker layer
var marker = new OpenLayers.Marker( location, icon );     

markerLayer.addMarker( marker );

Check out the Openlayers documentation about transforming location from one system to another.

雪若未夕 2024-07-25 03:56:45

如果地图服务器提供不同的栅格,那么您可能会运气不好。

但是,如果他们提供矢量(例如 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.

别在捏我脸啦 2024-07-25 03:56:45

这是一个老问题,但我在搜索中发现了这个问题,并认为我可能会插话,以防这对其他人有帮助。

这可能与所提出的问题所面临的情况有所不同,但我最近遇到了类似的情况。 就我而言,我需要在一张地图上显示两个不同 WMS 提供商的输出。 一个在 EPSG:900913 中提供服务,另一个在 EPSG:3857 中提供服务。 知道这些在功能上是等效的,我想我是否可以以这样的方式请求它们:使服务正常工作,地图能够与输出一起工作。 我的地图位于 900913(因此其他服务默认请求使用此投影)。

我如何正确请求其他服务的方法如下(填写您的信息):

var myLayer = new OpenLayers.Layer.WMS(
    "Name",
    "URL", {
        "layer": "layer"
    });

myLayer.projection = "EPSG:3857";

通常将 ?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):

var myLayer = new OpenLayers.Layer.WMS(
    "Name",
    "URL", {
        "layer": "layer"
    });

myLayer.projection = "EPSG:3857";

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文