I don't have too much experience with JavaScript and Google Maps Api. What I want to achieve: I have a map, where user can either put marker or draw polygon. I'm using gmap3 plugin and I've managed to do everything I wanted with markers (like adding, editing, dragging, removing etc), but I have problem with polygons. Here's the basic code:
$('#map-mappoints').gmap3(
{
action:'init',
options:{
zoom: 7
}
,
events: {
click: function(event, data) {
if($(".map #poly").hasClass('active')){
placePoly(data.latLng);
} else {
placeMarker(data.latLng);
}
}
}
},
{
action:"autofit"
}
);
function placePoly(location) {
$('#map-mappoints').gmap3({
action: 'addPolygon',
options:{
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35
},
callback: function(polygon){
var path = polygon.getPath();
path.push(location);
console.log(path);
}
}
)
}
I can see in console that it creates poly, but it adds only one path element, which is logic as it's triggered after each click on map, but I have no idea how I should make it to continue adding new elements to polygon, and then let user stop (probably by some button in toolbar), and create new after clicking "new poly".
Thank you for any hints.
ps. English is not my native language, so I'm sorry for any mistakes, I've tried to avoid them ;)