Openlayers 3中心地图 [英] Openlayers 3 center map

查看:88
本文介绍了Openlayers 3中心地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在唱 OpenLayers 3 来显示地图。我想使用latLon坐标使地图居中。
我开始使用快速入门代码
使用此代码,我无法更改地图的中心。我认为这与球形墨卡托投影有关。唯一的问题是,我只有lat lon坐标。

I'm sing OpenLayers 3 to display a map. I want to center the map using latLon coordinates. I'm using the quickstart code to begin with. Using this code, I cannot change the center of the map. I think this has something to do with Spherical Mercator projection. Only thing is, I only have lat lon coordinates.

有没有人知道如何从openlayers v3中心地图?

Does anyone know how to center a map from openlayers v3?

推荐答案

您需要使用

var olCoordinates = ol.proj.transform([lon, lat],"WGS84", "EPSG:900913")

现在您可以使用olCorrdinates设置中心。

Now you can set center with olCorrdinates.

不同的投影具有不同的代码名称。 WGS84是普通lon / lat和EPSG:900913是网络地图中常用的投影,如谷歌地图,openstreetmap和bing。

Different projections has different code names. WGS84 is "normal" lon/lat and EPSG:900913 is the projection often used in web maps like google maps, openstreetmap and bing.

我认为OpenLayers 3已内置支持从WGS84 / EPSG转换:4326(lon / lat),但如果需要转换为其他坐标系或从其他坐标系转换,则可以包含proj4js库。 Openlayers将与此lib集成,并能够以相同的方式进行转换。

I think OpenLayers 3 has built in support for transforming from WGS84/EPSG:4326 (lon/lat), but if you need to convert to or from other coordinate systems you can include the proj4js library. Openlayers will integrate with this lib and be able to do the transformations in the same way.

转换文档
http://openlayers.org/en/v3.1.1/apidoc/ol.proj.html

Proj4 lib
https://github.com/proj4js / proj4js

Proj4 lib https://github.com/proj4js/proj4js

编辑:
在您所参考的示例中,中心位置实际上是使用lon / lat设置的。

In the example you are refering to, the center location is actually set with lon/lat.

view: new ol.View({
    center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),
    zoom: 4
})

EPSG:4326实际上与WGS84和EPSG相同:3857与EPSG相同:900913。这非常令人困惑。我自己去过那里。

EPSG:4326 is actually the same as WGS84 and EPSG:3857 is the same as EPSG:900913. This is very confusing. I have been there myself.

你只需要将数字37.41和8.82更改为你的lon / lat坐标。如果要在初始化后更改中心位置,则需要使用setCenter();

You just need to change the numbers 37.41 and 8.82 to your lon/lat coordinates. If you want to change the center location after initialization you will need to use setCenter();

map.getView().setCenter(ol.proj.transform([lon, lat], 'EPSG:4326', 'EPSG:3857'))

这篇关于Openlayers 3中心地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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