How to track the polygon change event? - leaflet

I need to get the new coordinates of the polygon if the finish button was pressed. I applied pm:update, but this event is not triggered when rotating or moving the polygon. I also tried to use pm:action click, but this event does not give me the opportunity to get the coordinates of the polygon that I was changing.

Listen on the pm:edit event, it is fired directly after a change is happend.
polygon.on('pm:edit', (e)=>{
console.log(e);
});

Related

Leaflet Draw how to trigger button events from outside the map

I've got a leaflet draw instance where I need buttons outside the map to start / cancel draw actions. I have successfully triggered draw start with
map.Draw.Polyline(map, myDrawControlInstance.options.polyline).enable();
but the only action I could find anywhere in the API that is mentioned to cancel a draw action: map.Draw.Polyline(map, myDrawControlInstance.options.polyline).disable(); does not trigger the cancel action.
How can I mimic all buttons that appear in the Leaflet Draw interface when drawing, editing, deleting, etc.
Any help is greatly appreciated
Found a post somewhere from almost 10 years ago with the answer.
You have to keep the drawHandler that's returned by the new L.Draw. method and call the cancel() on it.
start a draw from outside:
const drawHandler = new L.Draw.Polyline(map, drawControl.options.polyline).enable();
cancel the draw from outside the map:
drawHandler.disable();

Is there a way to run function AFTER camera movements end? (MapBox)

How can I run function after camera's movement ends e.g send API request.
I am using MapBox and map controllers
Thanks!
I think what you're looking for is moveend event.
// Set an event listener that fires
// just after the map completes a transition.
map.on('moveend', function() {
console.log('A moveend event occurred.');
});

How to detect when user does not click on a layer? Leaflet

I am using leafletjs in a project. On the map I have several polygons and markers. There is a click event on all of them to display some information when one of them is clicked. I would like to take the information away if the user clicks on a 'blank' part of the map (not on any polygons or markers). I know the map has the 'click' event but so far I am struggling to find a way to detect if the user clicked on a layer. Any advice?
you can use preclick event to clear all the data
https://leafletjs.com/reference-1.2.0.html#map-preclick

Is it possible to make a Bing Maps TileLayer clickable?

There are Data Layer Events with which you can add e.g. click events to the Layer Class. How can I add event handlers to the TileLayer Class?
In the WMS Tile Layer Example I wish I could add the following lines of code:
Microsoft.Maps.Events.addHandler(NOAAWeatherRadar, 'click', function() {
// add infobox
});
Is this realizable or do you know of a workaround?
Tile layers do not have mouse events in any map control. Tile layers cover the complete surface of the map. If you want a mouse event simply add an event to the map itself. If you want to be able to detect a mouse event on a shape drawn in the tile layer, then you will need to do some server side processing to test for intersection against the raw data.

disabling 'grab' panning for bing maps control

How do I disable just the grab aspect of panning for bing maps AJAX control 7.0?
I have tried this -
var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), { credentials: "bing maps credentials", mapTypeId: Microsoft.Maps.MapTypeId.road, disablePanning: true});
But setting the disablePanning property in the map options not only disables grab panning but also zoom panning. Zoom becomes not completely disabled but instead will only zoom in and out on the center of the map. No doubt you will have come accross zoom panning where you can use the mouse scroll wheel to zoom in on the map under the cursor and therefore can pan around by zooming in and out and moving the cursor. I would like to have zoom panning enabled but grab panning (where the user depresses the mouse and drags it around) to be disabled.
I am aiming for functionality very similar to when using the my places editor on the main bing maps site. When using the polyline tool to draw on the map grab panning is disabled and zoom panning is enabled just as I would like. I am actually intending on creating a custom drawing tool similar to the polyline tool in the my places editor.
I have been studying the api but have not discovered how to do it yet. I have also tried to discover how it is done on the main bing maps site but as the javascript code is all minified I am finding it very difficult. I have managed to gleen that the polyline tool hijacks the mouse, but that is about all.
Surely there must be a simple way of doing this. How is it done?
I don't think there is a map option you can set to achieve the behavior you want(enable zoom panning/disable grab panning). However, there is an easy way to hack it. The panning is initiated by the user clicking down on the map and moving the mouse. So if you can supply your own mousedown event handler for the map, and in its implementation prevent the default behavior of the mousedown, you should be good to go. Turns out the handled property on MouseEventArgs does just this:
Microsoft.Maps.Events.addHandler(yourMapObj, 'mousedown', function (mouseEvent) {
mouseEvent.handled = true; //A boolean indicating whether the event is handled. If this property is set to true, the default map control behavior for the event is cancelled.
});
With this, mousedown events on the map are processed by you and ignored by the map. So when the user tries to pan the map using the mouse, nothing happens. They can still click and zoom around as usual. Keep in mind if you have other elements on the map such as pushpins and shapes, this will prevent the mousedown event from reaching them. So any mousedown event handlers you registered on them will not get called. You can handle this either by unregistering the above handler when you want the other mousedown events to be called(preferable), or interogate the target property on your MouseEventArgs to see what fired the mousedown(messy).