Skip to content

Instantly share code, notes, and snippets.

@ptbrowne ptbrowne/admin.py
Last active Mar 20, 2017

Embed
What would you like to do?
class LeafletJSONField(JSONField):
widget = LeafletWidget(width='100%', height='400px')
def process_formdata(self, valuelist):
if valuelist:
value = valuelist[0]
if not value:
self.data = None
return
try:
self.from_json(value)
self.data = value
except ValueError:
self.data = None
def _value(self):
if self.raw_data:
return self.raw_data[0]
if self.data:
return self.data
return ""
class OrganizationView(ModelView):
form_overrides['polygon'] = LeafletJSONField
{% block tail %}
{{ super() }}
<script src="https://api.mapbox.com/mapbox.js/v2.2.1/mapbox.js"></script>
<script type='text/javascript'>
L.mapbox.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6IlpIdEpjOHcifQ.Cldl4wq_T5KOgxhLvbjE-w';
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.2.3/leaflet.draw.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.2.3/leaflet.draw.css">
<script type="text/javascript">
L.Map.addInitHook(function () {
this.addControl(L.mapbox.geocoderControl('mapbox.places'));
var streetLayer = L.mapbox.tileLayer('KEY').addTo(this);
var satelliteLayer = L.mapbox.tileLayer('KEY').addTo(this);
var baseMaps = {
"Satellite": satelliteLayer,
"Rue": streetLayer
};
L.control.layers(baseMaps).addTo(this);
this.setView([48.55, -3.15], 10);
});
</script>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.