Giter Site home page Giter Site logo

django-leaflet's Introduction

Django Leaflet

See the documentation for more information.

django-leaflet allows you to use Leaflet in your Django projects.

It embeds Leaflet version 1.9.3.

Documentation Status

image

image

image

Main purposes of having a python package for the Leaflet Javascript library :

  • Install and enjoy ;
  • Do not embed Leaflet assets in every Django project ;
  • Enjoy geometry edition with Leaflet form widget ;
  • Control apparence and settings of maps from Django settings (e.g. at deployment) ;
  • Reuse Leaflet map initialization code (e.g. local projections) ;
note

django-leaflet is compatible with django-geojson fields, which allow handling geographic data without spatial database.

TUTORIALS

AUTHORS

makinacom_

LICENSE

  • Lesser GNU Public License
  • Leaflet Copyright - 2010-2011 CloudMade, Vladimir Agafonkin

django-leaflet's People

Contributors

adamchainz avatar anaethelion avatar apinsard avatar arctelix avatar brutasse avatar claudep avatar dependabot[bot] avatar djcoin avatar dyve avatar fanquake avatar gagaro avatar gutard avatar ingenieroariel avatar itbabu avatar josemazo avatar kiorky avatar kostyaesmukov avatar leplatrem avatar manelclos avatar mfrasca avatar mstarikov avatar ndufrane avatar nimasmi avatar nonzero avatar petrdlouhy avatar rgreenemun avatar sebdiem avatar sikmir avatar smcoll avatar zhigal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-leaflet's Issues

Refactor map_fragment JS code

Basic ideas:

  • Avoid "preprocessing" of JS code
  • Simplify bounds initialization...
  • Use load event instead of callback ?

Language Issues

Hi there,

Thanks for taking the time to create an app that integrates with leaflet!

I'm unfortunately running into an issue on a translated site.

  1. standard map & django app
  2. map + markers work perfectly when Content-Language: en
    3.no markers show switching to Content-Language: de

Any thoughts?

Could be related to #43 as there was no de translation but so far no luck

de-no_markers
en-has_markers

Reset view advanced options

Although not in documentation I see that we can have resetview :true. Is it possible to make that button locate the user instead of showing the whole map? If not what can be the easiest way to bind it with a geolocate user function?

Of course we can set it to false and create a new button in that place but since it's there I was thinking we can use that one for that purpose. Thanks.

map:init event never triggered

I have not done anything out of the ordinary and for some reason the map:init event is never triggered. Using the callback works as expected. Any ideas? Best way to debug?

Is there a way to change Leaflet.draw draw and edit options?

It seems the 'drawControl' is discarded after it gets options, in the L.GeometryField.addTo

I tried getting the control from the map navigating the leaflet container dom, but could not find it. I need to do something like drawControl.setDrawingOptions({'polygon': {'showArea': true}});

Is there an existing way to do this that I'm missing, or show I save the drawControl somewhere?

Allow plugin assets to use conditional comments

Some leaflet plugins specify conditional css. There is currently no way to render these using the plugin architecture.

Not sure how best this would be specified. Perhaps:

'css': ('/path/to/stylesheet.css',('ie7', 'ie8')), ?

Arguments of event map:init doesn't contain map

Hi,

since 0.8.0 my map load to fail since when doing :
$(window).on('map:init', function (e) { ... });

'e' doesn't contain the 'map' attribute.

By looking a bit in the debugger it seems that new CustomEvent(type, data); [leaflet-extras.js:210] doesn't add the data to the evt.

This problem seems to have been introduced by c14ff11 (we are using jquery here)

Typo in readme

In the example for the callback:

L.marker([50.5, 30.5]).addTo(e.map);

perhaps should be:

L.marker([50.5, 30.5]).addTo(map);

Ascii decode error on install

Hi!

I'm trying to pip install the library on ubuntu 14.04, in a virtualenv set up to use python3.3. And I end up with an ascii decode error thrown by the setup.py.

Here's the command I'm using to install:

pip install --allow-all-external --no-input --exists-action=w -r requirements.txt

Here's the output:

 Downloading/unpacking django-leaflet (from -r requirements.txt (line 33))
             Running setup.py (path:/home/blablabla/env/build/django-leaflet/setup.py) egg_info for package django-leaflet
               Traceback (most recent call last):
                 File "<string>", line 17, in <module>
                 File "/home/blablabla/env/build/django-leaflet/setup.py", line 19, in <module>
                   long_description=open(os.path.join(here, 'README.rst')).read() + '\n\n' +
                 File "/home/blablabla/env/lib/python3.3/encodings/ascii.py", line 26, in decode
                   return codecs.ascii_decode(input, self.errors)[0]
               UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 5022: ordinal not in range(128)
               Complete output from command python setup.py egg_info:
               Traceback (most recent call last):

             File "<string>", line 17, in <module>

             File "/home/blablabla/env/build/django-leaflet/setup.py", line 19, in <module>

               long_description=open(os.path.join(here, 'README.rst')).read() + '\n\n' +

             File "/home/blablablabla/env/lib/python3.3/encodings/ascii.py", line 26, in decode

               return codecs.ascii_decode(input, self.errors)[0]

           UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 5022: ordinal not in range(128)

           ----------------------------------------
           Cleaning up...

I'm not sure about the proper solution. Maybe casting the long_description variable input to unicode explicitly when we're using python3?

Let me know,
Thanks!

Error: Uncaught SyntaxError: Unexpected token -

Hi,
I am using django-leaflet with form wizard for rendering multiple forms having django-leaflet forms.

I get error Uncaught SyntaxError: Unexpected token - I think that it is because of hyphen in form fields.

Is there any way to work around this problem ?

Thanks.
Rama

imperial scale control does not appear

The README infers that when 'SCALE' is True, "km and miles" will both display in the scale control, which is the Leaflet default: http://leafletjs.com/reference.html#control-scale. Currently, this option behaves as a toggle for a metric-only scale control, which is perhaps a stylistic decision.

My preference is that we have the option to enable the metric and imperial scales individually. i'm happy to contribute but want to have a little discussion first to discover the preferred way to do this.

One conceivable option is to show both metric and imperial scales when 'SCALE' is True. It's a quick fix which adheres to Leaflet defaults, but isn't likely what the majority of users want (which is, i presume, metric-only).

Another option would be to implement the control with 'SCALE' having values of None, "metric", "imperial", or "both". This would be a backwards-incompatible change.

A much more granular approach would be to set 'SCALE' to another dict, matching the options for L.control.scale:

LEAFLET_CONFIG = {
    'SCALE': {
        'position': 'bottomleft',
        'maxWidth': 100,
        'metric': True,
        'imperial': True,
        'updateWhenIdle': False
    }
}

If we went with that approach, we could perhaps maintain the usage of True as an alternate way of turning on a default scale control configuration.

Or we could name a new LEAFLET_SCALE_CONFIG similar to the above and still use 'SCALE': True to enable it.

In any case, i have a situation when an imperial-only scale control is necessary, and i'd like to be able to set this site-wide through LEAFLET_CONFIG. Thoughts?

Wrong parameters name in README

Hi guys,

I just created a beautiful map in a Django project in less than 2 minutes, so thank for this amazing package.

I noticed that the two parameters MAP_CENTER and MAP_ZOOM are not doing anything. However, using DEFAULT_CENTER and DEFAULT_ZOOM worked, so you might consider updating the documentation.

Thanks.

redrawing the map with new data

I'd like to redraw the map after main_map_init has finished creating the map.

However I'd like to change the url which fetches the geoJSON data I am plotting.

I could I do this? could you document this case?

Django Admin - Unable to close shape

I am unable to close a shape made in admin.
It works correctly on the leaflet.draw demo page.

leaflet1

Also, the shape gets darker each time I try to close it.

leaflet2

Using LeafletGeoAdmin erases current value in change form

Editing a pre-existing object in the admin does not present the current geometry on the map or in the WKT field.

Submitting the form unchanged results in the field value being erased and/or "No geometry value provided." being thrown on the field.

MAX_ZOOM only applies to map

When setting max_zoom to 22, the map will allow to zoom deeper, but the layers won't draw, as max_zoom for the base layer is still the default.

What about adding an options dict to the TILES definition much like in urls.py?

django-leaflet in admin

Would it be possible for leafelt to have it's own admin.LeafletModelAdmin for the admin page? django-olwidget-0.6.0 is limited and quickly becoming outdated. Wish I had the skills to attempt it.

Form widget - could allow it to default to draw?

For example, if you have a PointField, the map widget starts with the click interaction being 'pan/zoom' only. When what the user would normally want to do is just drop a pin (because that is the purpose of this widget, to define a location), perhaps you should be able to make it (optionally) start in draw mode?

Then - the first interaction the user has with the map will be dropping a pin (or whatever) - which is the action they ultimately want to perform (particularly as you can still zoom/pan the map in draw mode).

ImportError: cannot import name GEOSException

With a fresh install of Django 1.6.2 and django-leaflet 1.13, Django throws this import error:
ImportError: cannot import name GEOSException

I can get rid of it renaming/deleting leaflet/admin.py

Remove minimap after init?

I have minimap set by default which is great, but what would be the correct way to remove it from certain maps?

Simplify customizing LeafletWidget map

If you need to customize the map used by the widget, currently you need to override the js field behaviour by extending GeometryField, then in django you subclass the LeafletWidget to specify the custom geometry_field_class, as follows:

::

YourGeometryField = L.GeometryField.extend({
    addTo: function (map) {
        L.GeometryField.prototype.addTo.call(this, map);
        // Customize map for field
        console.log(this);
    },
    // See GeometryField source (static/leaflet/leaflet.forms.js) to override more stuff...
});

::

class YourMapWidget(LeafletWidget):
    geometry_field_class = 'YourGeometryField'

class YourForm(forms.ModelForm):
    class Meta:
        model = YourModel
        fields = ('name', 'geom')
        widgets = {'geom': YourMapWidget()}

A shortcut would be useful to pass the geometry_field_class to the form instead of having to subclass LeafletWidget.

Window event 'map:init' not available in Chrome through addEventListener

In the docs, it says you can get a reference to the map using a brutish way or by using an event listener.

Using the form widget version of the map (I haven't tested the normal map tags), this event listener does not work in Chrome. A simple test:

<script type="text/javascript">
    window.addEventListener('map:init', function (e) {
            console.log("addEventListener")
    }, false);
    $(window).on('map:init', function (e) {
            console.log("jQuery on");
    });
</script>

Results in the "jQuery on" message in the console. This was using Chrome 29.0.1547.65.

I guess that is less to do with the library than Chrome doing something odd, but might be worth noting that in the docs?

Can't change marker icon in geojson layer

Hi, I am using django-leaflet for displaying some geojson layers in which there are points and other geometries. My idea was to send each iconUrl in the geojson and then style each of them automatically. With polygons all the styles (fill, opacity, color...) work perfect but I can't style point marker's image. They seem to go to another layer where I can't set the style and it gets overwritten with the default style.

Here's my code :

CREATE THE LAYER:

L.geoJson(data, {style: getStyle});

STYLE FUNCTION :

function getStyle(feature) {

// Tried different options
// Option 1 :
var icon = L.Icon.extend({ options : { iconUrl: feature.properties.icon.icon_url} });

// Option 2 : 
var icon = L.Icon.extend({ iconUrl: feature.properties.icon.icon_url});

// Option 3 :
var icon = L.icon({ iconUrl: feature.properties.icon.icon_url});

  return {
    fillColor: feature.properties.color || 'gray',
    weight: feature.properties.weight || 2,
    opacity: feature.properties.border_opacity || 0.8,
    color: feature.properties.border_color || 'black',
    fillOpacity: feature.properties.fill_opacity || 0.5,
    dashArray: feature.properties.dash_array || 1,
    icon: icon,
    iconUrl: feature.properties.icon.icon_url || '' // Just in case it should be this way
  };
}

EXAMPLE GEOJSON:

{
    "type": "FeatureCollection",
    "features": [
        {
            "geometry": {
                "type": "GeometryCollection",
                "geometries": [
                    {
                        "type": "LineString",
                        "coordinates": [
                            [
                                -3.92395337374613,
                                38.984058965480564
                            ],
                            [
                                -3.9220487181037775,
                                38.989367645629486
                            ],
                            [
                                -3.92395337374613,
                                38.984058965480564
                            ]
                        ]
                    },
                    {
                        "type": "Point",
                        "coordinates": [
                            -3.92084130141269,
                            38.9897951477041
                        ]
                    }
                ]
            },
            "type": "Feature",
            "properties": {
                "border_opacity": 0.1,
                "dash_array": "20, 5",
                "fill_opacity": 0.8,
                "icon": {
                    "icon_url": "http://localhost:3000/static/img/ct.png"
                }
            }
        },
        {
            "geometry": {
                "type": "GeometryCollection",
                "geometries": [
                    {
                        "type": "LineString",
                        "coordinates": [
                            [
                                -3.9225556358363347,
                                38.995273702863386
                            ],
                            [
                                -3.9223839614994938,
                                38.99636516690695
                            ],
                            [
                                -3.9225556358363347,
                                38.995273702863386
                            ]
                        ]
                    },
                    {
                        "type": "Point",
                        "coordinates": [
                            -3.92427800018094,
                            38.9930299609743
                        ]
                    }
                ]
            },
            "type": "Feature",
            "properties": {
                "border_opacity": 0.1,
                "dash_array": "20, 5",
                "fill_opacity": 0.8,
                "icon": {
                    "icon_url": "http://localhost:3000/static/img/ct.png"
                }
            }
        }
    ]
}

Everything but the iconUrl works perfectly. But as I previously said, I think markers are being created in a different layer (for them to be in front of everything), so I can't style them. Am I right or there is a way to do this?

Thank you very much.

display within hidden div (tabs in twitter bootstra)

When i trying display django-leaflet in TWB3 tabs, map should be reinitialized with Leaflet function:
map.invalidateSize()

I put in settings.py:

LEAFLET_CONFIG = {
    'NO_GLOBALS': False,
}

and wrote small script with reinitializing map after click on tab:

$("#mapTab").click(function(event) {
         map.invalidateSize();
});

Unfortunately, with no effect. Maps is still displayed only partially.
And now i'm not sure, what i'm doing wrong.

Customize LeafletWidget map

This is more of a conceptual question than an issue...

Have successfully used django-leaflet for read-only point display by following the concepts at https://github.com/makinacorpus/django-leaflet#usage. Have used both LEAFLET_CONFIG and the map_init js callback to heavily customize the map, including custom controls, marker icons, marker clusters, basemaps, overlays, etc.

Now editing point data and have successfully implemented the LeafletWidget with a PointField by following https://github.com/makinacorpus/django-leaflet#leaflet-map-forms-widgets, however am unsure how to go about customizing the map. What is the most straightforward way to edit data while having full control over the map initialization?

Thanks in advance,
Randal

Support for widget in admin inlines

It would be great to have a LeafletGeoInlineAdmin class, or perhaps just a mixin. There are two types of inline (stacked and tabular). Are multiple widgets per page supported? We'd have to figure out how to create a new widget with the right defaults on a click of the "Add another..." link.

Support for multiple maps with different configs

I understood that in settings.py you could set config for a map like crs and spatial extent. I have multiple maps on a page with different crs. Is it possible to configure these different maps with django-leaflet?

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.