Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 开放层中的中心多边形-osm api_Javascript_Jquery_Openlayers_Openstreetmap - Fatal编程技术网

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

Javascript 开放层中的中心多边形-osm api,javascript,jquery,openlayers,openstreetmap,Javascript,Jquery,Openlayers,Openstreetmap,我尝试过在开放层中使用以下函数对多边形进行居中- 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 S

我尝试过在开放层中使用以下函数对多边形进行居中-

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

}

谢谢你的建议,非常有帮助。