Closed Schumi09 closed 7 years ago
You shouldn't need to make your own javascript GeometryField
if you use the PolygonField
from django.leaflet
in your model.
What is the full stack trace ?
Thanks for your fast reply. Seems like I missed the point of it completly.
What's the best way to disable certain drawing tools? Right now I'm using
map.on('map:loadfield', function (e) {
drawControl = e.field._drawControl;
drawControl._toolbars.draw.options.polyline = false;
drawControl._toolbars.draw.options.marker = false;
map.addControl(drawControl);
});
But obviously IE ignores it. It looks a bit hacky anyway. Are there some settings?
Unfortunately I can't provide you a full stack trace. My project ist not set up that far right now :(
Actually, you may need to change the field on your form directly. Something like:
from leaflet.forms.fields import PolygonField
class SiteLocationForm(forms.ModelForm):
geom = PolygonField()
class Meta:
model = Model
fields = ('address', 'geom')
or
class SiteLocationForm(forms.ModelForm):
class Meta:
model = Model
fields = ('address', 'geom')
widgets = {'geom': LeafletWidget(geom_type="POLYGON")}
If you want full control on the drawing tools, you will need to have your own JS GeometryField. There is a _controlDrawOptions
method:
YourGeometryField = L.GeometryField.extend({
_controlDrawOptions: function () {
return {
edit: {
featureGroup: this.drawnItems
},
draw: {
polyline: this.options.is_linestring,
polygon: this.options.is_polygon,
circle: false, // Turns off this drawing tool
rectangle: this.options.is_polygon,
marker: this.options.is_point,
}
};
}
});
It works pretty well, even in IE 👍
Unfortunately one thing that does not work in IE is adding another controls, e.g. Layer or Geocoding
Simple example would be
var osm = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
});
var baseMaps = {"OpenStreetMap": osm,};
osm.addTo(map);
L.control.layers(baseMaps).addTo(map);
Works in other browsers, not in IE11. Any idea? ;)
I never really tried that with IE, I can't really help you on that, sorry :disappointed: .
As my project meanwhile relies on jQuery I could use
$(window).on('map:init', function (e) { });
instead of
window.addEventListener("map:init", function (e) {});
👍
Hi there,
I wanted to make use of a customized form widget so I got control about the geometry etc.
While modern browsers like Chrome or FF don't seem to have any issues, I get
in
I couldn't find anything related here, is there something known?
What I've done is
class ExtLeafletWidget(LeafletWidget): geometry_field_class = 'geom'
As it works in other browsers I dont think I did anything wrong.
I would appreciate any kind of help, Thanks for this amazing project 👍