You need to make a map with the ability to add polygons by clicking on it. Also, when clicking on a polygon, it should be highlighted, and when you click on the delete button, it should be deleted. It turned out something like this

addMarker: function (latLng, map) { var o = this.options; this.latLng = latLng; var newMarker = new google.maps.Marker({ position: this.latLng, map: map, icon: { path: google.maps.SymbolPath.CIRCLE, scale: 3, strokeColor: '#FF0000', strokeOpacity: 0.2 } }); o.markers.push(newMarker); var vertexLat = +latLng.lat(); var vertexLng = +latLng.lng(); var vertex = {lat: vertexLat, lng: vertexLng}; o.figureCoords.push(vertex); }, constructPolygon: function () { var o = this.options; this.newFigure = new google.maps.Polygon({ paths: o.figureCoords, strokeColor: '#FF0000', strokeOpacity: 0.5, strokeWeight: 2, fillColor: '#FF0000', fillOpacity: 0.1, editable: true, draggable: true }); } 

We click on the map, we create vertices, when we click on the "Add" button, a polygon is drawn using the coordinates saved in the array. There may be a lot of them on the map. Delete everything turns out, but you need to make it so that by clicking on a specific polygon, it is highlighted and it is possible to remove it by clicking on the "delete" button

    1 answer 1

      function selectFigure(event) { if (o.figureSelected === this) { o.figureSelected = {}; this.setOptions({fillOpacity: 0.1, strokeOpacity: 0.3}); } else { !(Object.keys(o.figureSelected).length === 0) && o.figureSelected.setOptions({fillOpacity: 0.1, strokeOpacity: 0.3}); o.figureSelected = this; this.setOptions({fillOpacity: 0.3, strokeOpacity: 0.5}); }; }; 

    Remove highlighted polygon

      deleteFigureSelected:function (map) { var o = this.options; clearFigureSelected(); o.figureSelected = {}; function setMapOnAllFigureSelected(map) { !(Object.keys(o.figureSelected).length === 0) && o.figureSelected.setMap(map); }; function clearFigureSelected() { setMapOnAllFigureSelected(null); }; }, 

    You can see the full code here https://github.com/EbenezerScrew/map-plugin