Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  51] [ 3]  / answers: 1 / hits: 30710  / 12 Years ago, thu, march 7, 2013, 12:00:00

Is it possible to get the coordinates of the rectangle on mouseClick, so I have all the corners of the rectangle?


More From » leaflet

 Answers
11

See event object (http://leafletjs.com/reference.html#event-objects):



var map = L.map('map').setView([53.902257, 27.561640], 13);

L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);

var bounds = [[53.912257, 27.581640], [53.902257, 27.561640]];

var rect = L.rectangle(bounds, {color: 'blue', weight: 1}).on('click', function (e) {
// There event is event object
// there e.type === 'click'
// there e.lanlng === L.LatLng on map
// there e.target.getLatLngs() - your rectangle coordinates
// but e.target !== rect
console.info(e);
}).addTo(map);


Use e.target.getLatLngs().


[#79773] Wednesday, March 6, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gonzaloulyssess

Total Points: 225
Total Questions: 114
Total Answers: 112

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;