Draw Polygons on Google Maps

101 views
Skip to first unread message

anasya...@gmail.com

unread,
Dec 24, 2017, 2:10:52 AM12/24/17
to Google Maps JavaScript API v3
I want my users to draw polygons on google maps but I want dynamic polygons with hovering the moused

Rob

unread,
Jan 2, 2018, 4:42:22 AM1/2/18
to Google Maps JavaScript API v3
This is certainly possible, but I would not recommend it, for the simple reason that many thousands of points could be generated in this way in just a couple of seconds.

You could use something like this (not tested) :

var aPolyPts = [];    // Global
var userDrawnPoly = new google.maps.Polyline();   // Global

google.maps.event.addListener(map, "mousemove", function(event) {
                    var pos = event.latLng;
                    //var lat = pos.lat();
                    //var lng = pos.lng();
                    aPolyPts.push(pos);
                    userDrawnPoly.setPath(aPolyPts);
                    userDrawnPoly.setMap(map);
});

Ideally, you would want to slow down the rate at which points are added to the polygon, either by placing a setTimeout() in the listener code or, better, not to use mousemove listener at all, but rather a click or rightclick listener so that points are only added to the polyline when the user clicks (or right-clicks) on the map.

HTH,
Rob

Estevão Soberano

unread,
Jan 7, 2018, 6:43:42 PM1/7/18
to Google Maps JavaScript API v3

What do you mean with dynamic polygons?

ciia...@gmail.com

unread,
Jan 18, 2018, 6:27:01 PM1/18/18
to Google Maps JavaScript API v3
Hello, I want save multiples poligon in database but separately someone have do it? or exits a pre-made script js/php??


Andrew Leach

unread,
Jan 18, 2018, 6:36:04 PM1/18/18
to google-map...@googlegroups.com
Please start a new thread for a new topic; don't reply to someone else's query with a question of your own.

A new topic will give you the chance to supply some more details. How many polygons? How many points? Do you have the coordinates, or the encoded line? What database do you have? Is it a spatially-capable one?


On Thu, 18 Jan 2018, at 13:50, ciia...@gmail.com wrote:
Hello, I want save multiples poligon in database but separately someone have do it? or exits a pre-made script js/php??



--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-maps-js-a...@googlegroups.com.
To post to this group, send email to google-map...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages