Skip to main content

An openlayers widget for Django with extended capabilities

Project description

django-extended-ol

django-extended-ol is a Django app that extends the basic OpenLayers Widget.

Features:

  • Custom WMTS base_layer with fixed resolutions
  • Search on the map (third-party service needed)

Quick start

pip install django-extended-ol
  1. Add "django_extended_ol" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
    ...,
    "django_extended_ol",
]
  1. Configure django_extended_ol in your settings.py, here's an example:
OLWIDGET = {
    "globals": {
        "srid": 2056,
        "default_center": [2551470, 1211190], # optional
        "default_resolution": 18, # optional
        "extent": [2420000, 1030000, 2900000, 1360000],
        "resolutions": [250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5, 0.25, 0.125, 0.0625]
    },
    "wmts": {
        "layer_name": 'plan_cadastral',
        "style": 'default',
        "matrix_set": 'EPSG2056',
        "attributions": '<a target="new" href="https://sitn.ne.ch/web/conditions_utilisation/contrat_SITN_MO.htm'
            + '">© SITN</a>', # optional
        "url_template": 'https://sitn.ne.ch/mapproxy95/wmts/1.0.0/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png',
        "request_encoding": 'REST', # optional
        "format": 'image/png' # optional
    },
    "search": { # optional, only if you want a search service
        "url_template": 'https://sitn.ne.ch/search?limit=10&partitionlimit=2&interface=desktop&query={search_term}'
    }
}
  1. You can now use WMTSWidget in your gis forms:
from django_extended_ol.forms.widgets import WMTSWidget
...
class MyCustomGISClass:
    gis_widget = WMTSWidget

Note that CSS is not provided by default, you have to give your map a height like:

    .dj_map {
        height: 400px;
    }

If you want a search widget, you can use WMTSWithSearchWidget. Please check search service specification below.

  1. You can also use it in your admin.py:
from django.contrib.gis import admin
from .models import YourGeomModel
from olwidget.admin import WMTSGISModelAdmin

admin.site.register(YourGeomModel, WMTSGISModelAdmin)

If you want the search widget please use WMTSGISWithSearchModelAdmin. Please check search service specification below.

  1. Start the development server and visit the admin.

Search service specification

You'll need a templated URL as showcased in the settings.py above. Such service should reply GeoJSON feature collection and each feature should have a bbox and a property named label.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_extended_ol-1.1.4.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_extended_ol-1.1.4-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file django_extended_ol-1.1.4.tar.gz.

File metadata

  • Download URL: django_extended_ol-1.1.4.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.5

File hashes

Hashes for django_extended_ol-1.1.4.tar.gz
Algorithm Hash digest
SHA256 da7cd2ac427a7fe8a9fd836bb14b6c6bd5dd10080f7c3522204c7275170f81aa
MD5 b2ad7be7b661fb01a5edfd13054388ff
BLAKE2b-256 7c316f5a757ef7496d95e4f38ee43f74cf88cecd1cbe82a96294223f761d34d0

See more details on using hashes here.

File details

Details for the file django_extended_ol-1.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_extended_ol-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0747ecf4696cdaac72321292a2cdce9e71d9b17629254e2e31e11f6294d269e0
MD5 7ff652ed80e57629c1261538a7136742
BLAKE2b-256 c18432c7d41651b32ab8c2e8c32cdc6565119597b4ae1fd868c04826cc56c480

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page