django-extended-ol 0.1.0__py3-none-any.whl

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.

File without changes
@@ -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"
File without changes
@@ -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,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,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,12 @@
1
+ django_extended_ol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ django_extended_ol/admin.py,sha256=tE7_DtllUHuNSEpsKLkfUdLpSX7uhjZa-Q5y2UH7h7A,165
3
+ django_extended_ol/apps.py,sha256=hw3h5JXhThL1TSDfWa2wxwBTWvCHuaEHWb8axT_QP88,188
4
+ django_extended_ol/forms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ django_extended_ol/forms/widgets.py,sha256=uVSj4TuJLGV-Fn8-AJsj00nrxZXSwwHqBI5IC2lErHc,1712
6
+ django_extended_ol/static/olwidget/js/WMTSWidget.js,sha256=6fGzhd8wx20Oll_64fu7ZPfs9MZwj74vQYZ7hnanfxE,796
7
+ django_extended_ol/templates/gis/openlayers-wmts.html,sha256=4MhZr_ldK_w7t2sswmHjTekX_P_js9SsXHW_0ESBSPw,1926
8
+ django_extended_ol-0.1.0.dist-info/LICENSE,sha256=0uvSPKfP0VUrQ1XqeXD62tYc54cfQqt21YI9lWW9hq8,1564
9
+ django_extended_ol-0.1.0.dist-info/METADATA,sha256=aXRMb31ksRmTegqtGBm0I1HQHSn-_szdC8rvpDHT3WY,2721
10
+ django_extended_ol-0.1.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
11
+ django_extended_ol-0.1.0.dist-info/top_level.txt,sha256=rX8AqitfQu0etd6PoOeNxcRl5fsus-YOs932PGUjDIs,19
12
+ django_extended_ol-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ django_extended_ol