0

Following the query here:

Exporting GeoJSON with defined properties using Folium Draw plugin

I would like to add labels to the elements, which will be drawn and their features will be defined.

By following this article:

https://www.mkrgeo-blog.com/qgis2-web-fixing-labelling-issues-in-openlayers-map/

where the code comes from OpenLayers and we were able to define not only the label but also the font, etc I was going to prepare something for my particular case.

 {map}.on("draw:created", function(e){    
    var layer = e.layer;
        feature = layer.feature = layer.feature || {};
    let x = 1 
    var title = prompt("Please provide the name", "default");
    var value = prompt("Please provide the value", "undefined");
    var id = x++;
    var label = "";
    feature.type = feature.type || "Feature";
    var props = feature.properties = feature.properties || {};
    props.Id = id;
    props.Title = title;
    props.Value = value;       
    if (feature.get(title) !== null) {
    label = String(feature.get(title));
    }
    drawnItems.addLayer(layer);

In this case, I get an error:

Uncaught TypeError: feature.get is not a function

Next, I tried this thread

get() and getProperties() are not a function, from a VectorLayer (GeoJSON)

and tweaked my code accordingly:

  {map}.on("draw:created", function(e){    
    var layer = e.layer;
        feature = layer.feature = layer.feature || {};
    let x = 1 
    var title = prompt("Please provide the name", "default");
    var value = prompt("Please provide the value", "undefined");
    var id = x++;
    var label = "";
    feature.type = feature.type || "Feature";
    var props = feature.properties = feature.properties || {};
    props.Id = id;
    props.Title = title;
    props.Value = value;
var newsource = e.target;
if (newsource.getState() === 'ready') {
  var myFeatures = newsource.getFeatures(); 
 
  var display = myFeatures.get(title);
}
    if (display !== null) {
    label = String(display);
    }
    drawnItems.addLayer(layer);

but now I am getting an error:

Uncaught TypeError: newsource.getState is not a function

which led me to the next thread:

OpenLayers GeoJSON t.getState is not a function

after which I realized, that importing OpenLayers library is necessary.

Is there any option for displaying the labels next to drawn shapes in Python folium?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.