Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Map in Template #361

Open
premudeshi opened this issue Jan 2, 2023 · 2 comments
Open

Display Map in Template #361

premudeshi opened this issue Jan 2, 2023 · 2 comments

Comments

@premudeshi
Copy link

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
Copy link
Author

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?

@Gagaro
Copy link
Member

Gagaro commented Jan 9, 2023

Maybe try setting the geom_type:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants