django-extended-ol 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of django-extended-ol might be problematic. Click here for more details.

@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, Canton de Neuchâtel - SITN
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,4 @@
1
+ include LICENSE
2
+ include README.rst
3
+ recursive-include django_extended_ol/static *
4
+ recursive-include django_extended_ol/templates *
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.1
2
+ Name: django-extended-ol
3
+ Version: 0.1.0
4
+ Summary: An openlayers widget for Django with extended capabilities
5
+ Author-email: SITN <sitn@ne.ch>
6
+ Project-URL: Homepage, https://github.com/sitn/django-extended-ol
7
+ Project-URL: Issues, https://github.com/sitn/django-extended-ol/issues
8
+ Classifier: Environment :: Web Environment
9
+ Classifier: Framework :: Django
10
+ Classifier: Framework :: Django :: 5.0
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: BSD License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Internet :: WWW/HTTP
21
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: Django>=5.0
26
+
27
+ # django-extended-ol
28
+
29
+ django-extended-ol is a Django app that extends the basic OpenLayers Widget.
30
+
31
+ * Custom WMTS base_layer with fixed resolutions
32
+
33
+ ## Quick start
34
+
35
+ 1. Add "olwidget" to your INSTALLED_APPS setting like this:
36
+
37
+ ```python
38
+ INSTALLED_APPS = [
39
+ ...,
40
+ "olwidget",
41
+ ]
42
+ ```
43
+
44
+ 2. Configure olwidget in your settings.py, here's an example:
45
+
46
+ ```python
47
+ OLWIDGET = {
48
+ "globals": {
49
+ "srid": 2056,
50
+ "default_center": [2551470, 1211190], # optional
51
+ "default_resolution": 18, # optional
52
+ "extent": [2420000, 1030000, 2900000, 1360000],
53
+ "resolutions": [250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5, 0.25, 0.125, 0.0625]
54
+ },
55
+ "wmts": {
56
+ "layer_name": 'plan_cadastral',
57
+ "style": 'default',
58
+ "matrix_set": 'EPSG2056',
59
+ "attributions": '<a target="new" href="https://sitn.ne.ch/web/conditions_utilisation/contrat_SITN_MO.htm'
60
+ + '">© SITN</a>', # optional
61
+ "url_template": 'https://sitn.ne.ch/mapproxy95/wmts/1.0.0/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png',
62
+ "request_encoding": 'REST', # optional
63
+ "format": 'image/png' # optional
64
+ }
65
+ }
66
+ ```
67
+
68
+ 3. You can now use WMTSWidget in your gis forms:
69
+
70
+ ```python
71
+ gis_widget = WMTSWidget
72
+ ```
73
+
74
+ 4. You can also use it in your admin.py:
75
+
76
+ ```python
77
+ from django.contrib.gis import admin
78
+ from .models import YourGeomModel
79
+ from olwidget.admin import WMTSGISModelAdmin
80
+
81
+ admin.site.register(YourGeomModel, WMTSGISModelAdmin)
82
+ ```
83
+
84
+ 5. Start the development server and visit the admin.
@@ -0,0 +1,58 @@
1
+ # django-extended-ol
2
+
3
+ django-extended-ol is a Django app that extends the basic OpenLayers Widget.
4
+
5
+ * Custom WMTS base_layer with fixed resolutions
6
+
7
+ ## Quick start
8
+
9
+ 1. Add "olwidget" to your INSTALLED_APPS setting like this:
10
+
11
+ ```python
12
+ INSTALLED_APPS = [
13
+ ...,
14
+ "olwidget",
15
+ ]
16
+ ```
17
+
18
+ 2. Configure olwidget in your settings.py, here's an example:
19
+
20
+ ```python
21
+ OLWIDGET = {
22
+ "globals": {
23
+ "srid": 2056,
24
+ "default_center": [2551470, 1211190], # optional
25
+ "default_resolution": 18, # optional
26
+ "extent": [2420000, 1030000, 2900000, 1360000],
27
+ "resolutions": [250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5, 0.25, 0.125, 0.0625]
28
+ },
29
+ "wmts": {
30
+ "layer_name": 'plan_cadastral',
31
+ "style": 'default',
32
+ "matrix_set": 'EPSG2056',
33
+ "attributions": '<a target="new" href="https://sitn.ne.ch/web/conditions_utilisation/contrat_SITN_MO.htm'
34
+ + '">© SITN</a>', # optional
35
+ "url_template": 'https://sitn.ne.ch/mapproxy95/wmts/1.0.0/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png',
36
+ "request_encoding": 'REST', # optional
37
+ "format": 'image/png' # optional
38
+ }
39
+ }
40
+ ```
41
+
42
+ 3. You can now use WMTSWidget in your gis forms:
43
+
44
+ ```python
45
+ gis_widget = WMTSWidget
46
+ ```
47
+
48
+ 4. You can also use it in your admin.py:
49
+
50
+ ```python
51
+ from django.contrib.gis import admin
52
+ from .models import YourGeomModel
53
+ from olwidget.admin import WMTSGISModelAdmin
54
+
55
+ admin.site.register(YourGeomModel, WMTSGISModelAdmin)
56
+ ```
57
+
58
+ 5. Start the development server and visit the admin.
@@ -0,0 +1,6 @@
1
+ from django.contrib.gis.admin import GISModelAdmin
2
+ from .forms.widgets import WMTSWidget
3
+
4
+
5
+ class WMTSGISModelAdmin(GISModelAdmin):
6
+ gis_widget = WMTSWidget
@@ -0,0 +1,7 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class OlwidgetConfig(AppConfig):
5
+ default_auto_field = "django.db.models.BigAutoField"
6
+ name = "django_extended_ol"
7
+ label = "olwidget"
@@ -0,0 +1,39 @@
1
+ from django.contrib.gis.forms.widgets import OpenLayersWidget
2
+ from django.conf import settings
3
+
4
+
5
+ class WMTSWidget(OpenLayersWidget):
6
+ template_name = "gis/openlayers-wmts.html"
7
+ map_srid = settings.OLWIDGET["globals"].get("srid", 4326)
8
+ extent = settings.OLWIDGET["globals"]["extent"]
9
+ center_from_extent = [
10
+ (extent[0] + extent[2]) / 2,
11
+ (extent[1] + extent[3]) / 2,
12
+ ]
13
+ print(center_from_extent)
14
+ widget_options = {
15
+ "wmts_layer_name": settings.OLWIDGET["wmts"].get("layer_name"),
16
+ "wmts_style": settings.OLWIDGET["wmts"]["style"],
17
+ "wmts_matrix_set": settings.OLWIDGET["wmts"]["matrix_set"],
18
+ "wmts_attributions": settings.OLWIDGET["wmts"].get("attributions", None),
19
+ "wmts_url_template": settings.OLWIDGET["wmts"]["url_template"],
20
+ "wmts_request_encoding": settings.OLWIDGET["wmts"].get("request_encoding", 'KVP'),
21
+ "wmts_format": settings.OLWIDGET["wmts"].get("format", None),
22
+ "default_map_center": settings.OLWIDGET["globals"].get("default_center", center_from_extent),
23
+ "default_resolution": settings.OLWIDGET["globals"].get("default_resolution", 8),
24
+ "extent": extent,
25
+ "resolutions" : settings.OLWIDGET["globals"]["resolutions"]
26
+ }
27
+
28
+ class Media(OpenLayersWidget.Media):
29
+ js = OpenLayersWidget.Media.js + (
30
+ "olwidget/js/WMTSWidget.js",
31
+ )
32
+
33
+ def __init__(self, attrs=None):
34
+ super().__init__()
35
+ # Give widget_options to the template
36
+ for key in self.widget_options.keys():
37
+ self.attrs[key] = self.widget_options[key]
38
+ if attrs:
39
+ self.attrs.update(attrs)
@@ -0,0 +1,27 @@
1
+ /* global ol */
2
+ 'use strict';
3
+
4
+ class WMTSWidget extends MapWidget {
5
+ createMap() {
6
+ this.map_extent = this.options.extent;
7
+ this.projection = new ol.proj.Projection({
8
+ code: `EPSG:${this.options.map_srid}`,
9
+ extent: this.map_extent,
10
+ });
11
+ return new ol.Map({
12
+ target: this.options.map_id,
13
+ layers: [this.options.base_layer],
14
+ view: new ol.View({
15
+ center: this.options.default_center,
16
+ resolution: this.options.default_resolution,
17
+ projection: this.projection,
18
+ resolutions: this.options.resolutions,
19
+ constrainResolution: true
20
+ })
21
+ });
22
+ }
23
+
24
+ defaultCenter() {
25
+ return this.options.default_center;
26
+ }
27
+ }
@@ -0,0 +1,59 @@
1
+ <!--
2
+ This is a copy from django/contrib/gis/templates/gis/openlayers.html
3
+ The call to OlMapWidget() is not in a block so the base html template cannot be extended
4
+ -->
5
+ {% load i18n l10n %}
6
+
7
+ <div id="{{ id }}_div_map" class="dj_map_wrapper">
8
+ <div id="{{ id }}_map" class="dj_map"></div>
9
+ {% if not disabled %}<span class="clear_features"><a href="">{% translate "Delete all Features" %}</a></span>{% endif %}
10
+ {% if display_raw %}<p>{% translate "Debugging window (serialized value)" %}</p>{% endif %}
11
+ <textarea id="{{ id }}" class="vSerializedField required" cols="150" rows="10" name="{{ name }}"
12
+ {% if not display_raw %} hidden{% endif %}>{{ serialized }}</textarea>
13
+ <script>
14
+ {% block options %}var options = {
15
+ geom_name: '{{ geom_type }}',
16
+ id: '{{ id }}',
17
+ map_id: '{{ id }}_map',
18
+ map_srid: {{ map_srid|unlocalize }},
19
+ name: '{{ name }}',
20
+ extent: {{ extent|safe }},
21
+ default_center: {{ default_map_center|safe }},
22
+ resolutions: {{ resolutions|safe }},
23
+ default_resolution: {{ default_resolution|unlocalize }}
24
+ };
25
+ {% endblock %}
26
+
27
+ {% block base_layer %}
28
+
29
+ const matrixIds = [];
30
+ for (let i = 0; i < options.resolutions.length; i += 1) {
31
+ matrixIds.push(i);
32
+ }
33
+
34
+ const tileGrid = new ol.tilegrid.WMTS({
35
+ origin: [options.extent[0], options.extent[3]],
36
+ resolutions: options.resolutions,
37
+ matrixIds
38
+ });
39
+
40
+ const WMTSOptions = {
41
+ layer: '{{ wmts_layer_name }}',
42
+ style: '{{ wmts_style }}',
43
+ matrixSet: '{{ wmts_matrix_set }}',
44
+ crossOrigin: 'anonymous',
45
+ attributions: '{{ wmts_attributions|safe }}',
46
+ url: '{{ wmts_url_template }}',
47
+ tileGrid: tileGrid,
48
+ requestEncoding: '{{ wmts_request_encoding }}',
49
+ format: '{{ wmts_format }}'
50
+ }
51
+
52
+ options.base_layer = new ol.layer.Tile({
53
+ source: new ol.source.WMTS(WMTSOptions),
54
+ });
55
+ {% endblock %}
56
+
57
+ var {{ module }} = new WMTSWidget(options);
58
+ </script>
59
+ </div>
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.1
2
+ Name: django-extended-ol
3
+ Version: 0.1.0
4
+ Summary: An openlayers widget for Django with extended capabilities
5
+ Author-email: SITN <sitn@ne.ch>
6
+ Project-URL: Homepage, https://github.com/sitn/django-extended-ol
7
+ Project-URL: Issues, https://github.com/sitn/django-extended-ol/issues
8
+ Classifier: Environment :: Web Environment
9
+ Classifier: Framework :: Django
10
+ Classifier: Framework :: Django :: 5.0
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: BSD License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Internet :: WWW/HTTP
21
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: Django>=5.0
26
+
27
+ # django-extended-ol
28
+
29
+ django-extended-ol is a Django app that extends the basic OpenLayers Widget.
30
+
31
+ * Custom WMTS base_layer with fixed resolutions
32
+
33
+ ## Quick start
34
+
35
+ 1. Add "olwidget" to your INSTALLED_APPS setting like this:
36
+
37
+ ```python
38
+ INSTALLED_APPS = [
39
+ ...,
40
+ "olwidget",
41
+ ]
42
+ ```
43
+
44
+ 2. Configure olwidget in your settings.py, here's an example:
45
+
46
+ ```python
47
+ OLWIDGET = {
48
+ "globals": {
49
+ "srid": 2056,
50
+ "default_center": [2551470, 1211190], # optional
51
+ "default_resolution": 18, # optional
52
+ "extent": [2420000, 1030000, 2900000, 1360000],
53
+ "resolutions": [250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5, 0.25, 0.125, 0.0625]
54
+ },
55
+ "wmts": {
56
+ "layer_name": 'plan_cadastral',
57
+ "style": 'default',
58
+ "matrix_set": 'EPSG2056',
59
+ "attributions": '<a target="new" href="https://sitn.ne.ch/web/conditions_utilisation/contrat_SITN_MO.htm'
60
+ + '">© SITN</a>', # optional
61
+ "url_template": 'https://sitn.ne.ch/mapproxy95/wmts/1.0.0/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png',
62
+ "request_encoding": 'REST', # optional
63
+ "format": 'image/png' # optional
64
+ }
65
+ }
66
+ ```
67
+
68
+ 3. You can now use WMTSWidget in your gis forms:
69
+
70
+ ```python
71
+ gis_widget = WMTSWidget
72
+ ```
73
+
74
+ 4. You can also use it in your admin.py:
75
+
76
+ ```python
77
+ from django.contrib.gis import admin
78
+ from .models import YourGeomModel
79
+ from olwidget.admin import WMTSGISModelAdmin
80
+
81
+ admin.site.register(YourGeomModel, WMTSGISModelAdmin)
82
+ ```
83
+
84
+ 5. Start the development server and visit the admin.
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ setup.py
6
+ django_extended_ol/__init__.py
7
+ django_extended_ol/admin.py
8
+ django_extended_ol/apps.py
9
+ django_extended_ol.egg-info/PKG-INFO
10
+ django_extended_ol.egg-info/SOURCES.txt
11
+ django_extended_ol.egg-info/dependency_links.txt
12
+ django_extended_ol.egg-info/requires.txt
13
+ django_extended_ol.egg-info/top_level.txt
14
+ django_extended_ol/forms/__init__.py
15
+ django_extended_ol/forms/widgets.py
16
+ django_extended_ol/static/olwidget/js/WMTSWidget.js
17
+ django_extended_ol/templates/gis/openlayers-wmts.html
@@ -0,0 +1 @@
1
+ django_extended_ol
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ['setuptools>=40.8.0']
3
+ build-backend = 'setuptools.build_meta'
4
+
5
+ [project]
6
+ name = "django-extended-ol"
7
+ version = "0.1.0"
8
+ authors = [
9
+ { name="SITN", email="sitn@ne.ch" },
10
+ ]
11
+ description = "An openlayers widget for Django with extended capabilities"
12
+ readme = "README.md"
13
+ requires-python = ">=3.10"
14
+ dependencies = [
15
+ "Django >= 5.0"
16
+ ]
17
+ classifiers = [
18
+ "Environment :: Web Environment",
19
+ "Framework :: Django",
20
+ "Framework :: Django :: 5.0",
21
+ "Intended Audience :: Developers",
22
+ "License :: OSI Approved :: BSD License",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3 :: Only",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Topic :: Internet :: WWW/HTTP",
31
+ "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/sitn/django-extended-ol"
36
+ Issues = "https://github.com/sitn/django-extended-ol/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from setuptools import setup
2
+
3
+ setup()