mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Upgraded OpenLayers to v.7.2.2.
This commit is contained in:
parent
279967ec85
commit
1833eb3f3e
@ -102,12 +102,12 @@ class OpenLayersWidget(BaseGeometryWidget):
|
|||||||
class Media:
|
class Media:
|
||||||
css = {
|
css = {
|
||||||
"all": (
|
"all": (
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/ol3/4.6.5/ol.css",
|
"https://cdn.jsdelivr.net/npm/ol@v7.2.2/ol.css",
|
||||||
"gis/css/ol3.css",
|
"gis/css/ol3.css",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
js = (
|
js = (
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/ol3/4.6.5/ol.js",
|
"https://cdn.jsdelivr.net/npm/ol@v7.2.2/dist/ol.js",
|
||||||
"gis/js/OLMapWidget.js",
|
"gis/js/OLMapWidget.js",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,39 +1,40 @@
|
|||||||
/* global ol */
|
/* global ol */
|
||||||
'use strict';
|
'use strict';
|
||||||
function GeometryTypeControl(opt_options) {
|
class GeometryTypeControl extends ol.control.Control {
|
||||||
// Map control to switch type when geometry type is unknown
|
// Map control to switch type when geometry type is unknown
|
||||||
const options = opt_options || {};
|
constructor(opt_options) {
|
||||||
|
const options = opt_options || {};
|
||||||
|
|
||||||
const element = document.createElement('div');
|
const element = document.createElement('div');
|
||||||
element.className = 'switch-type type-' + options.type + ' ol-control ol-unselectable';
|
element.className = 'switch-type type-' + options.type + ' ol-control ol-unselectable';
|
||||||
if (options.active) {
|
if (options.active) {
|
||||||
element.classList.add("type-active");
|
|
||||||
}
|
|
||||||
|
|
||||||
const self = this;
|
|
||||||
const switchType = function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (options.widget.currentGeometryType !== self) {
|
|
||||||
options.widget.map.removeInteraction(options.widget.interactions.draw);
|
|
||||||
options.widget.interactions.draw = new ol.interaction.Draw({
|
|
||||||
features: options.widget.featureCollection,
|
|
||||||
type: options.type
|
|
||||||
});
|
|
||||||
options.widget.map.addInteraction(options.widget.interactions.draw);
|
|
||||||
options.widget.currentGeometryType.element.classList.remove('type-active');
|
|
||||||
options.widget.currentGeometryType = self;
|
|
||||||
element.classList.add("type-active");
|
element.classList.add("type-active");
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
element.addEventListener('click', switchType, false);
|
super({
|
||||||
element.addEventListener('touchstart', switchType, false);
|
element: element,
|
||||||
|
target: options.target
|
||||||
|
});
|
||||||
|
const self = this;
|
||||||
|
const switchType = function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (options.widget.currentGeometryType !== self) {
|
||||||
|
options.widget.map.removeInteraction(options.widget.interactions.draw);
|
||||||
|
options.widget.interactions.draw = new ol.interaction.Draw({
|
||||||
|
features: options.widget.featureCollection,
|
||||||
|
type: options.type
|
||||||
|
});
|
||||||
|
options.widget.map.addInteraction(options.widget.interactions.draw);
|
||||||
|
options.widget.currentGeometryType.element.classList.remove('type-active');
|
||||||
|
options.widget.currentGeometryType = self;
|
||||||
|
element.classList.add("type-active");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ol.control.Control.call(this, {
|
element.addEventListener('click', switchType, false);
|
||||||
element: element
|
element.addEventListener('touchstart', switchType, false);
|
||||||
});
|
}
|
||||||
};
|
}
|
||||||
ol.inherits(GeometryTypeControl, ol.control.Control);
|
|
||||||
|
|
||||||
// TODO: allow deleting individual features (#8972)
|
// TODO: allow deleting individual features (#8972)
|
||||||
class MapWidget {
|
class MapWidget {
|
||||||
|
@ -149,6 +149,9 @@ Minor features
|
|||||||
removes the former ``map_css`` block) to better comply with a strict Content
|
removes the former ``map_css`` block) to better comply with a strict Content
|
||||||
Security Policy.
|
Security Policy.
|
||||||
|
|
||||||
|
* :class:`~django.contrib.gis.forms.widgets.OpenLayersWidget` is now based on
|
||||||
|
OpenLayers 7.2.2 (previously 4.6.5).
|
||||||
|
|
||||||
:mod:`django.contrib.messages`
|
:mod:`django.contrib.messages`
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ QUnit.test('MapWidget.defaultCenter', function(assert) {
|
|||||||
'6.81,47.08',
|
'6.81,47.08',
|
||||||
'Default center at 6.81, 47.08'
|
'Default center at 6.81, 47.08'
|
||||||
);
|
);
|
||||||
assert.equal(widget.map.getView().getZoom(), 17);
|
assert.equal(Math.round(widget.map.getView().getZoom()), 17);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('MapWidget.interactions', function(assert) {
|
QUnit.test('MapWidget.interactions', function(assert) {
|
||||||
|
@ -157,7 +157,7 @@
|
|||||||
<textarea id="id_multipolygon" name="multipolygon" class="vSerializedField required"
|
<textarea id="id_multipolygon" name="multipolygon" class="vSerializedField required"
|
||||||
style="display:none;" rows="10" cols="150"></textarea>
|
style="display:none;" rows="10" cols="150"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<script src='https://cdnjs.cloudflare.com/ajax/libs/ol3/4.6.5/ol.js'></script>
|
<script src='https://cdn.jsdelivr.net/npm/ol@v7.2.2/dist/ol.js'></script>
|
||||||
<script src='../django/contrib/gis/static/gis/js/OLMapWidget.js' data-cover></script>
|
<script src='../django/contrib/gis/static/gis/js/OLMapWidget.js' data-cover></script>
|
||||||
<script src='./gis/mapwidget.test.js'></script>
|
<script src='./gis/mapwidget.test.js'></script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user