Drawing rectangle on leaflet by giving coordinate

135 views
Skip to first unread message

Tridip Bhattacharjee

unread,
Aug 9, 2015, 3:07:33 PM8/9/15
to Leaflet

i know the syntax to draw rectangle on leaflet by giving coordinate. here is the sample code which i can use to draw rectangle on leaflet by giving coordinate.

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);

my coordinate look like LatLng(-37.77353, 175.26882),LatLng(-37.77285, 175.26882),LatLng(-37.77285, 175.27097),LatLng(-37.77353, 175.27097)

but if anyone see the above coordinate store in bounds variable then there two set of lat lang specified but mine is 4 set.

just tell me how could i push this kind of latlang LatLng(-37.77353, 175.26882),LatLng(-37.77285, 175.26882),LatLng(-37.77285, 175.27097),LatLng(-37.77353, 175.27097) to draw circle on my map ?

Reply all
Reply to author
Forward
0 new messages