django-extended-ol 1.0.0__tar.gz → 1.1.1__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.

Files changed (22) hide show
  1. {django_extended_ol-1.0.0/django_extended_ol.egg-info → django_extended_ol-1.1.1}/PKG-INFO +16 -8
  2. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/README.md +12 -5
  3. django_extended_ol-1.1.1/django_extended_ol/admin.py +10 -0
  4. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/django_extended_ol/forms/widgets.py +11 -1
  5. django_extended_ol-1.1.1/django_extended_ol/static/olwidget/css/WMTSWidget.css +30 -0
  6. django_extended_ol-1.1.1/django_extended_ol/static/olwidget/js/WMTSWidget.js +91 -0
  7. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/django_extended_ol/templates/gis/openlayers-wmts.html +8 -0
  8. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1/django_extended_ol.egg-info}/PKG-INFO +16 -8
  9. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/django_extended_ol.egg-info/SOURCES.txt +1 -0
  10. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/pyproject.toml +2 -1
  11. django_extended_ol-1.0.0/django_extended_ol/admin.py +0 -6
  12. django_extended_ol-1.0.0/django_extended_ol/static/olwidget/js/WMTSWidget.js +0 -27
  13. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/LICENSE +0 -0
  14. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/MANIFEST.in +0 -0
  15. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/django_extended_ol/__init__.py +0 -0
  16. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/django_extended_ol/apps.py +0 -0
  17. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/django_extended_ol/forms/__init__.py +0 -0
  18. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/django_extended_ol.egg-info/dependency_links.txt +0 -0
  19. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/django_extended_ol.egg-info/requires.txt +0 -0
  20. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/django_extended_ol.egg-info/top_level.txt +0 -0
  21. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/setup.cfg +0 -0
  22. {django_extended_ol-1.0.0 → django_extended_ol-1.1.1}/setup.py +0 -0
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: django-extended-ol
3
- Version: 1.0.0
3
+ Version: 1.1.1
4
4
  Summary: An openlayers widget for Django with extended capabilities
5
- Author-email: SITN <sitn@ne.ch>
5
+ Author-email: SITN <sitn@ne.ch>, maltaesousa <stephane.maltaesousa@ne.ch>
6
6
  Project-URL: Homepage, https://github.com/sitn/django-extended-ol
7
7
  Project-URL: Issues, https://github.com/sitn/django-extended-ol/issues
8
8
  Classifier: Environment :: Web Environment
@@ -23,6 +23,7 @@ Requires-Python: >=3.10
23
23
  Description-Content-Type: text/markdown
24
24
  License-File: LICENSE
25
25
  Requires-Dist: Django>=5.0
26
+ Dynamic: license-file
26
27
 
27
28
  # django-extended-ol
28
29
 
@@ -31,6 +32,7 @@ django-extended-ol is a Django app that extends the basic OpenLayers Widget.
31
32
  Features:
32
33
 
33
34
  * Custom WMTS base_layer with fixed resolutions
35
+ * Search on the map (third-party service needed)
34
36
 
35
37
  ## Quick start
36
38
 
@@ -67,11 +69,14 @@ OLWIDGET = {
67
69
  "url_template": 'https://sitn.ne.ch/mapproxy95/wmts/1.0.0/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png',
68
70
  "request_encoding": 'REST', # optional
69
71
  "format": 'image/png' # optional
72
+ },
73
+ "search": { # optional, only if you want a search service
74
+ "url_template": 'https://sitn.ne.ch/search?limit=10&partitionlimit=2&interface=desktop&query={search_term}'
70
75
  }
71
76
  }
72
77
  ```
73
78
 
74
- 3. You can now use WMTSWidget in your gis forms:
79
+ 3. You can now use `WMTSWidget` in your gis forms:
75
80
 
76
81
  ```python
77
82
  from django_extended_ol.forms.widgets import WMTSWidget
@@ -80,6 +85,8 @@ class MyCustomGISClass:
80
85
  gis_widget = WMTSWidget
81
86
  ```
82
87
 
88
+ If you want a search widget, you can use `WMTSWithSearchWidget`. Please check search service specification below.
89
+
83
90
  4. You can also use it in your admin.py:
84
91
 
85
92
  ```python
@@ -90,11 +97,12 @@ class MyCustomGISClass:
90
97
  admin.site.register(YourGeomModel, WMTSGISModelAdmin)
91
98
  ```
92
99
 
100
+ If you want the search widget please use `WMTSGISWithSearchModelAdmin`. Please check search service specification below.
101
+
93
102
  5. Start the development server and visit the admin.
94
103
 
95
104
 
96
- # Build this package
105
+ ## Search service specification
97
106
 
98
- ```sh
99
- py -m build
100
- ```
107
+ You'll need a templated URL as showcased in the `settings.py` above.
108
+ Such service should reply GeoJSON feature collection and each feature should have a `bbox` and a property named `label`.
@@ -5,6 +5,7 @@ django-extended-ol is a Django app that extends the basic OpenLayers Widget.
5
5
  Features:
6
6
 
7
7
  * Custom WMTS base_layer with fixed resolutions
8
+ * Search on the map (third-party service needed)
8
9
 
9
10
  ## Quick start
10
11
 
@@ -41,11 +42,14 @@ OLWIDGET = {
41
42
  "url_template": 'https://sitn.ne.ch/mapproxy95/wmts/1.0.0/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png',
42
43
  "request_encoding": 'REST', # optional
43
44
  "format": 'image/png' # optional
45
+ },
46
+ "search": { # optional, only if you want a search service
47
+ "url_template": 'https://sitn.ne.ch/search?limit=10&partitionlimit=2&interface=desktop&query={search_term}'
44
48
  }
45
49
  }
46
50
  ```
47
51
 
48
- 3. You can now use WMTSWidget in your gis forms:
52
+ 3. You can now use `WMTSWidget` in your gis forms:
49
53
 
50
54
  ```python
51
55
  from django_extended_ol.forms.widgets import WMTSWidget
@@ -54,6 +58,8 @@ class MyCustomGISClass:
54
58
  gis_widget = WMTSWidget
55
59
  ```
56
60
 
61
+ If you want a search widget, you can use `WMTSWithSearchWidget`. Please check search service specification below.
62
+
57
63
  4. You can also use it in your admin.py:
58
64
 
59
65
  ```python
@@ -64,11 +70,12 @@ class MyCustomGISClass:
64
70
  admin.site.register(YourGeomModel, WMTSGISModelAdmin)
65
71
  ```
66
72
 
73
+ If you want the search widget please use `WMTSGISWithSearchModelAdmin`. Please check search service specification below.
74
+
67
75
  5. Start the development server and visit the admin.
68
76
 
69
77
 
70
- # Build this package
78
+ ## Search service specification
71
79
 
72
- ```sh
73
- py -m build
74
- ```
80
+ You'll need a templated URL as showcased in the `settings.py` above.
81
+ Such service should reply GeoJSON feature collection and each feature should have a `bbox` and a property named `label`.
@@ -0,0 +1,10 @@
1
+ from django.contrib.gis.admin import GISModelAdmin
2
+ from .forms.widgets import WMTSWidget, WMTSWithSearchWidget
3
+
4
+
5
+ class WMTSGISModelAdmin(GISModelAdmin):
6
+ gis_widget = WMTSWidget
7
+
8
+
9
+ class WMTSGISWithSearchModelAdmin(GISModelAdmin):
10
+ gis_widget = WMTSWithSearchWidget
@@ -21,13 +21,16 @@ class WMTSWidget(OpenLayersWidget):
21
21
  "default_map_center": settings.OLWIDGET["globals"].get("default_center", center_from_extent),
22
22
  "default_resolution": settings.OLWIDGET["globals"].get("default_resolution", 8),
23
23
  "extent": extent,
24
- "resolutions" : settings.OLWIDGET["globals"]["resolutions"]
24
+ "resolutions": settings.OLWIDGET["globals"]["resolutions"]
25
25
  }
26
26
 
27
27
  class Media(OpenLayersWidget.Media):
28
28
  js = OpenLayersWidget.Media.js + (
29
29
  "olwidget/js/WMTSWidget.js",
30
30
  )
31
+ css = {
32
+ "all": OpenLayersWidget.Media.css["all"] + ("olwidget/css/WMTSWidget.css",)
33
+ }
31
34
 
32
35
  def __init__(self, attrs=None):
33
36
  super().__init__()
@@ -36,3 +39,10 @@ class WMTSWidget(OpenLayersWidget):
36
39
  self.attrs[key] = self.widget_options[key]
37
40
  if attrs:
38
41
  self.attrs.update(attrs)
42
+
43
+
44
+ class WMTSWithSearchWidget(WMTSWidget):
45
+ widget_options = {
46
+ **WMTSWidget.widget_options,
47
+ "search_url": settings.OLWIDGET["search"].get("url_template", None)
48
+ }
@@ -0,0 +1,30 @@
1
+ .ext-ol-search {
2
+ position: absolute;
3
+ top: 0.5em;
4
+ left: 2.5em;
5
+ }
6
+
7
+ .ext-ol-autocomplete-results {
8
+ border: 1px solid var(--border-color);
9
+ max-height: 200px;
10
+ overflow-y: auto;
11
+ background-color: var(--body-bg);
12
+ color: var(--body-fg);
13
+ width: 20em;
14
+ position: absolute;
15
+ top: 2.5em;
16
+ left: 2.5em;
17
+ }
18
+
19
+ .ext-ol-autocomplete-results div {
20
+ padding: 8px;
21
+ cursor: pointer;
22
+ }
23
+
24
+ .ext-ol-autocomplete-results div:hover {
25
+ background-color: var(--darkened-bg);
26
+ }
27
+
28
+ .ext-ol-hidden {
29
+ display: none;
30
+ }
@@ -0,0 +1,91 @@
1
+ /* global ol */
2
+ 'use strict';
3
+
4
+ class WMTSWidget extends MapWidget {
5
+
6
+ /**
7
+ * Overrides MapWiget.createMap() that is called by
8
+ * MapWidget itself and stores the map in this.map
9
+ * @returns ol.Map instance
10
+ */
11
+ createMap() {
12
+ this.map_extent = this.options.extent;
13
+ this.projection = new ol.proj.Projection({
14
+ code: `EPSG:${this.options.map_srid}`,
15
+ extent: this.map_extent,
16
+ });
17
+ return new ol.Map({
18
+ target: this.options.map_id,
19
+ layers: [this.options.base_layer],
20
+ view: new ol.View({
21
+ center: this.options.default_center,
22
+ resolution: this.options.default_resolution,
23
+ projection: this.projection,
24
+ resolutions: this.options.resolutions,
25
+ constrainResolution: true
26
+ })
27
+ });
28
+ }
29
+
30
+ defaultCenter() {
31
+ return this.options.default_center;
32
+ }
33
+
34
+ search(searchterm) {
35
+ let debounceTimeout;
36
+ const query = searchterm.trim();
37
+
38
+ clearTimeout(debounceTimeout);
39
+ if (query.length < 3) {
40
+ this.clearResults()
41
+ return;
42
+ }
43
+
44
+ debounceTimeout = setTimeout(() => {
45
+ const url = this.options.search_url.replace('{search_term}', encodeURIComponent(query));
46
+
47
+ fetch(url)
48
+ .then(response => response.json())
49
+ .then(data => {
50
+ this.clearResults();
51
+ if (data && data.features) {
52
+ data.features.forEach(feature => {
53
+ const label = feature.properties.label;
54
+ const coords = feature.geometry.coordinates;
55
+ const div = document.createElement("div");
56
+ div.textContent = label;
57
+ div.addEventListener("click", () => {
58
+ this.clearResults();
59
+ this.inputSearchElement.value = label;
60
+ this.map.getView().fit(feature.bbox, {padding: [50, 50, 50, 50]})
61
+ });
62
+ this.divSearchResults.appendChild(div);
63
+ this.divSearchResults.classList.remove("ext-ol-hidden");
64
+ });
65
+ }
66
+ })
67
+ .catch(error => {
68
+ console.error("Search error!", error);
69
+ console.error(`Something went wrong parsing the response of ${url}`);
70
+ });
71
+ }, 300);
72
+ }
73
+
74
+ clearResults() {
75
+ this.divSearchResults.innerHTML = "";
76
+ this.divSearchResults.classList.add("ext-ol-hidden");
77
+ }
78
+
79
+ createInteractions() {
80
+ super.createInteractions();
81
+ document.addEventListener("DOMContentLoaded", () => {
82
+ document.querySelectorAll('.ext-ol-search-widget').forEach((divElement) => {
83
+ this.inputSearchElement = divElement.querySelector('input');
84
+ this.divSearchResults = divElement.querySelector('div.ext-ol-autocomplete-results');
85
+ this.inputSearchElement.addEventListener("input", () => this.search(this.inputSearchElement.value));
86
+ });
87
+ });
88
+ }
89
+ }
90
+
91
+
@@ -6,6 +6,12 @@
6
6
 
7
7
  <div id="{{ id }}_div_map" class="dj_map_wrapper">
8
8
  <div id="{{ id }}_map" class="dj_map"></div>
9
+ {% if search_url %}
10
+ <div id="{{ id }}_input_search" class="ext-ol-search-widget">
11
+ <input type="text" class="vTextField ext-ol-search" name="search">
12
+ <div class="ext-ol-autocomplete-results ext-ol-hidden"></div>
13
+ </div>
14
+ {% endif %}
9
15
  {% if not disabled %}<span class="clear_features"><a href="">{% translate "Delete all Features" %}</a></span>{% endif %}
10
16
  {% if display_raw %}<p>{% translate "Debugging window (serialized value)" %}</p>{% endif %}
11
17
  <textarea id="{{ id }}" class="vSerializedField required" cols="150" rows="10" name="{{ name }}"
@@ -52,6 +58,8 @@ const WMTSOptions = {
52
58
  options.base_layer = new ol.layer.Tile({
53
59
  source: new ol.source.WMTS(WMTSOptions),
54
60
  });
61
+
62
+ options.search_url = '{{ search_url|safe }}';
55
63
  {% endblock %}
56
64
 
57
65
  var {{ module }} = new WMTSWidget(options);
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: django-extended-ol
3
- Version: 1.0.0
3
+ Version: 1.1.1
4
4
  Summary: An openlayers widget for Django with extended capabilities
5
- Author-email: SITN <sitn@ne.ch>
5
+ Author-email: SITN <sitn@ne.ch>, maltaesousa <stephane.maltaesousa@ne.ch>
6
6
  Project-URL: Homepage, https://github.com/sitn/django-extended-ol
7
7
  Project-URL: Issues, https://github.com/sitn/django-extended-ol/issues
8
8
  Classifier: Environment :: Web Environment
@@ -23,6 +23,7 @@ Requires-Python: >=3.10
23
23
  Description-Content-Type: text/markdown
24
24
  License-File: LICENSE
25
25
  Requires-Dist: Django>=5.0
26
+ Dynamic: license-file
26
27
 
27
28
  # django-extended-ol
28
29
 
@@ -31,6 +32,7 @@ django-extended-ol is a Django app that extends the basic OpenLayers Widget.
31
32
  Features:
32
33
 
33
34
  * Custom WMTS base_layer with fixed resolutions
35
+ * Search on the map (third-party service needed)
34
36
 
35
37
  ## Quick start
36
38
 
@@ -67,11 +69,14 @@ OLWIDGET = {
67
69
  "url_template": 'https://sitn.ne.ch/mapproxy95/wmts/1.0.0/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png',
68
70
  "request_encoding": 'REST', # optional
69
71
  "format": 'image/png' # optional
72
+ },
73
+ "search": { # optional, only if you want a search service
74
+ "url_template": 'https://sitn.ne.ch/search?limit=10&partitionlimit=2&interface=desktop&query={search_term}'
70
75
  }
71
76
  }
72
77
  ```
73
78
 
74
- 3. You can now use WMTSWidget in your gis forms:
79
+ 3. You can now use `WMTSWidget` in your gis forms:
75
80
 
76
81
  ```python
77
82
  from django_extended_ol.forms.widgets import WMTSWidget
@@ -80,6 +85,8 @@ class MyCustomGISClass:
80
85
  gis_widget = WMTSWidget
81
86
  ```
82
87
 
88
+ If you want a search widget, you can use `WMTSWithSearchWidget`. Please check search service specification below.
89
+
83
90
  4. You can also use it in your admin.py:
84
91
 
85
92
  ```python
@@ -90,11 +97,12 @@ class MyCustomGISClass:
90
97
  admin.site.register(YourGeomModel, WMTSGISModelAdmin)
91
98
  ```
92
99
 
100
+ If you want the search widget please use `WMTSGISWithSearchModelAdmin`. Please check search service specification below.
101
+
93
102
  5. Start the development server and visit the admin.
94
103
 
95
104
 
96
- # Build this package
105
+ ## Search service specification
97
106
 
98
- ```sh
99
- py -m build
100
- ```
107
+ You'll need a templated URL as showcased in the `settings.py` above.
108
+ Such service should reply GeoJSON feature collection and each feature should have a `bbox` and a property named `label`.
@@ -13,5 +13,6 @@ django_extended_ol.egg-info/requires.txt
13
13
  django_extended_ol.egg-info/top_level.txt
14
14
  django_extended_ol/forms/__init__.py
15
15
  django_extended_ol/forms/widgets.py
16
+ django_extended_ol/static/olwidget/css/WMTSWidget.css
16
17
  django_extended_ol/static/olwidget/js/WMTSWidget.js
17
18
  django_extended_ol/templates/gis/openlayers-wmts.html
@@ -4,9 +4,10 @@ build-backend = 'setuptools.build_meta'
4
4
 
5
5
  [project]
6
6
  name = "django-extended-ol"
7
- version = "1.0.0"
7
+ version = "1.1.1"
8
8
  authors = [
9
9
  { name="SITN", email="sitn@ne.ch" },
10
+ { name="maltaesousa", email="stephane.maltaesousa@ne.ch" },
10
11
  ]
11
12
  description = "An openlayers widget for Django with extended capabilities"
12
13
  readme = "README.md"
@@ -1,6 +0,0 @@
1
- from django.contrib.gis.admin import GISModelAdmin
2
- from .forms.widgets import WMTSWidget
3
-
4
-
5
- class WMTSGISModelAdmin(GISModelAdmin):
6
- gis_widget = WMTSWidget
@@ -1,27 +0,0 @@
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
- }