Hi everyone,
I would like to change the base map of the OSMWidget to a satellite image, in order to see the farm plot and allow them to add the field boundary.
I would like to see something like this
Someone know how to do so?
This is my forms.py
from django import forms
from django.contrib.gis import forms as geoforms
from .models import MultiPolygon
class MultiPolygonForm(forms.ModelForm):
geom = geoforms.PolygonField(widget=geoforms.OSMWidget(attrs={'map_width': 800, 'map_height': 500}))
class Meta:
model = MultiPolygon
fields = ('name', "rotation", "crop", "geom")
Thanks
I never worked with gis
, but a quick search on google led me to this article, hope it works.
1 Like
Thanks to report the article, but i would like to change directly the widget attributes of OSMWidget if it is possible to get as i said before a satellite image.
Hmm, that’s tricky. You’re going to need a few “here-and-there” knowledge to pull this off.
My shot on this is:
- Create a custom template that inherits from
gis/openlayers.html
source code.
- Redefine the block
base_layer
on your child template, and looking on the internet, you can set the layer to this reference, this will probably set the map to the satellite layer.
- Create a widget that inherits from
django.contrib.gis.forms.widgets.OpenLayersWidget
source code and set the template_name
to your custom template.
- Use the widget you just created on the form.