admin管理员组文章数量:1310480
I tried to set map center by method setCenter, but still not working. Map is not moving. I tried to used transform from projection to map projection and without successful. Here is part of code. Thanks.
<script type="text/javascript">
var lon = 15.869378; //WGS LL84
var lat = 49.528964;
var zoom = 5;
var map, layer;
function init(){
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.TMS("Name",
"[URL]",
{ 'type':'png', 'getURL':get_my_url });
map.addLayer(layer);
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(lon, lat).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject())));
map.setCenter(new OpenLayers.LonLat(lon, lat).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()), zoom);
}
</script>
I tried to set map center by method setCenter, but still not working. Map is not moving. I tried to used transform from projection to map projection and without successful. Here is part of code. Thanks.
<script type="text/javascript">
var lon = 15.869378; //WGS LL84
var lat = 49.528964;
var zoom = 5;
var map, layer;
function init(){
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.TMS("Name",
"[URL]",
{ 'type':'png', 'getURL':get_my_url });
map.addLayer(layer);
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(lon, lat).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject())));
map.setCenter(new OpenLayers.LonLat(lon, lat).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()), zoom);
}
</script>
Share
Improve this question
asked Dec 3, 2013 at 8:30
MusketyrMusketyr
7731 gold badge19 silver badges40 bronze badges
2 Answers
Reset to default 4I think it may caused by wrong map projection, in your map you should set map projection (I use EPSG:900913 in the example), such as:
map = new OpenLayers.Map('testmap', {
numZoomLevels: 10,
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG: 4326")
});
if you don't do that, map.getProjectionObject() will still get the EPSG:4326 projection.
The marker is shown exactly in the point where it should be?
Anyway, try this:
map.setCenter(new OpenLayers.LonLat(lon, lat).transform('EPSG:4326', 'EPSG:3857'), zoom);
本文标签:
版权声明:本文标题:javascript - OpenLayers after call setCenter, map is still on 0,0 position - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741821015a2399363.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论