0

I am trying to allow users on my app to define a "territory" (as a polygon). Then others can query a point (lat and long), to determine whos territory that point falls in. I have determined from the docs for GeoAlchemy2, that this would likely be a good tool for the job (my app is curently in dev, so I am open to other suggestions. I am using flask, flask-sqlalchemy, and Sqlite in dev... plan on Postgres in prod. AngularJS for frontend).

My search lead me to ng-map, specifically the drawing manager directive seen here. https://ngmap.github.io/#/!drawing-manager.html. In modifying the example, I can get to the google onMapOverlayCompleted object. In there I see a latLng object, but am unsure how to transform it into something I can persist in the database. Assuming I do this in JS, can I dump it to JSON to send to my Flask API?

Can anyone point me in the right direction on how to do this? I am more than willing to listen to better ideas.

Thanks.

Here is some code from that example:

var app = angular.module('myapp', ['ngMap']);
app.controller('DrawingManagerCtrl', function() {
  var vm = this;
  vm.onMapOverlayCompleted = function(e){
    console.log(e);
  };
});

How can I get the polygon from 'e'?

GMarsh
  • 2,401
  • 3
  • 13
  • 22
  • Please have you an idea about this error? Uncaught TypeError: Cannot read property 'onMapOverlayCompleted' of undefined – Ne AS May 02 '17 at 23:31

1 Answers1

0

You can check this answer https://stackoverflow.com/a/38827199/785985 on how to get the array of points. It's this code:

e.overlay.getPath().getArray();

Then you can iterate the array and get each item latitude and longitude. So your code becomes:

vm.onMapOverlayCompleted = function(e){
  console.log(e);
  e.overlay.getPath().getArray().forEach(function (position) {
    console.log('lat', position.lat());
    console.log('lng', position.lng());
  });
}
Community
  • 1
  • 1
Rodrigo Saling
  • 396
  • 4
  • 9
  • Please have you an idea about this error? Uncaught TypeError: Cannot read property 'onMapOverlayCompleted' of undefined – Ne AS May 02 '17 at 23:31
  • @Llg Are you using my function together with GMarsh's code? You have to define `vm` variable like he did: `var vm = this;`. – Rodrigo Saling May 03 '17 at 11:53