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

Add Leaflet backend to enable custom map providers e.g. OpenStreetMap #94

Open
wants to merge 9 commits into
base: django-1.11
Choose a base branch
from

Conversation

st-a
Copy link

@st-a st-a commented Nov 1, 2017

First of all: Thanks for the great Django plugin! Extending your code was straight forward, although I have never written custom Django widgets myself.

The existing JS code was not modified, to maintain backward compatibility. Instead there was a new settings.py parameter introduced: GEOPOSITION_BACKEND. Only the JS and CSS files needed for the specified backend will be loaded. While google is the default backend, there is no need for existing users to change their configuration files.

To use the new backend add GEOPOSITION_BACKEND = 'leaflet' to settings.py. This will load Leaflet to display the default OpenStreetMap. As Leaflet is provider agnostic, you could use any other map provider from the following list: http://leaflet-extras.github.io/leaflet-providers/preview

Here is an example configuration displaying satellite imagery with some more custom map options:

GEOPOSITION_BACKEND = 'leaflet'
GEOPOSITION_MAP_OPTIONS = {
    'url': 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
    'attribution': 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community',
    'dataZoom': 15,  # zoom for records with geposition set already
    'initialZoom': 9,  # zoom for records without geoposition set
    'initialCenter': [51, 13.45]  # center for records without geoposition set
}

If you are OK with the proposed architecture, I'll add documentation and examples to the readme accordingly.

@st-a
Copy link
Author

st-a commented Nov 1, 2017

Looks like PR #86 needs to be merged to fix the CI build errors.

@darccio
Copy link

darccio commented Oct 29, 2018

Thanks for your code! I integrated this PR in my fork and it works flawlessly https://github.com/imdario/django-geoposition/releases/tag/v0.3.6

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

Successfully merging this pull request may close these issues.

None yet

3 participants