2015-10-19 23 views
0

我曾與開放層與下面的功能 -中心多邊形打開圖層 - OSM API

function centerIn(longitude,latitude){ 
lonlat = new OpenLayers.LonLat(longitude, latitude).transform(
    new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 
    new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection 
); 
map.setCenter(new OpenLayers.LonLat(lonlat.lon, lonlat.lat), 10); 
map.zoomTo(theZoom); 
} 

centerIn(0.99689177607425,44.1216337491133)爲中心的多邊形嘗試;

我的多邊形邊界是 - 1.18915251826175,44.069361365345 1.12048796748053,43.941939265001 1.45900420283204,43.9394671408999

在執行它指向polygon.Not的邊緣polygon.Could人的中心建議我一些解決方案解決此問題。

回答

0

根據你的問題,我覺得你需要得到多邊形的邊界。我已經使用了屬性來獲得邊界。 然後放大地圖。

function centerPolygon(){ 
console.log('centerPolygon'); 
var features_poly=vectorLayer.getFeaturesByAttribute('id',3); 
//console.log(features_poly[0].geometry.bounds); 
var bounds=features_poly[0].geometry.bounds; 
map.zoomToExtent(bounds); 

} 
+0

感謝您的建議。它非常有幫助。 – Hrithik