-
Notifications
You must be signed in to change notification settings - Fork 27
/
SpatialOperatorDifference.js
104 lines (93 loc) · 3.09 KB
/
SpatialOperatorDifference.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Copyright (c) 2018-present terrestris GmbH & Co. KG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Spatial Operator Difference Button
*
* @class BasiGX.view.button.SpatialOperatorDifference
*/
Ext.define('BasiGX.view.button.SpatialOperatorDifference', {
extend: 'BasiGX.view.button.SpatialOperatorBase',
xtype: 'basigx-button-spatial-operator-difference',
requires: [
'BasiGX.util.Geometry'
],
/**
*
*/
viewModel: {
data: {
tooltip: 'Difference on geometries',
text: 'Difference on geometries'
}
},
/**
*
*/
bind: {
text: '{text}'
},
config: {
targetVectorLayer: null,
/**
* the number of features which are allowed to process together.
* Union may use a high number without problems,
* intersect will be restricted to 2
*/
maxAllowedFeaturesForOperation: 2,
showSelectMasterSlaveFeatureDialog: true
},
handler: function() {
// effectively disable the toggle functionality, behaves like
// `enableToggle: false` but keeps the ability to be part
// of a `toggleGroup`
this.setPressed(false);
},
/**
* Difference function which is given 2 geometries
*
* @param {Array} featureArray The array holding the features to handle
* @return {ol.Feature} The final feature
*/
processSelectedGeometries: function(featureArray) {
if (!jsts) {
Ext.log.error('No jsts could be found, check your application ' +
'resources and make sure to include the jsts library');
return;
}
var parser = new jsts.io.OL3Parser();
var parsedGeometries = [];
var differenceGeom;
var newFeature = null;
Ext.each(featureArray, function(feat) {
parsedGeometries.push(parser.read(feat.getGeometry()));
});
for (var i = 0; i < parsedGeometries.length; i++) {
if (i === 0) {
differenceGeom = parsedGeometries[i];
} else {
differenceGeom = differenceGeom.difference(
parsedGeometries[i]);
}
}
if (!differenceGeom.isValid() || differenceGeom.isEmpty() ||
differenceGeom.getArea() === 0) {
return false;
}
var result = parser.write(differenceGeom);
newFeature = new ol.Feature({geometry: result});
return newFeature;
}
});