I am using google maps API for searching houses in different places in a city. All the houses will be having markers and user will draw multiple polygons around the markers based on his interest.
I need to check what all the locations user selected and show only those markers in maps. With my code, I am able to get it done, but struck with some issue
Once user draw first polygon, I am storing that in a variable and then merging it with the coordinates of second polygon and repeating the same for all the polygons. So, all the polygons coordinates are in a single object. Whenever I draw multiple polygons all of them are getting connected with a polyline because I am saving them in one object and sending that to mapOptions.
How to get rid of this issue?? Following is the code, I am using when user draws a polygon. I want all the polygons to be independent to each-other
function drawFreeHand(){
//the polygon
poly = new google.maps.Polyline({map:map,clickable:false});
//move-listener
var move = google.maps.event.addListener(map,'mousemove',function(e){
poly.getPath().push(e.latLng);
});
//mouseup-listener
google.maps.event.addListenerOnce(map,'mouseup',function(e){
google.maps.event.removeListener(move);
var path = poly.getPath();
poly.setMap(null);
var theArrayofLatLng = path.j;
var ArrayforPolygontoUse = GDouglasPeucker(theArrayofLatLng,50);
multi_poly = myFunction1(ArrayforPolygontoUse)
console.log(multi_poly);
var polyOptions = {
map: map,
fillColor: '#0099FF',
fillOpacity: 0.7,
strokeColor: '#AA2143',
strokeWeight: 2,
clickable: false,
zIndex: 1,
path:multi_poly,
editable: false
}
poly = new google.maps.Polygon(polyOptions);
});
}
function myFunction1(myVar) {
if(ArrayforPolygontoUse != undefined) {
str1 = ArrayforPolygontoUse;
}
else {
var str1 = [];
}
return ArrayforPolygontoUse = $.merge(str1,myVar);
}