Hi All,

I've been trying to figure this out but I'm getting no where fast. Basically, I'm trying to disable the polyline and polygon toolbar items. I have the following code but I'm not sure where it needs to go???

var drawControl = new L.Control.Draw({
draw: {
polyline: false;
polygon: false
}
});

I'd also like to change the help text for some of the toolbar items, for example for the remove tool "leaflet-select-control-remove". Where can I make these modifications?

Your help is really much appreciated!!!

Comments

jodydeanrogan’s picture

Hi All,

I'm still trying, I've looked everywhere, I've even tried with CSS, still no luck. Would anybody be able to point me in the right direction?

BTW, love the work being done with Leaflet on Drupal.

Thanks in advance.

pcambra’s picture

Issue summary: View changes
StatusFileSize
new901 bytes

I think this is an extremely useful feature, I was struggling with it for a while and here's the "hack" solution that doesn't run the init method for the leaflet widget library but a custom one and mimics the draw control instead.

In widget.js, add this:

          options.map.drawControl = new L.Control.Draw({
            position: 'topright',
            circle: false,
            rectangle: false,
            polyline: false,
            polygon: false
          });

just before:

        L.Util.extend(options.map, {
                layers: [L.tileLayer(options.map.base_url)]
            });

And then add this for getting the remove button back just after the map.widget.enable():

map.selectControl = L.Control.select().addTo(map);

Attaching it as a patch in case someone uses drush make or something but this is not a definitive solution.

pcambra’s picture

Status: Active » Needs work

Now what I think it would be the right fix.

In the Leaflet.widget library (https://github.com/tnightingale/Leaflet.widget) the initialize() method of Leaflet.widget.js should pass the draw options to the initDraw one:

    initialize: function (map, options) {
        L.Util.setOptions(this, options);
        L.Handler.prototype.initialize.call(this, map);

        if (!this._map.drawControl) {
            this._initDraw();
        }
    },

And the _initDraw() method then can just decide on that options if it should display or not display the element and its position:

    _initDraw: function () {
        this._map.drawControl = new L.Control.Draw({
            position: 'topright',
            polyline: { shapeOptions: this.options.drawVectorStyle },
            polygon: { shapeOptions: this.options.drawVectorStyle },
            circle: false,
            rectangle: false
        }).addTo(this._map);

        this._map.selectControl = L.Control.select().addTo(this._map);
    },

Here, in the drupal module, the widget/field options should expose the position and display a checkbox for disabling the polyline, polygon and deletion buttons of the toolbar.

I can provide a proper patch with the things described above if the maintainer is still around.