Coder Social home page Coder Social logo

Comments (8)

capooti avatar capooti commented on August 31, 2024 3

This is the code I used:

views.py

class MyModelLayer(GeoJSONLayerView):
    def get_queryset(self):
        context = MyModel.objects.all().filter(...some_filter_here...)
        return context

urls.py

url(r'^data/mymodel.geojson$', 
    MyModelLayer.as_view(model=MyModel,
        properties=(
            ['field1', 'field2',]
        )),
        name='mymodel-geojson'),

from django-geojson.

leplatrem avatar leplatrem commented on August 31, 2024 1

Hi !

It looks like you're confused between the view (serving GeoJSON) and the template filter (embedding GeoJSON within an HTML template).

So, if you need to serve GeoJSON with some properties, just add this in urls.py :

 GeoJSONLayerView.as_view(model=MyModel, properties=('field1', 'field2'), name='myname')

But if you need to embed some GeoJSON within an HTML page (less common to be honest), you may be right, the many parameters are maybe useless ! I will open another issue for that :)

from django-geojson.

capooti avatar capooti commented on August 31, 2024

I ended up using an inherited generic views, redefining the get_queryset method to return the desired queryset.
Though, still curious about how to pass the parameters to the geojsonfeature filter.

from django-geojson.

capooti avatar capooti commented on August 31, 2024

Hi, no I am not confused :) I exactly did what you suggested in urls.
I had then to use the generic view approach and redefine the get_queryset as I did not find a different way to pass a filtered query set.
My question here is: how to pass the parameters to the geojsonfeature filter? Thanks in advance.

from django-geojson.

leplatrem avatar leplatrem commented on August 31, 2024

Ok, great, indeed a filtered queryset like this should work.

Regarding the other question: so far it looks like the template filter geojsonfeature does not allow parameters (see issue #16). Why do you need it for ?

from django-geojson.

capooti avatar capooti commented on August 31, 2024

because according to this:
https://github.com/makinacorpus/django-geojson/blob/master/djgeojson/templatetags/geojson_tags.py#L17

we may pass the following parameters to the filter:

def geojsonfeature(source, geometry_field='geom', properties=None, srid=GEOJSON_DEFAULT_SRID)

but cannot figure out how to pass the properties and srid parameters (it looks like a Django filter will accept just one parameter from template).
The only way I can figure out to use this filter if you need to modify its parameters is by inheriting from it and change the parameters in the inherited filter.
Is this the intended behaviour?
Regards

from django-geojson.

leplatrem avatar leplatrem commented on August 31, 2024

Yes indeed, this part of the code was written in a way that cannot be used :D (purpose of issue #16)

We could specify only one parameter as string (split on :)

 {{ object|geojsonfeature:"name,age" }}
 {{ object|geojsonfeature:"name:geom" }}
 {{ object|geojsonfeature:"title,description:geom:2154" }}
 {{ object|geojsonfeature:":geom:4326" }}

from django-geojson.

capooti avatar capooti commented on August 31, 2024

+1, thanks :)

from django-geojson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.