【问题标题】:Center polygon in open layers - osm api开放层中的中心多边形 - osm api
【发布时间】:2015-10-20 18:13:22
【问题描述】:

我已经尝试使用以下功能在开放层中将多边形居中-

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

在执行时它指向多边形的边缘。不是多边形的中心。有人可以建议我一些解决方案来解决这个问题。

【问题讨论】:

    标签: javascript jquery openlayers openstreetmap


    【解决方案1】:

    根据您的问题,我觉得您需要获取多边形的边界。我已使用属性来获取边界。 然后放大地图。

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

    【讨论】:

    • 感谢您的建议。非常有帮助。
    猜你喜欢
    • 2019-10-20
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 2015-03-19
    • 2016-08-10
    • 1970-01-01
    • 2020-05-04
    • 2011-11-21
    相关资源
    最近更新 更多