I was looking for a solution but all are how to draw polylines from the json file etc. Main question is how to get the functionality to create a new polyline and store old in array each time when click on button “New Polyline”? Second how to leave polylines and draw new on map after click “New Polyline” button and clean and restore only when click right button? May better way is to store Polylines outside the class, or make a new separately class for this? May you have to approach this differently?
Bad demo but highlight what I mean I hope: jsfiddle
Array was moved to global scope but can’t setMap on last polyline works only via clearOverlays function. Now complications arise on other buttons. I create additional global object newPoly but don’t know whether is good idea may better get object from myPolyline? In other side restore case can’t set on map stored in array polylines.
To save the polylines you’ve made, create another global variable to store the polylines and push them in, and at the same time, setMap(null) on the last polyline in the array. You can’t store the polylines you’ve made in the same object, since you’re making a new one each time.
So move:
out of the class, and into the global scope, or into another class, its fine to leave the marker array in there, since that’s local to that polyline instance.
this should also help – https://developers.google.com/maps/documentation/javascript/overlays#OverlaysOverview