drykovanov / mapbox-gl-draw-rotate-scale-rect-mode

MIT License
25 stars 17 forks source link

TxRectMode mapbox-gl-draw custom mode

This is the custom mapbox-gl-draw mode which allows to rotate and scale rectangle polygons.

Live demo is here

Demo gif

Features:

Installation:

npm install git+https://github.com/drykovanov/mapbox-gl-draw-rotate-scale-rect-mode#0.1.10

Usage examples:

First, init MapboxDraw with TxRectMode and styling provided.

There is an example of styling in demo.js and icon set for scaling and rotation.

    import { TxRectMode, TxCenter } from 'mapbox-gl-draw-rotate-scale-rect-mode';
    ...
    const draw = new MapboxDraw({
        displayControlsDefault: false,
        controls: {
        },

        modes: Object.assign({
            tx_poly: TxRectMode,
        }, MapboxDraw.modes),

        styles: drawStyle,
    });

Second, create your rectangle polygon (with turf) and provide it's featureId to changeMode():


    const coordinates = [cUL,cUR,cLR,cLL,cUL];
    const poly = turf.polygon([coordinates]);
    poly.id = <unique id>;

    draw.add(poly);

    draw.changeMode('tx_poly', {
        featureId: poly.id, // required
    });

changeMode('tx_poly', ...) accepts the following options:

Demo gif