Переключение режимов
This commit is contained in:
parent
43f80f2e3a
commit
208973f8a6
@ -110,8 +110,21 @@
|
||||
<div class="card-body p-0">
|
||||
<div id="map"></div>
|
||||
</div>
|
||||
<div class="card-footer d-flex" style="gap: 30px">
|
||||
<button id="exportGeoJSON" class="btn btn-info">Экспортировать GeoJSON</button>
|
||||
<div class="card-footer " style="gap: 30px">
|
||||
<div class="custom-control custom-radio">
|
||||
<input class="custom-control-input" type="radio" id="modeChangeRadio2"
|
||||
name="modeChangeRadio" checked="" value="crop">
|
||||
<label for="modeChangeRadio2" class="custom-control-label">Режим обрезки</label>
|
||||
</div>
|
||||
<div class="custom-control custom-radio">
|
||||
<input class="custom-control-input" type="radio" id="modeChangeRadio1"
|
||||
name="modeChangeRadio" value="scaling">
|
||||
<label for="modeChangeRadio1" class="custom-control-label">Режим
|
||||
масштабирования</label>
|
||||
</div>
|
||||
<button id="exportGeoJSON" class="btn btn-info float-right d-none">
|
||||
Экспортировать GeoJSON
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -135,6 +148,34 @@
|
||||
<script src="{% static 'js/ol/layersStyles.js' %}?ver={% settings_value 'APP_VER' %}"></script>
|
||||
<script src="{% static 'js/ol/proj4js.js' %}?ver={% settings_value 'APP_VER' %}"></script>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
function setSelectionToGroup() {
|
||||
transformInteraction.setSelection(group);
|
||||
}
|
||||
|
||||
let previousChoice;
|
||||
|
||||
document.querySelectorAll('input[type="radio"][name="modeChangeRadio"]').forEach((button) => {
|
||||
button.addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
if (this.value === "crop") {
|
||||
map.un("pointermove", setSelectionToGroup)
|
||||
map.removeInteraction(transformInteraction)
|
||||
|
||||
} else if (this.value === "scaling") {
|
||||
// Добавляем возможность масштабирования и перемещения с помощью маркеров
|
||||
map.addInteraction(transformInteraction);
|
||||
|
||||
// Обновляем выделение при перемещении мыши
|
||||
map.on('pointermove', setSelectionToGroup);
|
||||
}
|
||||
previousChoice = this.value;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
function rgbToHex(rgb) {
|
||||
var hexRegex = /^#[0-9A-Fa-f]{6}$/; // Регулярное выражение для HEX формата
|
||||
@ -188,11 +229,14 @@
|
||||
let i = 0
|
||||
const scanLayerExists = Boolean(parseInt('{{ scan_layer_enable }}'))
|
||||
let vectorSource = {}
|
||||
let vectorLayer = {}
|
||||
let group = {}
|
||||
layers = [
|
||||
new ol.layer.Tile({
|
||||
source: new ol.source.OSM()
|
||||
}),
|
||||
]
|
||||
|
||||
if (scanLayerExists) {
|
||||
scanLayer = new ol.layer.Tile({
|
||||
source: new ol.source.XYZ({
|
||||
@ -233,14 +277,10 @@
|
||||
});
|
||||
{#translateInteraction = new ol.interaction.Translate({});#}
|
||||
{#map.addInteraction(translateInteraction);#}
|
||||
|
||||
// Добавляем возможность масштабирования и перемещения с помощью маркеров
|
||||
transformInteraction = new ol.interaction.Transform({
|
||||
addCondition: ol.events.condition.shiftKeyOnly,
|
||||
translateFeature: false
|
||||
});
|
||||
map.addInteraction(transformInteraction);
|
||||
let vectorLayer;
|
||||
|
||||
// Дефолтные значения стиля
|
||||
const DEFAULT_STYLE = {
|
||||
@ -528,13 +568,8 @@
|
||||
|
||||
// Настройка transformInteraction для редактирования
|
||||
const features = vectorSource.getFeatures();
|
||||
const group = new ol.Collection(features);
|
||||
transformInteraction.setSelection(group);
|
||||
group = new ol.Collection(features);
|
||||
|
||||
// Обновляем выделение при перемещении мыши
|
||||
map.on('pointermove', () => {
|
||||
transformInteraction.setSelection(group);
|
||||
});
|
||||
const extent = vectorSource.getExtent();
|
||||
if (!ol.extent.isEmpty(extent)) {
|
||||
map.getView().fit(extent, {padding: [20, 20, 20, 20]});
|
||||
@ -568,12 +603,7 @@
|
||||
map.addLayer(vectorLayer);
|
||||
|
||||
const features = vectorSource.getFeatures();
|
||||
const group = new ol.Collection(features);
|
||||
transformInteraction.setSelection(group);
|
||||
|
||||
map.on('pointermove', () => {
|
||||
transformInteraction.setSelection(group);
|
||||
});
|
||||
group = new ol.Collection(features);
|
||||
|
||||
const extent = vectorSource.getExtent();
|
||||
if (!ol.extent.isEmpty(extent)) {
|
||||
@ -662,7 +692,6 @@
|
||||
vectorLayer = null;
|
||||
}
|
||||
const emptyGroup = new ol.Collection();
|
||||
transformInteraction.setSelection(emptyGroup)
|
||||
}
|
||||
|
||||
// Если редактирование слоя
|
||||
@ -692,4 +721,5 @@
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
Loading…
x
Reference in New Issue
Block a user