Last active
March 20, 2017 09:32
-
-
Save ptbrowne/0de17a427e2c69811c90ecd8b2b60acc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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