django-leaflet icon indicating copy to clipboard operation
django-leaflet copied to clipboard

Display Map in Template

Open premudeshi opened this issue 3 years ago • 2 comments

Hello, I am having issues with displaying the map in a template. I can get it to display as a form, but I am unable to display it, without any of the edit controls. I was also wondering if it was possible to implement leaflet-image, to turn the map into a data url, which would be used as a thumbnail for the map?

premudeshi avatar Jan 02 '23 16:01 premudeshi

I am also having issues with editing the pins in the form. This is my models.py

class Location(models.Model):
    draft = models.BooleanField(default=False)
    user = models.ForeignKey(User, on_delete=models.PROTECT, related_name='locations')
    date = models.DateTimeField(auto_now=True)
    claim = models.ForeignKey(ClaimMaster, on_delete=models.CASCADE, related_name='locations', null=True,blank=True)
    description = models.TextField()
    location = GeometryCollectionField()
    thumbnail = models.TextField(blank=True)

This is my forms.py

class LocationModelForm(forms.ModelForm):

    class Meta:
        model = Location
        labels = {
            'claim': 'Attach to Claim',
            'description': 'Description',
            'location': 'Geometery Pin'
        }
        fields = ['claim', 'description', 'location']
        widgets = {
            'location': LeafletWidget()}

Anytime I attempt to save the form, I get the error 'Polygon does not match geometry type'. However, it works perfectly in the admin form. What am I missing?

premudeshi avatar Jan 03 '23 01:01 premudeshi

Maybe try setting the geom_type:

widgets = {'location': LeafletWidget(attrs={'geom_type': "GEOMETRYCOLLECTION"})}

Gagaro avatar Jan 09 '23 10:01 Gagaro