0

I have fixed an issue with the drawing circles by the Leaflet draw plugin, where the Turf library has been provided. Everything works fine, apart from the data, which I passed earlier by the prompt function. They come out only in the point created as the circle by standard code. Unfortunately, it is nothing for TurfCircle the same as NewTurfBuffer.

My code (used in Python folium) looks as follows:

 map.on(L.Draw.Event.CREATED, function(e) {
            var layer = e.layer,
                type = e.layerType;
            feature = layer.feature = layer.feature || {}; // Initialize feature
            let x = 1 
            var title = prompt("Please provide the name", "default");
            var value = prompt("Please provide the value", "undefined");
            var id = x++;
            feature.type = feature.type || "Feature"; // Initialize feature type
            if (type === 'circle') {
                    var theCenterPt = layer.getLatLng();
                    var center = [theCenterPt.lng,theCenterPt.lat];
                    console.log(center);
                    console.log(title);
                    var theRadius = layer.getRadius();
                    var turfCircle;
                    var options = {steps: 256, units: 'meters'};
                    var turfCirle = turf.circle(center, theRadius, options);
                    var NewTurfCircle = new L.GeoJSON(turfCircle)
                    drawnItems.addLayer(NewTurfCircle);
                    var thepoint = turf.point(center);
                    var buffered = turf.buffer(thepoint, theRadius, {units: 'meters'});
                    var NewTurfBuffer = new L.GeoJSON(buffered)
                    drawnItems.addLayer(NewTurfBuffer);
                }
            var props = feature.properties = feature.properties || {}; // Initialize feature properties
                props.Id = id;
                props.Title = title;
                props.Value = value;
            var coords = JSON.stringify(layer.toGeoJSON(), NewTurfBuffer);
            {%- if this.show_geometry_on_click %}
            layer.on('click', function() {
                alert(coords);
                console.log(coords);
            });
            {%- endif %}
            drawnItems.addLayer(layer);
         });

I still get empty properties for my FeatureCollection

enter image description here

I think the issue can be similar to this one: Why doesn't JSON.stringify display object properties that are functions? https://gis.stackexchange.com/questions/332908/overlay-with-the-feature-collection-properties

but it looks like I am wrong in placing my properties inside of the FeatureCollection

https://gis.stackexchange.com/questions/25279/is-it-valid-to-have-a-properties-element-in-an-geojson-featurecollection

anyway, I am looking for a solution that will allow me to pass the data to these properties boxes.

UPDATE II:

I tried

       var buffered = turf.buffer(thepoint, theRadius, {units: 'meters'});
                    buffered.push(layer.feature);
                    var NewTurfBuffer = new L.GeoJSON(buffered)
                    drawnItems.addLayer(NewTurfBuffer);

but an error occurs:

buffered.push is not a function

Hint taken from here: https://gis.stackexchange.com/questions/285352/how-to-get-the-exact-circle-that-user-has-drawn-using-leaflet-draw-circle

Geographos
  • 827
  • 2
  • 23
  • 57

0 Answers0