Google Maps Directive - drawing polygons

1,250 views
Skip to first unread message

Nolan Dubeau

unread,
Aug 29, 2012, 12:45:46 PM8/29/12
to ang...@googlegroups.com
Hi folks,

Here's a fiddle - http://jsfiddle.net/ZmwdD/  - which uses the Angular-UI Google Maps directive as well as an external Config object of lat/lng coordinates which are coming from a server side query.  If this fiddle were to work it should draw a reverse polygon on the map (sometimes referred to as a cut-out or donut).  The fiddle indicates that the Config object can be accessed okay, however the rendering of the polygon does not take place.  I tried adding a $scope.$apply() however this throws an error indicating that a $digest is already in progress.

Any ideas on what i'm doing wrong?

Thank you!

Nolan

Roy Choo

unread,
Aug 29, 2012, 12:57:05 PM8/29/12
to ang...@googlegroups.com
hmmm.. i just created a test button... and it seems ok.
http://jsfiddle.net/roychoo/r39R5/1/

maybe i am missing something?

Regards
Roy

Nolan Dubeau

unread,
Aug 29, 2012, 1:48:51 PM8/29/12
to ang...@googlegroups.com
Hi Roy,

Nice.  yep, looks like it works okay when you call it from the button.  I will need to double check what's going on with my app code.

I added a watch so that it could the polygons could be drawn as soon as the map is ready. http://jsfiddle.net/nolandubeau/Aajav/

Thanks.

Nolan

Mike McElroy

unread,
Aug 29, 2012, 4:01:11 PM8/29/12
to ang...@googlegroups.com
Does this give you your desired behavior?

Basically, I tied the drawGeofence() function to the map-tilesloaded event (see ui-event in HTML), and made it a closure which selectively runs on the firstLoad (see $scope.drawGeofence in JS).

-Mike

Nolan Dubeau

unread,
Aug 29, 2012, 5:10:14 PM8/29/12
to ang...@googlegroups.com
Hi Mike,

Sure does.  Using the ui-event seems much cleaner.  Thank you!

Nolan

Mike McElroy

unread,
Aug 29, 2012, 5:38:52 PM8/29/12
to ang...@googlegroups.com
It seems like a slightly inefficient way to do it, since the event gets fired all the time as you're moving around the map or zooming in or out (but technically, the event is always fired anyways, it just doesn't have listeners attached to it regularly).  Perhaps you could deregister the function somehow instead of setting the boolean on that first load?

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

Reply all
Reply to author
Forward
0 new messages