Discovering the modified or removed shape in the leaflet drawControl

Incorporated leaflet and leafletDraw into my Angular6 application, everything is functioning properly. I can trigger the create event and add a polygon to my map, but I'm facing difficulty in determining which shape is deleted or edited:

ngOnInit() {
        const myMap = this.mapElement.nativeElement;
        const map = L.map(myMap).setView([35.6892, 51.3890], 5);
        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: 'Data © <a href="http://osm.org/copyright">OpenStreetMap</a>',
            maxZoom: 18,
        }).addTo(map);
        const editableLayers = new L.FeatureGroup();
        map.addLayer(editableLayers);
        if (this.type === 'marker') {
            this.marker = MarkerOptions;
            if (this.data) {
                L.marker(this.data, MarkerOptions).addTo(editableLayers).bindPopup('I am popup');
            }
        } else if (this.type === 'polygon') {
            this.polygon =  {
                allowIntersection: false,
                drawError: {
                    message: '<strong>Oh snap!<strong> you can\'t draw that!'
                },
                shapeOptions: {}
            };
            if (this.data) {
                L.polygon(this.data).addTo(editableLayers);
            }
        }
        const drawPluginOptions: LeafletControls.Control.DrawConstructorOptions = {
            position: 'topright',
            draw: {
                polyline: false,
                polygon: this.polygon,
                circle: false,
                rectangle: false,
                circlemarker: false,
                marker: this.marker
            },
            edit: {
                featureGroup: editableLayers,
                remove: {},
                edit: {
                    selectedPathOptions: {
                        stroke: false ,
                        color : '#e10010',
                        weight : 500
                    }
                }
            }
        };
        const drawControl = new L.Control.Draw(drawPluginOptions);
        map.addControl(drawControl);
        map.once(L.Draw.Event.CREATED, (e: any) => {
            console.log('lia e' , e);
            this.layer = e.layer;
            // if (type === 'marker') {
            //     layer.bindPopup('A popup!');
            // }
            editableLayers.addLayer(this.layer);
        });
        map.on('draw:edited', (e: any) => {
            console.log('lia edit' , e , this.layer); //unable to trigger which shape is.
        });
        map.on('draw:deleted', (e: any) => {
            console.log('lia delete' , e ); //unable to trigger which shape is.
            console.log(this.layer);
        });
    }

Answer №1

When the draw:edited and draw:deleted events occur, they provide you with a LayerGroup that contains all the layers that were either edited or deleted.

map.on('draw:edited', (e: any) => {
        var editedlayers = e.layers;
        editedlayers.eachLayer(function(layer) { // Now you can take action on the edited layer
        });
    });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating XML templates in Angular 7: A comprehensive guide

How do I pass XML values in Angular 7 when the API requires this specific format of XML code? -modifydata "<datasets><dataset select=\""always\""> <replace match=\""Letter/@FName\"" value=\""Nazeeeeeeeeeeeeer\" ...

Preventing screenshots on an Asp.net MVC web application: Best practices for enhanced security

Our client has requested that we implement measures to prevent screenshots of our web application. Additionally, we need to block the ability to take screenshots using third party tools such as the snipping tool. I would greatly appreciate any assistance ...

What is the significance of the jQuery iframe load event?

Is there a specific way to handle this situation? I have an iframe that is getting inserted through $.ajax() and I need to perform some actions once the content of the iframe is fully loaded: .... success: function(html){ // <-- html contains the IF ...

Establishing the ISO date time to the beginning of the day

When working with a Date retrieved from a Mongo query in ISO format, the goal is to compare it with today's date. To accomplish this, a new Date is created and its time is set to zero: var today = new Date(); today.setHours(0,0,0,0); //Sat Jan 20 201 ...

Why is Reactjs axios returning a promise instead of the expected value?

I have been attempting to retrieve data from an API using axios, but all I am getting back is a Promise. The Node.js code: router.get('/isAdmin/:userId/:groupeId', async (req, res) => { let userId = req.params.userId let groupeId = ...

Converting an HTTP request and incorporating a success function in Typescript and Angular2

I am working on a http request: private getValues() { this._watchlistElements.map(v => this.http.get('http://localhost/getValue/' + v.xid) .subscribe(res => { this._values.push(res.json()); })); }; When the request ...

Sorting JSON content to obtain particular outcomes

I am utilizing the Quotes on Design API https://quotesondesign.com/api-v4-0/ to display random quotes by various designers on my website. However, I am looking to showcase quotes by specific designers in a random manner. Unfortunately, the code snippet ...

Error in unit testing: Trying to access property 'pipe' of an undefined variable results in a TypeError

Recently, I've been faced with the challenge of writing a unit test for one of the functions in my component. The specific function in question is called 'setup', which internally calls another function named 'additionalSetup'. In ...

personalized XMLHttpRequest method open

var open = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, uri, async, user, pass) { this.addEventListener("readystatechange", function(event) { if(this.readyState == 4){ var self = this; var respons ...

Tailwind CSS Sturdy Top Navigation Bar

I have been attempting to implement a Fixed Navigation Bar using Tailwind CSS and have the main page scroll with a sticky effect, but I'm encountering difficulties in getting it to function properly... Here is the current state of my progress: https ...

`The malfunctioning button on an HTML5 application developed with Intel XDK`

Currently, I am in the process of developing an HTML5 App through Intel XDK. On my initial page (page_0), users have the ability to choose a conversion style. Opting for the first option directs them to page_1 where they encounter input boxes and buttons. ...

What is the best way to contact all products that have been made by a specific User?

Using MongoDB with Mongoose, I have successfully implemented basic CRUD operations. However, I am facing difficulty in fetching all the products created by a specific user. I'm unsure if my approach is correct, but I attempted to use this syntax: user ...

Introducing a versatile jQuery library capable of resizing, rotating, and dragging lines effortlessly

Are there any existing jQuery libraries out there that could help me draw lines on the screen? Ideally, I'd like the ability to resize, rotate, and drag the lines using just my mouse. Check out the images below for reference: https://i.sstatic.net/Th ...

What is the method for obtaining the current participant's ID from the Angular frontend of a Hyperledger Composer application?

Need help with hyperledger-composer: I know how to retrieve the id of the current participant within a transaction processor function using this code: let currentParticipant = getCurrentParticipant(); let participantId = currentParticipant.getFullyQuali ...

Word with the Most Points

I have created a code to determine the highest scoring word as a string, however when I calculate all words and attempt to display the results, I am encountering an issue where all results are showing as: NaN function high(x) { var words = x.split(&ap ...

The Jquery Mobile 1.4.5 virtual keyboard on the device is causing the form inputs at the bottom of the page to become hidden

I am currently working on a web app using JQuery Mobile 1.4.5. Encounter an issue that seems to be related to either the browser or JQM bug specifically when using Google Chrome in fullscreen mode on Android (v.4.4.2). Upon clicking on the Click Here!! ...

Utilize Firebase Realtime Database to generate new data entries using triggers

Hey there, to all the amazing folks at stackoverflow who have been supporting me over the years, I have a new question for you! I've been delving into Android programming for quite some time now and I enjoy exploring different ways to optimize apps. ...

Add photos to a Google Cloud bucket through an Angular 7 application

Can anyone help me figure out how to upload an image to a Google Cloud bucket within an Angular 7 app that doesn't utilize Node.js as the backend, but instead uses Firebase as a backend service? I've searched for guides and documentation but have ...

Ensuring the correctness of a file path using a regular expression in AngularJS

I am trying to validate my input to see if it is correct. It should be in the format Folder/game.dll. Below is the code I am using: <input type="text" name="addRelativePath" ng-model="addGameModel.RelativePath" class="form-control" required ng-pattern= ...

Leveraging a third-party library in AngularJS to interact with a factory or service

My current challenge involves developing an application that is predominantly angular-based, but also incorporates some non-angular code. I have structured my code into modules, including various factories. One of these factories is specifically dedicated ...