使用javascript移动Openlayer地图的中心 [英] Move the center of an Openlayer map with javascript
本文介绍了使用javascript移动Openlayer地图的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何使用javascript重新定位和缩放Openlayer地图?例如,我有一个包含城市的下拉菜单,当我选择其中一个城市时,中心和缩放将更改为当前城市,依此类推。
I need to know how to recenter and zoom an Openlayer map with javascript? For example, I have a dropdown menu with cities, when I select a one of those cities the center and zoom will change to the current city and so on.
推荐答案
是的,你可以做到。您只需要传递该城市的 lat
和 lon
并传递给此函数,它将把它放入 center
。
Yes you can do that. You will just have to pass the lat
and lon
of that city and pass to this function and it will put that in center
.
function setCenter(lat,lon) {
var lonlat = new OpenLayers.LonLat(lon, lat);
map.panTo(lonlat);
}
其中 map
是对象:
map = new OpenLayers.Map('map',{numZoomLevels:2});
此处存在 openlayermap
的所有示例:
http://openlayers.org/dev/examples/
这篇关于使用javascript移动Openlayer地图的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文