bozdoz / leaflet-freehandshapes

Refactored Leaflet shape drawing plugin. Forked with <3 from Leaflet.FreeDraw
https://bozdoz.github.io/leaflet-freehandshapes/
Other
18 stars 10 forks source link

Forced polygons #8

Open 00ricardo opened 4 years ago

00ricardo commented 4 years ago

Hi there, there is a way to forced LatLng to a polygon? I want to create a polygon passing the coordinates into it.

something like:

freehandshapes.create([
[0,0],[0,1],[1,0],[1,1],[0,0]
]);
bozdoz commented 4 years ago

I would bet you could do it with something like freehandshapes.addLayer(L.polygon([[0,0], [0,1], [1,0], [0,0]]), false)

See the addLayer method here: https://github.com/bozdoz/leaflet-freehandshapes/blob/master/src/index.js#L94-L103

00ricardo commented 4 years ago

Your solution is not really what i need

var fireLines = new L.FreeHandShapes({
    polygon: {
        className: 'fireLine',
        color: 'red',
        fillColor: 'red',
        opacity: 0.7,
        weight: 3,
        smoothFactor: 1
    },
    polyline: {
        color: '#D55F04',
        smoothFactor: 1
    },
    simplify_tolerance: 0.001,
    merge_polygons: true,
    concave_polygons: false
});

   fireLines.addLayer(L.polygon([
                [0, 0],
                [0, 1],
                [1, 0],
                [1, 1],
                [0, 0]
            ]), false);

Check this:

image

It should be merged and same color as well.

bozdoz commented 4 years ago

Sorry, try addPolygon(latlngs, ...):

https://github.com/bozdoz/leaflet-freehandshapes/blob/master/src/index.js#L221-L232

You can see in that method that it will simplify the lat/lng pairs, and merge; it also uses getPolygon which uses the styles you define in the options.

00ricardo commented 4 years ago

Hey... i found a problem. When i forced the latlngs to create a polygon it overlayed the others and it doesn't merge. How can i get this right?

Thats my result: image

It should look something like this: image