angular-google-maps
angular-google-maps copied to clipboard
[2.1.X][master] Saving the coordinates of polygon drawn using drawingManager
How can I save the coordinates of polygon which is drawn using drawingManager and store it in array. As I am trying 'overlaycomplete' which is not working with listener $scope.$watch('map.drawingManagerControl.getDrawingManager', function (val) { if (!$scope.map.drawingManagerControl.getDrawingManager) { alert("Hello"); return; } google.maps.event.addListener($scope.map.drawingManagerControl.getDrawingManager, 'polygoncomplete', function (e) { alert("hello"); console.log(e.getBounds()); }); });
Which directive are you using for drawing?
I am using ui-gmap-manager directive
Did you figure this out? Im just wondering if its possible - I have a need to allow the user to draw a polygon then save its coordinates - .... maybe even some buttons for undo last point or 'start over' something like that -
I was able to get the event handler to work but I can't get the coordinates... or i dont know where they are in the returned object ...
$scope.drawingManagerEvents = { polygoncomplete: function(polygon) { console.log(polygon); } };
sorry but Im new to google maps and these directives and Im not sure what I should expect to work
With the state that the current drawing manager is in you can expect this to not work. It needs to be improved. I am looking for volunteers.
The eventhandler for the polygoncomplete event will receive a Google Map Polygon object hidden within its arguments. You can get the coordinates like so:
$scope.drawingManagerEvents = {
polygoncomplete: function(drawingManager, eventName, scope, args) {
var polygon = args[0];
var path = polygon.getPath();
var coords = [];
for (var i = 0 ; i < path.length ; i++) {
coords.push({
latitude: path.getAt(i).lat(),
longitude: path.getAt(i).lng()
});
}
}
};
Does anyone plan on working on this and submitting a PR.
Hi, I solved eh : D I'm doing the same and took two days but finally achieved eh
overlaycomplete : function(maps,eventName, scope, args){ var polygon = args[0]; console.log(polygon.overlay.getPath().getArray()); }
so PR or got it working with what is avail?
So, is this working and I should use it?
By adding "events" property to
<ui-gmap-drawing-manager options="drawingManagerOptions" control="drawingManagerControl" events="drawingManagerOptions.events"> </ui-gmap-drawing-manager>
$scope.drawingManagerOptions = { drawingControl: true, drawingControlOptions: { position: google.maps.ControlPosition.TOP_CENTER, drawingModes: [ google.maps.drawing.OverlayType.POLYGON ] }, events: { polygoncomplete: function(drawingManager, eventName, scope, args) { var polygon = args[0]; var path = polygon.getPath(); console.log(path) var coords = []; for (var i = 0 ; i < path.length ; i++) { coords.push({ latitude: path.getAt(i).lat(), longitude: path.getAt(i).lng() }); } console.log(coords); } } }
I hope this help