Center popup box in a leaflet.draw box

772 views
Skip to first unread message

James Wong

unread,
Jun 23, 2013, 6:32:04 AM6/23/13
to leafl...@googlegroups.com
Does anyone knows who to make popup boxes created with a rectangle box appear at the center of the box? I am using this code to automatically append a popup msg whenever a box is created but it isn't appearing at the center.


main_map.on('draw:created', function (e) {
var type = e.layerType,
layer = e.layer;
if (type === 'marker') {
// Do marker specific actions
}

// Do whatever else you need to. (save to db, add to map etc)
main_map.addLayer(layer);
layer.bindPopup("test").openPopup();
});

Bryan McBride

unread,
Jun 25, 2013, 1:05:19 AM6/25/13
to leafl...@googlegroups.com
Try this:

layer._popup.setLatLng(layer.getBounds().getCenter());
Reply all
Reply to author
Forward
0 new messages