[英]Center polygon in open layers - 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
執行時它指向多邊形的邊緣,而不是多邊形的中心,有人可以建議我一些解決方案。
根據您的問題,我覺得您需要獲取多邊形的邊界。我已經使用過屬性來獲取邊界。 然后放大地圖。
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.