geoman-io / leaflet-geoman

🍂🗺️ The most powerful leaflet plugin for drawing and editing geometry layers
https://geoman.io
MIT License
2.21k stars 433 forks source link

Can't add text to labels when SetOptIn is true #1465

Closed kawallala closed 7 months ago

kawallala commented 7 months ago

Hi, I am using the geoman library in a situation where other layers have been drawn before that I don't want to edit, so I've been using the SetoptIn option.

When I tried to add the ability of using labels in the map via the enableDraw('Text') I noticed that the textarea was not editable, and the SetOptIn option appears to be the culprit, how can I solve this while using the option still?

I make a jsfiddle with the issue, if the option is false, then the text layer works as intended https://jsfiddle.net/y2r1hpLc/1/

kawallala commented 7 months ago

did not realized this is a copy of #1186, however I still want to ask, this does not appear to be fixed, is the work around in the issue linked the only option?

Falke-Design commented 7 months ago

You need to do following:

map.on("pm:create", (e) => {
  e.layer.options.pmIgnore = false;
  L.PM.reInitLayer(e.layer);
  if(e.shape === "Text"){
    e.layer.pm.enable();
    e.layer.pm.focus();
  }
});

Having OptIn enabled means to do some things manually, like explicitly saying that you want to enable editing of this text layer.