Google Map V3 - undo the last point when drawing using the drawing manager

I have an application that uses the Google Drawing manager to draw polylines and polygons on a map. Although this is a great library, I got a question from the user if it would be possible to undo the last drawn point when you draw the polyline. I searched, but I found out that this is possible only AFTER the polyline. Can anyone crack this?

Another great option is to expand an existing polyline.

+4
source share
1 answer

Use this function to undu and shorten

function undoOverlays(){
        $( "#my_shape" ).hide('slow'); 
        bounds = mapOverlays[(mapOverlays.length)-1].getPath(); console.log(bounds);
        if(bounds.length>1){
        undo_redo.push(bounds.pop());
        }
        else { $('#message_popup').html('Everything is Cleared.');$('#message_popup').show('slow');$('#message_popup').delay(2000).fadeOut('slow'); }
    }

    function redoOverlays(){
        $( "#my_shape" ).hide('slow');
        bounds = mapOverlays[(mapOverlays.length)-1].getPath();
        if(undo_redo.length>0){
        for(var i=0;i<undo_redo.length;i++);
        {
        bounds.push(undo_redo.pop());
        }
        }
        else { $('#message_popup').html('Everything is Recovered.');$('#message_popup').show('slow');$('#message_popup').delay(2000).fadeOut('slow'); }
    }
-1
source

Source: https://habr.com/ru/post/1525856/


All Articles