2015-04-06 179 views
-1

我想放大EPSG:3857投影的地圖上的邊界框。地圖應該放大到這裏的某個地方:Openlayers zoomtoextent縮放到另一個位置

https://www.google.co.il/maps/place/Netanya/@32.3047285,34.860532,12z/data=!3m1!4b1!4m2!3m1!1s0x151d400493c075d5:0x2cd995be543c3f22,但是將下面的代碼放到非洲附近海域的某個地方。你能讓我知道什麼是錯的嗎?

bounds = new OpenLayers.Bounds(); 
 
bounds.extend(new OpenLayers.LonLat(34.8660822,32.3172887)); 
 
bounds.extend(new OpenLayers.LonLat(34.8570271,32.2953077)); 
 
bounds.toBBOX(); 
 
map.openlayers.zoomToExtent(bounds); 
 
map.openlayers.updateSize();

回答

1

你必須從EPSG改變你的邊界:4326(WGS84)到EPSG:900913(EPSG:3857)

bounds = new OpenLayers.Bounds(); 
bounds.extend(new OpenLayers.LonLat(34.8660822,32.3172887)); 
bounds.extend(new OpenLayers.LonLat(34.8570271,32.2953077)); 
bounds.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); 
map.openlayers.zoomToExtent(bounds, true);