geojs 1.10.7 → 1.10.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geojs",
3
- "version": "1.10.7",
3
+ "version": "1.10.8",
4
4
  "description": "JavaScript Geo Visualization and Analysis Library",
5
5
  "homepage": "https://github.com/OpenGeoscience/geojs",
6
6
  "license": "Apache-2.0",
@@ -72,7 +72,8 @@ var polygonAnnotation = function (args) {
72
72
  annotation.call(this, 'polygon', args);
73
73
 
74
74
  var m_this = this,
75
- s_actions = this.actions;
75
+ s_actions = this.actions,
76
+ s_state = this.state;
76
77
 
77
78
  /**
78
79
  * Get a list of renderable features for this annotation. When the polygon
@@ -245,6 +246,46 @@ var polygonAnnotation = function (args) {
245
246
  return continuousVerticesActions(m_this, s_actions, state, 'polygon', arguments);
246
247
  };
247
248
 
249
+ /**
250
+ * Get or set the state of this annotation.
251
+ *
252
+ * @param {string|undefined} [arg] If `undefined`, return the state,
253
+ * otherwise change it. This should be one of the
254
+ * {@link geo.annotation.state} values.
255
+ * @returns {this|string} The current state or this annotation.
256
+ * @fires geo.event.annotation.state
257
+ */
258
+ this.state = function (arg) {
259
+ const oldState = s_state();
260
+ if (arg && arg !== oldState && ((oldState === annotationState.create || oldState === annotationState.edit) && arg === annotationState.done)) {
261
+ /* Uncross polygons when they are complete. */
262
+ const opts = {style: 'object-listlist-outer-list'};
263
+ const polys = util.polyops.union(m_this.options('vertices'), [], opts);
264
+ let merged = true;
265
+ while (polys.length > 1 && merged) {
266
+ merged = false;
267
+ for (let i = 0; !merged && i < polys[0].outer.length; i += 1) {
268
+ const pt1 = polys[0].outer[i];
269
+ for (let p = 1; !merged && p < polys.length; p += 1) {
270
+ for (let j = 0; !merged && j < polys[p].outer.length; j += 1) {
271
+ const pt2 = polys[p].outer[j];
272
+ if (pt1.x === pt2.x && pt1.y === pt2.y) {
273
+ polys[0].inner = polys[0].inner.concat(polys[p].inner);
274
+ polys[0].outer = polys[0].outer.slice(0, i).concat(polys[p].outer.slice(j)).concat(polys[p].outer.slice(0, j)).concat(polys[0].outer.slice(i));
275
+ polys.splice(p, 1);
276
+ merged = true;
277
+ }
278
+ }
279
+ }
280
+ }
281
+ }
282
+ if (polys.length === 1) {
283
+ m_this.options('vertices', polys[0].inner.length ? polys[0] : polys[0].outer);
284
+ }
285
+ }
286
+ return s_state(arg);
287
+ };
288
+
248
289
  /**
249
290
  * Process any actions for this annotation.
250
291
  *