如何计算ngmap多边形的中心?

时间:2017-05-26 13:42:59

标签: angularjs angularjs-directive ng-map

我正在使用ngmap,每当我导入KML多边形文件时,多边形就会被淹没在地图上。 我有一个关于缩放多边形的问题。 有没有办法计算多边形中心(纬度和经度)? 如果没有,那么无论如何都要在ngmap上绘制多边形后进行缩放。

谢谢

1 个答案:

答案 0 :(得分:0)

每当添加KML图层并将 var id_ele; $(".container-fluid .row").hover(function(){ id_ele = ''; id_ele = $(this).attr('id'); id_ele = '#' + id_ele; $('.nav--beca').find("a[href*='"+id_ele + "']").addClass('nav__item--current'); }, function(){ $('.nav--beca').find("a[href*='"+id_ele + "']").removeClass('nav__item--current'); }); 指令的Public Function unikue(BigString As String, LittleString As String) As String Dim B As Variant, L As Variant, Barr, Larr Dim Good As Boolean Barr = Split(BigString, ",") Larr = Split(LittleString, ",") For Each B In Barr Good = True For Each L In Larr If L = B Then Good = False Next If Good Then unikue = unikue & "," & B Next B If unikue <> "" Then unikue = Mid(unikue, 2) End Function 属性设置为preserve-viewport时,地图就会根据图层视口自动居中(这也意味着不需要明确指定中心)

确定KML图层中心:

1)设置kml-layer指令的true属性以引用KML图层

id

2)渲染图层后,获取KML图层的实例,然后通过kml-layer函数获取中心:

<kml-layer preserve-viewport="true" id="myLayer" url="http://googlemaps.github.io/js-v2-samples/ggeoxml/cta.kml"></kml-layer>

实施例

&#13;
&#13;
google.maps.KmlLayer.getDefaultViewport
&#13;
NgMap.getMap().then(function(map) {
        var layer = map.kmlLayers["myLayer"]
        var center = layer.getDefaultViewport().getCenter();       
});
&#13;
&#13;
&#13;