开放层中的中心多边形 - osm api

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

在执行时它指向 polygon.Not 的边缘 polygon.Could 的中心有人建议我一些解决方案来解决这个问题。

根据您的问题,我觉得您需要获取 polygon.I 的范围,这些范围已与属性一起使用以获取范围。 然后放大地图。

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);

}