django-leaflet
django-leaflet copied to clipboard
plugins for admin?
I'm using django-leaflet for admin only right now and I'd like to have a plugin like Leaflet.Coordinates available for adding points. My programming skills are limited, but I'd like to try to add plugin functionality to the admin site. Needless to say, I have no idea where to start. Could you point me to an example? It would be great if I could contribute something.
Thanks for considering to contribute :)
Sorry for the delay. It looks like the guyz at Makina Corpus are busy those days :)
Regarding the inclusion of custom script in forms, you can try this (untested):
LEAFLET_CONFIG = {
'PLUGINS': {
'forms': {
'js': ['vendors/Leaflet.Coordinates.js', 'yourapp/script.js']
'auto-include': True
}
}
}
In script.js:
$(window).on('map:init', function (e) {
var detail = e.originalEvent ?
e.originalEvent.detail : e.detail;
...
// Play with Leaflet.Coordinates
L.marker([50.5, 30.5]).addTo(detail.map);
...
// Optional specific behaviour for particular field
map.on('map:loadfield', function (ev) {
...
// Customize map for field
console.log(ev.field, ev.fieldid);
...
});
});
Good luck!
Any news to share ?
Hi !
This works indeed.
But is there a way to load only specific plugins for specific fields ?
Here I'm trying to display the other features around the edited feature in the admin widget (I intend to allow to snap to those other features). I managed to create a geojson overlayer layer by creating a custom plugin.
LEAFLET_CONFIG = {
'PLUGINS': {
'myoverlay': {
'js': ['/static/leaflet-layers/myoverlay.js'],
'auto-include': False,
},
}
}
But I can't find how to add that plugin to a specific widget. It seems the only way is to add the plugin to
LEAFLET_CONFIG = {
'PLUGINS': {
'forms': {
'js': ['/static/leaflet-layers/myoverlay.js'],
'auto-include': True,
},
}
}
This results in adding the layer in all my widgets. But that overlay only makes sense in a specific field !
I was expecting something like :
class MyModel( models.Model ):
geom = leafletmodels.Geometry( plugins='myoverlay' )
or the ability to define plugins in LeafletWidget (so that I could override my widgets).
Is this possible ?
Thanks !
Olivier
Is this possible ?
It is not impossible, but not available out of the box :(
When you say type of field, you mean geometry type?
I am trying to load plugin as it's present in the doc but no result. I want to load the same plugin Leaflet.Coordinates in my admin LeafletgeoAdmin widget. Apparently JS or CS files are not loaded whereas I put leaflet_tags in the leaflet/admin/widget
Sorry, I should miss something but I don't know what ? Please could you explain step by step ?
thanks a lot for your share Best
well done, I fix my trouble by using 'forms' otherwise the 'name of the coordinate plugins' I had insert the js code in the admin widget by using window.event
sorry for the noise bye !
this issue is currently giving me grief, and after much work porting mapentity to python 3 and django 1.9 it feels pretty irritating to be stumped by admin templating of a JS library plugins.
Could we get some clear direction as to either the 'right way' to solve this, or acknowledgement that this is indeed a missing feature?
Ok, I've found the cause of all the trouble.
The media method is 'naive', it explicitly passes the base leaflet JavaScript, plus the JavaScript and CSS defined in _form_js and _form_css which are created in leaflet/__init__.py and used to build the 'forms' plugin and added to the plugin dictionary.
I don't have a PR handy at the moment, but I do have working code. Which I am using with a custom template that overrides the callback block in order to hook into the map creation callback.
I'll try and find time to fork the repo and write a PR.
Ok, I've found the cause of all the trouble.
Great!
[...] it feels pretty irritating [...] Could we get some clear direction [...]
I completely understand, and feel sorry for that.
As I said ealier and elsewhere, I cannot maintain this library anymore. I wrote it while I was working at makina corpus, and haven't used it since I left. The new team seems pretty busy and it looks like they can't take time to review/comment/help...