[英]OpenLayers LonLat transform
I want to use decimal Lon and Lat like Google Maps uses. 我想像Google Maps一样使用十进制Lon和Lat。 But it seems I need to transform the LonLat object in OpenLayers, eg 但是似乎我需要在OpenLayers中转换LonLat对象,例如
var map, layer;
function init(){
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
map.addLayer(layer);
map.setCenter(
new OpenLayers.LonLat(-1.60400390625, 54.07228265560386).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 6
);
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(0,0);
var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset);
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(-1.60400390625, 54.07228265560386).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject()),icon));
}
Each time I place a marker the position needs to be transformed to EPSG:4326. 每次我放置一个标记时,位置都需要转换为EPSG:4326。 Is there a way to tell the map to always use this projection? 有没有办法告诉地图始终使用此投影?
Whether you can set the projection on a map or not, depends on which service you are using for the base layer. 是否可以在地图上设置投影,取决于您用于基础层的服务。 As far as I know, OSM only provides its rendered tiles in EPSG:900913, so there is no way around transforming your coordinates before adding them to the map. 据我所知,OSM仅在EPSG:900913中提供其渲染的图块,因此在将坐标添加到地图之前没有办法进行变换。 You could search for a service that provides its tiles in multiple projections, but I haven't seen one that is free to use so far. 您可以搜索一种服务,该服务以多种投影方式提供其图块,但到目前为止,我还没有看到可以免费使用的一种服务。 An alternative would be to render your own tiles in the needed projection and provide them through your own tile server. 一种替代方法是在所需的投影中渲染您自己的图块,然后通过您自己的图块服务器提供它们。
Let's suppose you have such a map, you can change the projection using OpenLayers.Map.setOptions() like this: 假设您有这样一张地图,可以使用OpenLayers.Map.setOptions()更改投影,如下所示:
map.setOptions({
projection: "EPSG:4326"
});
But you may also need to set some projection related properties, like maxExtent
etc. See this question . 但是您可能还需要设置一些与投影有关的属性,例如maxExtent
等。请参maxExtent
问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.