简体   繁体   English

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

[英]How to get new coordinates of the edited shape and calculate the center dynamically

I'm using ngmap in my application. 我在我的应用程序中使用ngmap I was able to display a polygon from its coordinates using shape . 我能够使用shape从其坐标显示多边形。 Now I want to make this polygon editable. 现在我想让这个多边形可编辑。 I referenced this link and my polygon is now editable. 我引用了这个链接 ,我的多边形现在可以编辑了。 The problem is that I can't find how can I get the new coordinates. 问题是我无法找到如何获得新坐标。

Is there any events as onMapOverlayCompleted in the drawing-manager ? drawing-manager是否存在onMapOverlayCompleted事件?

How can I get the new coordinates? 我怎样才能获得新坐标?

Also how can I calculate the value of the center attribute dynamically 另外,我如何动态计算center属性的值

It depends on the shape type, in case of Rectangle to determine the resized bounds you could utilize bounds_changed event. 它取决于形状类型,在Rectangle情况下确定可以使用bounds_changed事件的调整大小的边界。 The following example demonstrates how to print the resized size of rectangle: 以下示例演示如何打印调整大小的矩形:

 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM