Skip to content

Commit

Permalink
修改编辑示例问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Feb 29, 2024
1 parent 52dc20a commit affe702
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
13 changes: 10 additions & 3 deletions examples/leaflet/drawAndEditFeatures.html
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,24 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>

// 切换状态
document.querySelector('#addFeature').addEventListener('click', function() {
console.log(isChanged);
if (isChanged) {
document.querySelector('.message').style.display = 'block';
var message = document.querySelector('.message');
message.style.display = 'block';
setTimeout(() => {
message.style.display = 'none';
}, 3000);
document.querySelector('.add-tips').style.display = 'inline-block';
return;
}
switchPanel('add');
});
document.querySelector('#editFeature').addEventListener('click', function() {
if (isChanged) {
document.querySelector('.message').style.display = 'block';
var message = document.querySelector('.message');
message.style.display = 'block';
setTimeout(() => {
message.style.display = 'none';
}, 3000);
document.querySelector('.add-tips').style.display = 'inline-block';
return;
}
Expand Down
23 changes: 15 additions & 8 deletions examples/mapboxgl/drawAndEditFeatures.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<head>
<meta charset="UTF-8" />
<title data-i18n="resources.title_editFeatures"></title>
<script type="text/javascript" include="draw,snap" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<script type="text/javascript" include="draw,snap,lodash" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<style>
.key-input,
.value-input {
Expand Down Expand Up @@ -140,9 +140,10 @@
margin-bottom: 10px;
}
.info-bottom {
margin-top: 20px;
height: 55px;
float: right;
position: absolute;
right: 20px;
margin-top: 40px;
bottom: 10px;
}
.edit-tips {
width: 300px;
Expand Down Expand Up @@ -976,11 +977,17 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
});
editFeaturesService.editFeatures(addFeatureParams, function (serviceResult) {
if (serviceResult.result.succeed) {
var addFeature = draw.getAll().features[0];
if (addFeature) {
if(addFeatureId) {
draw.delete(addFeatureId);
var addFeature = _.cloneDeep(currentFeature.data);
addFeature.properties.datasetName = currentDataset;
addFeature.properties.id = currentFeature.data.id;
draw.add(addFeature);
var source = map.getSource(currentDataset);
var features = source._data.features;
features.push(addFeature);
source.setData({
type: 'FeatureCollection',
features: features
});
}
widgets.alert.showAlert(isUpdate ? '更新要素成功' : '新增要素成功', true, 240);
}
Expand Down
14 changes: 13 additions & 1 deletion examples/maplibregl/drawAndEditFeatures.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<head>
<meta charset="UTF-8" />
<title data-i18n="resources.title_editFeatures"></title>
<script type="text/javascript" include="draw,snap" src="../../dist/maplibregl/include-maplibregl.js"></script>
<script type="text/javascript" include="draw,snap,lodash" src="../../dist/maplibregl/include-maplibregl.js"></script>
<style>
.key-input,
.value-input {
Expand Down Expand Up @@ -976,6 +976,18 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
});
editFeaturesService.editFeatures(addFeatureParams, function (serviceResult) {
if (serviceResult.result.succeed) {
if(addFeatureId) {
draw.delete(addFeatureId);
var addFeature = _.cloneDeep(currentFeature.data);
addFeature.properties.datasetName = currentDataset;
var source = map.getSource(currentDataset);
var features = source._data.features;
features.push(addFeature);
source.setData({
type: 'FeatureCollection',
features: features
});
}
widgets.alert.showAlert(isUpdate ? '更新要素成功' : '新增要素成功', true);
}
});
Expand Down
10 changes: 7 additions & 3 deletions examples/openlayers/drawAndEditFeatures.html
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
var container = document.getElementById('popup');
var content = document.getElementById('popup-content');
var isChanged = false;
var currentAddFeature = null;
getDomains(currentDataset);
var overlayPopup = new ol.Overlay({
element: container,
Expand Down Expand Up @@ -869,6 +870,7 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
});
console.log('properties', properties);
currentFeature.data.properties = properties;
currentAddFeature.setProperties(properties);
var olFeature = new ol.format.GeoJSON().readFeature(currentFeature.data);
if (!olFeature.getId()) {
datasetInfoList[currentDataset].uniqueId++;
Expand Down Expand Up @@ -935,6 +937,8 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
});
editFeaturesService.editFeatures(addFeatureParams, function (serviceResult) {
if (serviceResult.result.succeed) {
// currentSource.removeFeature(currentAddFeature);
// currentSource.addFeature(currentFeature.origin);
widgets.alert.showAlert(isUpdate ? '更新要素成功' : '新增要素成功', true);
}
});
Expand Down Expand Up @@ -970,8 +974,6 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
function startSelect(multi = false) {
clearInteraction();
select = new ol.interaction.Select({
wrapX: false,
multi: true,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: [90, 90, 90, 0.9]
Expand All @@ -991,7 +993,8 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
select.on('select', function (e) {
isChanged = true;
var feature = e.selected[0];
if (feature) {
isModifyFeature = feature && feature.getProperties().features && feature.getProperties().geometries;
if (feature && !isModifyFeature) {
if (status == 'DELETE') {
var props = new ol.format.GeoJSON().writeFeature(feature);
props = JSON.parse(props);
Expand Down Expand Up @@ -1076,6 +1079,7 @@ <h5><span data-i18n="resources.text_featureToDelete"></span>:</h5>
});
draw.on('drawend', function(e) {
if (e.feature) {
currentAddFeature = e.feature;
map.removeOverlay(overlayPopup);
var props = new ol.format.GeoJSON().writeFeature(e.feature);
props = JSON.parse(props);
Expand Down

0 comments on commit affe702

Please sign in to comment.