如何获取已编辑形状的新坐标并动态计算中心

时间:2017-05-05 14:17:51

标签: javascript angularjs google-maps polygon ng-map

我在我的应用程序中使用ngmap。我能够使用shape从其坐标显示多边形。现在我想让这个多边形可编辑。我引用了这个link,我的多边形现在可以编辑了。问题是我无法找到如何获得新坐标。

onMapOverlayCompleted中是否有drawing-manager个活动?

如何获取新坐标?

另外,如何动态计算center属性的值

1 个答案:

答案 0 :(得分:0)

取决于形状类型,如果Rectangle确定可以使用bounds_changed事件的已调整大小的边界。以下示例演示如何打印调整大小的矩形:



var app = angular.module('myapp', ['ngMap']);
app.controller('DrawingManagerCtrl', function (NgMap) {
    var vm = this;
    
    NgMap.getMap().then(function (map) {
            vm.map = map;
    });

    

    vm.rectShapeResized = function (e) {
        var rect = vm.map.shapes[0]; //get the first instance of shape
        console.log(rect.getBounds().toString());  //print a new bounds
    };
});

<script src="https://maps.google.com/maps/api/js?libraries=placeses,visualization,drawing,geometry,places"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>


<div ng-app="myapp" ng-controller="DrawingManagerCtrl as vm">
    <ng-map zoom="7" center="48.8588377,2.2775177" map-type-id="ROADMAP" street-view-control-options="{position: 'LEFT_CENTER'}">
        
        <shape name="rectangle" 
          editable="true" on-bounds_changed="vm.rectShapeResized()" 
             bounds="[ [48.190, 2.649], [48.899, 3.443] ]">
          </shape>
    </ng-map>
</div>
&#13;
&#13;
&#13;