• #31186
    Forcetalks

    How to export all points within Leaflet polygon in Salesforce?

    How to export all points within Leaflet polygon in Salesforce?

     

    #31224
     Prachi #6
    Forcetalks

    Hello Madhulika,

    Although ‘export’ is very ambiguous, here’s a way to console log the drawn polygon as ‘geojson’ string:-

    map.on(‘draw:created’, function (e) {
    var type = e.layerType,
    layer = e.layer;

    if (type === ‘polygon’) {
    // structure the geojson object
    var geojson = {};
    geojson[‘type’] = ‘Feature’;
    geojson[‘geometry’] = {};
    geojson[‘geometry’][‘type’] = “Polygon”;

    // export the coordinates from the layer
    coordinates = [];
    latlngs = layer.getLatLngs();
    for (var i = 0; i < latlngs.length; i++) {
    coordinates.push([latlngs[i].lng, latlngs[i].lat])
    }

    // push the coordinates to the json geometry
    geojson[‘geometry’][‘coordinates’] = [coordinates];

    // Finally, show the poly as a geojson object in the console
    console.log(JSON.stringify(geojson));

    }

    drawnItems.addLayer(layer);
    });

    I hope this will help.

    thanks

    #34854
    Salesforce | shariq shariq #1
    Forcetalks

    Hi,

    I have found this code online, try this and let me know –

    map.on(‘draw:created’, function (e) {
    var type = e.layerType,
    layer = e.layer;

    if (type === ‘polygon’) {
    // here you got the polygon points
    var points = layer._latlngs;

    // here you can get it in geojson format
    var geojson = layer.toGeoJSON();
    }
    // here you add it to a layer to display it in the map
    drawnItems.addLayer(layer);
    });

    Hope this helps.

    #41474
    Forcetalks

    Hey,

    It is simpler than that.

    map.on('draw:created', function (e) {
    var type = e.layerType,
    layer = e.layer;

    if (type === 'polygon') {
    // here you got the polygon points
    var points = layer._latlngs;

    // here you can get it in geojson format
    var geojson = layer.toGeoJSON();
    }
    // here you add it to a layer to display it in the map
    drawnItems.addLayer(layer);
    });

    Thanks.

    #51989
     Prachi #6
    Forcetalks

    Hi,

    I have found this code online, try this and let me know –

    map.on(‘draw:created’, function (e) {
    var type = e.layerType,
    layer = e.layer;

    if (type === ‘polygon’) {
    // here you got the polygon points
    var points = layer._latlngs;

    // here you can get it in geojson format
    var geojson = layer.toGeoJSON();
    }
    // here you add it to a layer to display it in the map
    drawnItems.addLayer(layer);
    });

    Hope this helps.

Viewing 5 posts - 1 through 5 (of 5 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?