makinacorpus / django-leaflet

Use Leaflet in your Django projects
GNU Lesser General Public License v3.0
716 stars 282 forks source link

Simplify customizing LeafletWidget map #80

Open rgreenemun opened 10 years ago

rgreenemun commented 10 years ago

If you need to customize the map used by the widget, currently you need to override the js field behaviour by extending GeometryField, then in django you subclass the LeafletWidget to specify the custom geometry_field_class, as follows:

::

YourGeometryField = L.GeometryField.extend({
    addTo: function (map) {
        L.GeometryField.prototype.addTo.call(this, map);
        // Customize map for field
        console.log(this);
    },
    // See GeometryField source (static/leaflet/leaflet.forms.js) to override more stuff...
});

::

class YourMapWidget(LeafletWidget):
    geometry_field_class = 'YourGeometryField'

class YourForm(forms.ModelForm):
    class Meta:
        model = YourModel
        fields = ('name', 'geom')
        widgets = {'geom': YourMapWidget()}

A shortcut would be useful to pass the geometry_field_class to the form instead of having to subclass LeafletWidget.

leplatrem commented 9 years ago

Thanks for your feedback !

This is a good idea, I'm sorry for the delay of this response :(

Please open a pull-request with the changes you propose, and we'll review and merge it !


We would welcome any help for maintaining this library. If you use it and find it useful, please Watch it on Github, help us review contributions or comment issues :) Thousand thanks in advance.