watergis / maplibre-gl-terradraw

This plugin is to add controls to your maplibre for sketching powered by terradraw library.
https://terradraw.water-gis.com/
MIT License
16 stars 1 forks source link

feat: bring more customizations of plugin such as changing mode order and drawing mode options #18

Closed JinIgarashi closed 1 month ago

JinIgarashi commented 1 month ago

Now, an array of modes can be passed to the constructor of the plugin, and the mode controls will be added exactly the same order. You can also remove unnecessary modes from the array when you initialize the plugin.

For instance, you can only add point and select control on the plugin like the below code.

const drawControl = new MaplibreTerradrawControl({
    modes: ['point', 'select']
});
map.addControl(drawControl, 'top-left');

For example, if you only want to use polygon control, and you want to disable draggable option and node insertion/deletion on an edge of a polygon, the setting can be as follows.

const drawControl = new MaplibreTerradrawControl(
    {
        modes: ['polygon', 'select']
    },
    {
        select: new TerraDrawSelectMode({
            flags: {
                polygon: {
                    feature: {
                        draggable: false, // users cannot drag to move polygon
                        rotateable: true,
                        scaleable: true,
                        coordinates: {
                            midpoints: false, // users cannot add a node on the middle of edge.
                            draggable: true,
                            deletable: false // users cannot delete a node.
                        }
                    }
                }
            }
        })
    }
);
map.addControl(drawControl, 'top-left');
changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: b5bda75f2970c223967e193d10180816deb72b68

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------------------------- | ----- | | @watergis/maplibre-gl-terradraw | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

netlify[bot] commented 1 month ago

Deploy Preview for maplibre-gl-terradraw ready!

Name Link
Latest commit b5bda75f2970c223967e193d10180816deb72b68
Latest deploy log https://app.netlify.com/sites/maplibre-gl-terradraw/deploys/66dcc8450af79e0008f7c42c
Deploy Preview https://deploy-preview-18--maplibre-gl-terradraw.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.