I used a nice plugin for python folium:
https://www.youtube.com/watch?v=rAicpbCUwco&ab_channel=SudoControl
but the problem is, that my saved geojson file has no properties.
I tried to inject JS to my folium code:
drawjs = """
map.on(L.Draw.Event.CREATED; function (e) {
var type = e.layerType,
layer = e.layer;
var title = prompt("Please provide the name", "default");
var value = prompt("Please provide the value", "undefined");
var id = x++
e.feature.setProperties({
'Id': id,
'Name': title,
'Value': value,
});
});
"""
draw = plugins.Draw(
drawjs,
export=True,
filename='drawing.geojon',
position='topleft'
)
map.add_child(draw)
Unfortunately, I have an error:
<module>
draw = plugins.Draw(
TypeError: __init__() got multiple values for argument 'export'
which means, that I've used the wrong argument for attaching the JS code to my plugin.
How can it be sorted out?
UPDATE:
After solving an issue here:
https://stackoverflow.com/questions/74536711/python-folium-problem-with-editing-draw-plugin
I am on the right track to sorting it out. The piece of code where an error occurs looks like this:
var {{ this.get_name() }} = new L.Control.Draw(
options
).addTo( {{this._parent.get_name()}} );
{{ this._parent.get_name() }}.on(L.Draw.Event.CREATED,
function(e) {
let x = 1 // defining autoincrement ID
var layer = e.layer,
type = e.layerType;
var title = prompt("Please provide the name", "default");
var value = prompt("Please provide the value",
"undefinied");
var id = x++
var coords = JSON.stringify(layer.toGeoJSON());
{%- if this.show_geometry_on_click %}
layer.on('click', function() {
alert(coords);
console.log(coords);
e.feature.setProperties({
'Id': id,
'Name': title,
'Value': value,
});
});
{%- endif %}
drawnItems.addLayer(layer);
});
where the JS console error states:
Uncaught TypeError: Cannot read properties of undefined (reading 'setProperties')
export
. Your line is the same withDraw(export=drawjs, export=True,..)
. The error says 'you pass multipleexport
argument to Draw'. You need to inject the JS script to html page, not passing to Draw.setProperties
method for feature.