Skip to content

Commit affe702

Browse files
committed
修改编辑示例问题
1 parent 52dc20a commit affe702

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

examples/leaflet/drawAndEditFeatures.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,17 +648,24 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
648648

649649
// 切换状态
650650
document.querySelector('#addFeature').addEventListener('click', function() {
651-
console.log(isChanged);
652651
if (isChanged) {
653-
document.querySelector('.message').style.display = 'block';
652+
var message = document.querySelector('.message');
653+
message.style.display = 'block';
654+
setTimeout(() => {
655+
message.style.display = 'none';
656+
}, 3000);
654657
document.querySelector('.add-tips').style.display = 'inline-block';
655658
return;
656659
}
657660
switchPanel('add');
658661
});
659662
document.querySelector('#editFeature').addEventListener('click', function() {
660663
if (isChanged) {
661-
document.querySelector('.message').style.display = 'block';
664+
var message = document.querySelector('.message');
665+
message.style.display = 'block';
666+
setTimeout(() => {
667+
message.style.display = 'none';
668+
}, 3000);
662669
document.querySelector('.add-tips').style.display = 'inline-block';
663670
return;
664671
}

examples/mapboxgl/drawAndEditFeatures.html

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<head>
77
<meta charset="UTF-8" />
88
<title data-i18n="resources.title_editFeatures"></title>
9-
<script type="text/javascript" include="draw,snap" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
9+
<script type="text/javascript" include="draw,snap,lodash" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
1010
<style>
1111
.key-input,
1212
.value-input {
@@ -140,9 +140,10 @@
140140
margin-bottom: 10px;
141141
}
142142
.info-bottom {
143-
margin-top: 20px;
144-
height: 55px;
145-
float: right;
143+
position: absolute;
144+
right: 20px;
145+
margin-top: 40px;
146+
bottom: 10px;
146147
}
147148
.edit-tips {
148149
width: 300px;
@@ -976,11 +977,17 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
976977
});
977978
editFeaturesService.editFeatures(addFeatureParams, function (serviceResult) {
978979
if (serviceResult.result.succeed) {
979-
var addFeature = draw.getAll().features[0];
980-
if (addFeature) {
980+
if(addFeatureId) {
981+
draw.delete(addFeatureId);
982+
var addFeature = _.cloneDeep(currentFeature.data);
981983
addFeature.properties.datasetName = currentDataset;
982-
addFeature.properties.id = currentFeature.data.id;
983-
draw.add(addFeature);
984+
var source = map.getSource(currentDataset);
985+
var features = source._data.features;
986+
features.push(addFeature);
987+
source.setData({
988+
type: 'FeatureCollection',
989+
features: features
990+
});
984991
}
985992
widgets.alert.showAlert(isUpdate ? '更新要素成功' : '新增要素成功', true, 240);
986993
}

examples/maplibregl/drawAndEditFeatures.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<head>
77
<meta charset="UTF-8" />
88
<title data-i18n="resources.title_editFeatures"></title>
9-
<script type="text/javascript" include="draw,snap" src="../../dist/maplibregl/include-maplibregl.js"></script>
9+
<script type="text/javascript" include="draw,snap,lodash" src="../../dist/maplibregl/include-maplibregl.js"></script>
1010
<style>
1111
.key-input,
1212
.value-input {
@@ -976,6 +976,18 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
976976
});
977977
editFeaturesService.editFeatures(addFeatureParams, function (serviceResult) {
978978
if (serviceResult.result.succeed) {
979+
if(addFeatureId) {
980+
draw.delete(addFeatureId);
981+
var addFeature = _.cloneDeep(currentFeature.data);
982+
addFeature.properties.datasetName = currentDataset;
983+
var source = map.getSource(currentDataset);
984+
var features = source._data.features;
985+
features.push(addFeature);
986+
source.setData({
987+
type: 'FeatureCollection',
988+
features: features
989+
});
990+
}
979991
widgets.alert.showAlert(isUpdate ? '更新要素成功' : '新增要素成功', true);
980992
}
981993
});

examples/openlayers/drawAndEditFeatures.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
351351
var container = document.getElementById('popup');
352352
var content = document.getElementById('popup-content');
353353
var isChanged = false;
354+
var currentAddFeature = null;
354355
getDomains(currentDataset);
355356
var overlayPopup = new ol.Overlay({
356357
element: container,
@@ -869,6 +870,7 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
869870
});
870871
console.log('properties', properties);
871872
currentFeature.data.properties = properties;
873+
currentAddFeature.setProperties(properties);
872874
var olFeature = new ol.format.GeoJSON().readFeature(currentFeature.data);
873875
if (!olFeature.getId()) {
874876
datasetInfoList[currentDataset].uniqueId++;
@@ -935,6 +937,8 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
935937
});
936938
editFeaturesService.editFeatures(addFeatureParams, function (serviceResult) {
937939
if (serviceResult.result.succeed) {
940+
// currentSource.removeFeature(currentAddFeature);
941+
// currentSource.addFeature(currentFeature.origin);
938942
widgets.alert.showAlert(isUpdate ? '更新要素成功' : '新增要素成功', true);
939943
}
940944
});
@@ -970,8 +974,6 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
970974
function startSelect(multi = false) {
971975
clearInteraction();
972976
select = new ol.interaction.Select({
973-
wrapX: false,
974-
multi: true,
975977
style: new ol.style.Style({
976978
fill: new ol.style.Fill({
977979
color: [90, 90, 90, 0.9]
@@ -991,7 +993,8 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
991993
select.on('select', function (e) {
992994
isChanged = true;
993995
var feature = e.selected[0];
994-
if (feature) {
996+
isModifyFeature = feature && feature.getProperties().features && feature.getProperties().geometries;
997+
if (feature && !isModifyFeature) {
995998
if (status == 'DELETE') {
996999
var props = new ol.format.GeoJSON().writeFeature(feature);
9971000
props = JSON.parse(props);
@@ -1076,6 +1079,7 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
10761079
});
10771080
draw.on('drawend', function(e) {
10781081
if (e.feature) {
1082+
currentAddFeature = e.feature;
10791083
map.removeOverlay(overlayPopup);
10801084
var props = new ol.format.GeoJSON().writeFeature(e.feature);
10811085
props = JSON.parse(props);

0 commit comments

Comments
 (0)