SpyCop / cleanup-logger

Node.js Web application for visual logging on OSM of stray litter cleanup
0 stars 0 forks source link

Add area calculations #9

Open SpyCop opened 2 years ago

SpyCop commented 2 years ago

For area calculations there are several ways of displaying it:

It might be useful to add the calculated value to the database, but maybe it is also possible to just calculate the area every time based on the Points in the data base?

SpyCop commented 2 years ago

Not using the Draw plugin, we can use turf.js with their area() function. Using the GeoMan toGeoJSON() on the layer from the pm:create event:

map.on('pm:create', (e) => {
    console.log(e);
    // Add code here for handling creation of
    var type = e.shape,
        layer = e.layer;
    if (type === 'Polygon') {
        geoJSONFt = layer.toGeoJSON();
        geoJSONFt.properties.area = turf.area(geoJSONFt);
        console.log(geoJSONFt);
    };
});