2

I am trying to create a participatory mapping site where users can draw pts, lines and polys using Leaflet draw.

Is it possible to create a pop window where users can add a title or description of the feature they draw -or- after they draw, click on the feature and add a label or description?

6

Absolutely. I added this functionality to an application by creating a popup on the shape when the draw:created function fired. Here is a quick run through of how it works.

map.on('draw:created', function (e) {
     var idIW = L.popup();
     var content = '<span><b>Shape Name</b></span><br/><input id="shapeName" type="text"/><br/><br/><span><b>Shape Description<b/></span><br/><textarea id="shapeDesc" cols="25" rows="5"></textarea><br/><br/><input type="button" id="okBtn" value="Save" onclick="saveIdIW()"/>';
     idIW.setContent(content);
     idIW.setLatLng(latlng); //calculated based on the e.layertype
     idIW.openOn(map);
}

function saveIdIW() {
     var sName = $('#shapeName').val();
     var sDesc = $('#shapeDesc').val();

     var drawings = drawnItems.getLayers();  //drawnItems is a container for the drawn objects
     drawings[drawings.length - 1].title = sName;
     drawings[drawings.length - 1].content = sDesc;

     if (idIW) {
        map.closePopup();
     }
}

Here is an image of how it appears: enter image description here

| improve this answer | |
  • @ew_gis: i am in situation that when user click on marker or click on any shape then i need to show a popup window by which user can enter some text. when user click on save button after entering text and when later user click on marker then text need to be displayed in popup. you gave bit code but can you please guide to do it with full code. thanks – Thomas Aug 10 '15 at 13:52
  • 1
    @Thomas, it would be best if you posted a new question. One showing your code progress so far, and where you are having difficulties. That way the community can review and respond. – evv_gis Aug 10 '15 at 14:14
  • yes i will post my issue because i am new in leaflet and that is the reason i some time stuck. thanks for your reply – Thomas Aug 10 '15 at 14:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.