geojs 1.8.10 → 1.9.2

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.8.10",
3
+ "version": "1.9.2",
4
4
  "description": "JavaScript Geo Visualization and Analysis Library",
5
5
  "homepage": "https://github.com/OpenGeoscience/geojs",
6
6
  "license": "Apache-2.0",
@@ -21,6 +21,7 @@
21
21
  "jquery": "^3.6.0",
22
22
  "kdbush": "^3.0.0",
23
23
  "mousetrap": "^1.6.5",
24
+ "polybooljs": "git+https://github.com/manubb/polybooljs#eps-logic",
24
25
  "proj4": "^2.7.5",
25
26
  "vgl": "0.3.11"
26
27
  },
@@ -48,19 +49,19 @@
48
49
  "eslint-plugin-import": "^2.25.3",
49
50
  "eslint-plugin-node": "^11.1.0",
50
51
  "eslint-plugin-promise": "^5.0.0",
51
- "expose-loader": "^3.1.0",
52
+ "expose-loader": "^4.0.0",
52
53
  "express": "^4.17.2",
53
54
  "fs-extra": "^10.0.0",
54
55
  "glob": "^8.0.1",
55
56
  "glslang-validator-prebuilt": "^0.0.7",
56
- "imports-loader": "^3.1.1",
57
+ "imports-loader": "^4.0.0",
57
58
  "jaguarjs-jsdoc": "^1.0.2",
58
59
  "jasmine-core": "^4.0.0",
59
60
  "js-yaml": "^4.1.0",
60
61
  "jsdoc": "^3.6.10",
61
62
  "jsdoc-autoprivate": "0.0.1",
62
63
  "jsonlint-mod": "^1.7.6",
63
- "jstransformer-markdown-it": "jstransformers/jstransformer-markdown-it#snyk-fix-9cae6682d6a0ba4f72fd9fec4e488acd",
64
+ "jstransformer-markdown-it": "git+https://github.com/jstransformers/jstransformer-markdown-it#snyk-fix-9cae6682d6a0ba4f72fd9fec4e488acd",
64
65
  "karma": "^6.3.15",
65
66
  "karma-chrome-launcher": "^3.1.0",
66
67
  "karma-coverage": "^2.1.1",
@@ -85,7 +86,7 @@
85
86
  "sinon": "^14.0.0",
86
87
  "style-loader": "^3.3.1",
87
88
  "stylus": "^0.57.0",
88
- "stylus-loader": "^6.2.0",
89
+ "stylus-loader": "^7.0.0",
89
90
  "terser-webpack-plugin": "^5.3.1",
90
91
  "touch-emulator": "^1.0.0",
91
92
  "typeface-lato": "^1.1.13",
@@ -74,6 +74,12 @@ var editHandleFeatureLevel = 3;
74
74
  * @property {boolean|string[]} [showLabel=true] `true` to show the annotation
75
75
  * label on annotations in done or edit states. Alternately, a list of
76
76
  * states in which to show the label. Falsy to not show the label.
77
+ * @property {boolean} [allowBooleanOperations] This defaults to `true` for
78
+ * annotations that have area and `false` for those without area (e.g.,
79
+ * false for lines and points). If it is truthy, then, when the annotation
80
+ * is being created, it checks the metakeys on the first click that defines
81
+ * a coordinate to determine what boolean polygon operation should be
82
+ * performaned on the completion of the annotation.
77
83
  */
78
84
 
79
85
  /**
@@ -94,7 +100,7 @@ var annotation = function (type, args) {
94
100
  }
95
101
 
96
102
  var m_this = this,
97
- m_options = $.extend({}, {showLabel: true}, args || {}),
103
+ m_options = $.extend(true, {}, this.constructor.defaults, args || {}),
98
104
  m_id = m_options.annotationId;
99
105
  delete m_options.annotationId;
100
106
  if (m_id === undefined || (m_options.layer && m_options.layer.annotationById(m_id))) {
@@ -797,10 +803,14 @@ var annotation = function (type, args) {
797
803
  key = styles[i];
798
804
  value = util.ensureFunction(objStyle[key])();
799
805
  if (value !== undefined) {
806
+ let defvalue = ((m_this.constructor.defaults || {}).style || {})[key];
800
807
  if (key.toLowerCase().match(/color$/)) {
801
808
  value = util.convertColorToHex(value, 'needed');
809
+ defvalue = defvalue !== undefined ? util.convertColorToHex(defvalue, 'needed') : defvalue;
810
+ }
811
+ if (value !== defvalue) {
812
+ obj.properties[key] = value;
802
813
  }
803
- obj.properties[key] = value;
804
814
  }
805
815
  }
806
816
  for (i = 0; i < textFeature.usedStyles.length; i += 1) {
@@ -1408,6 +1418,13 @@ function constrainAspectRatio(ratio) {
1408
1418
  return constraintFunction;
1409
1419
  }
1410
1420
 
1421
+ /**
1422
+ * This object contains the default options to initialize the class.
1423
+ */
1424
+ annotation.defaults = {
1425
+ showLabel: true
1426
+ };
1427
+
1411
1428
  module.exports = {
1412
1429
  state: annotationState,
1413
1430
  actionOwner: annotationActionOwner,
@@ -19,13 +19,20 @@ const ellipseAnnotation = require('./ellipseAnnotation');
19
19
  */
20
20
  var circleAnnotation = function (args, annotationName) {
21
21
  'use strict';
22
- args = $.extend({}, args, {constraint: 1});
23
22
  if (!(this instanceof circleAnnotation)) {
24
23
  return new circleAnnotation(args, annotationName);
25
24
  }
25
+ args = $.extend(true, {}, this.constructor.defaults, args, {constraint: 1});
26
26
  ellipseAnnotation.call(this, args, annotationName || 'circle');
27
27
  };
28
28
  inherit(circleAnnotation, ellipseAnnotation);
29
+
30
+ /**
31
+ * This object contains the default options to initialize the class.
32
+ */
33
+ circleAnnotation.defaults = $.extend({}, ellipseAnnotation.defaults, {
34
+ });
35
+
29
36
  var circleRequiredFeatures = {};
30
37
  circleRequiredFeatures[markerFeature.capabilities.feature] = true;
31
38
  registerAnnotation('circle', circleAnnotation, circleRequiredFeatures);
@@ -23,7 +23,7 @@ var ellipseAnnotation = function (args, annotationName) {
23
23
  if (!(this instanceof ellipseAnnotation)) {
24
24
  return new ellipseAnnotation(args, annotationName);
25
25
  }
26
-
26
+ args = $.extend(true, {}, this.constructor.defaults, args);
27
27
  rectangleAnnotation.call(this, args, annotationName || 'ellipse');
28
28
 
29
29
  var m_this = this;
@@ -70,9 +70,59 @@ var ellipseAnnotation = function (args, annotationName) {
70
70
  }
71
71
  return features;
72
72
  };
73
+
74
+ /**
75
+ * Return this annotation as a polygon list.
76
+ *
77
+ * @param {geo.util.polyop.spec} [opts] The ``tolerance`` and
78
+ * ``pixelTolerance`` parameters are used if set. Otherwise, a polygon is
79
+ * approximated to 1/10th of a pixel at the map's current maximum zoom
80
+ * level.
81
+ * @returns {geo.polygonList} A list of polygons.
82
+ */
83
+ this.toPolygonList = function (opts) {
84
+ const coord = m_this._coordinates();
85
+ if (coord.length < 3) {
86
+ return [];
87
+ }
88
+ let tolerance = (opts && opts.tolerance) || 0;
89
+ if (!tolerance) {
90
+ const map = m_this.layer().map();
91
+ if (opts && opts.pixelTolerance) {
92
+ tolerance = map.unitsPerPixel(map.zoom()) * opts.pixelTolerance;
93
+ } else {
94
+ tolerance = map.unitsPerPixel(map.zoomRange().max) * 0.1;
95
+ }
96
+ }
97
+ const w = ((coord[0].x - coord[1].x) ** 2 + (coord[0].y - coord[1].y) ** 2) ** 0.5;
98
+ const h = ((coord[0].x - coord[3].x) ** 2 + (coord[0].y - coord[3].y) ** 2) ** 0.5;
99
+ const cx = (coord[0].x + coord[2].x) / 2;
100
+ const cy = (coord[0].y + coord[2].y) / 2;
101
+ const radius = Math.max(w, h) / 2;
102
+ const rotation = -Math.atan2(coord[1].y - coord[0].y, coord[1].x - coord[0].x);
103
+ const sides = Math.max(12, Math.ceil(Math.PI / Math.acos((radius - tolerance) / (radius + tolerance))));
104
+ const a = w / 2 * (1 + (1 - Math.cos(Math.PI / sides)) / 2);
105
+ const b = h / 2 * (1 + (1 - Math.cos(Math.PI / sides)) / 2);
106
+ const poly = [];
107
+ const cosr = Math.cos(rotation), sinr = Math.sin(rotation);
108
+ for (let s = 0; s < sides; s += 1) {
109
+ const sa = Math.PI * 2 * s / sides;
110
+ const cosa = Math.cos(sa), sina = Math.sin(sa);
111
+ const x = cx + a * cosr * cosa - b * sinr * sina;
112
+ const y = cy + a * sinr * cosa + b * cosr * sina;
113
+ poly.push([x, y]);
114
+ }
115
+ return [[poly]];
116
+ };
73
117
  };
74
118
  inherit(ellipseAnnotation, rectangleAnnotation);
75
119
 
120
+ /**
121
+ * This object contains the default options to initialize the class.
122
+ */
123
+ ellipseAnnotation.defaults = $.extend({}, rectangleAnnotation.defaults, {
124
+ });
125
+
76
126
  var ellipseRequiredFeatures = {};
77
127
  ellipseRequiredFeatures[markerFeature.capabilities.feature] = true;
78
128
  registerAnnotation('ellipse', ellipseAnnotation, ellipseRequiredFeatures);
@@ -37,8 +37,7 @@ var lineAnnotation = function (args) {
37
37
  if (!(this instanceof lineAnnotation)) {
38
38
  return new lineAnnotation(args);
39
39
  }
40
-
41
- args = $.extend(true, {}, {
40
+ args = $.extend(true, {}, this.constructor.defaults, {
42
41
  style: {
43
42
  line: function (d) {
44
43
  /* Return an array that has the same number of items as we have
@@ -48,16 +47,7 @@ var lineAnnotation = function (args) {
48
47
  },
49
48
  position: function (d, i) {
50
49
  return m_this.options('vertices')[i];
51
- },
52
- strokeColor: {r: 0, g: 0, b: 0},
53
- strokeOpacity: 1,
54
- strokeWidth: 3,
55
- closed: false,
56
- lineCap: 'butt',
57
- lineJoin: 'miter'
58
- },
59
- highlightStyle: {
60
- strokeWidth: 5
50
+ }
61
51
  },
62
52
  createStyle: {
63
53
  line: function (d) {
@@ -68,15 +58,9 @@ var lineAnnotation = function (args) {
68
58
  },
69
59
  position: function (d, i) {
70
60
  return m_this.options('vertices')[i];
71
- },
72
- strokeColor: {r: 0, g: 0, b: 1},
73
- strokeOpacity: 1,
74
- strokeWidth: 3,
75
- closed: false,
76
- lineCap: 'butt',
77
- lineJoin: 'miter'
61
+ }
78
62
  }
79
- }, args || {});
63
+ }, args);
80
64
  args.vertices = args.vertices || args.coordinates || [];
81
65
  delete args.coordinates;
82
66
  annotation.call(this, 'line', args);
@@ -337,6 +321,31 @@ var lineAnnotation = function (args) {
337
321
  };
338
322
  inherit(lineAnnotation, annotation);
339
323
 
324
+ /**
325
+ * This object contains the default options to initialize the class.
326
+ */
327
+ lineAnnotation.defaults = $.extend({}, annotation.defaults, {
328
+ style: {
329
+ strokeColor: {r: 0, g: 0, b: 0},
330
+ strokeOpacity: 1,
331
+ strokeWidth: 3,
332
+ closed: false,
333
+ lineCap: 'butt',
334
+ lineJoin: 'miter'
335
+ },
336
+ highlightStyle: {
337
+ strokeWidth: 5
338
+ },
339
+ createStyle: {
340
+ strokeColor: {r: 0, g: 0, b: 1},
341
+ strokeOpacity: 1,
342
+ strokeWidth: 3,
343
+ closed: false,
344
+ lineCap: 'butt',
345
+ lineJoin: 'miter'
346
+ }
347
+ });
348
+
340
349
  var lineRequiredFeatures = {};
341
350
  lineRequiredFeatures[lineFeature.capabilities.basic] = [annotationState.create];
342
351
  registerAnnotation('line', lineAnnotation, lineRequiredFeatures);
@@ -40,29 +40,7 @@ var pointAnnotation = function (args) {
40
40
  return new pointAnnotation(args);
41
41
  }
42
42
 
43
- args = $.extend(true, {}, {
44
- style: {
45
- fill: true,
46
- fillColor: {r: 0, g: 1, b: 0},
47
- fillOpacity: 0.25,
48
- radius: 10,
49
- scaled: false,
50
- stroke: true,
51
- strokeColor: {r: 0, g: 0, b: 0},
52
- strokeOpacity: 1,
53
- strokeWidth: 3
54
- },
55
- createStyle: {
56
- fillColor: {r: 0.3, g: 0.3, b: 0.3},
57
- fillOpacity: 0.25,
58
- strokeColor: {r: 0, g: 0, b: 1}
59
- },
60
- highlightStyle: {
61
- fillColor: {r: 0, g: 1, b: 1},
62
- fillOpacity: 0.5,
63
- strokeWidth: 5
64
- }
65
- }, args || {});
43
+ args = $.extend(true, {}, this.constructor.defaults, args);
66
44
  args.position = args.position || (args.coordinates ? args.coordinates[0] : undefined);
67
45
  delete args.coordinates;
68
46
  annotation.call(this, 'point', args);
@@ -201,6 +179,33 @@ var pointAnnotation = function (args) {
201
179
  };
202
180
  inherit(pointAnnotation, annotation);
203
181
 
182
+ /**
183
+ * This object contains the default options to initialize the class.
184
+ */
185
+ pointAnnotation.defaults = $.extend({}, annotation.defaults, {
186
+ style: {
187
+ fill: true,
188
+ fillColor: {r: 0, g: 1, b: 0},
189
+ fillOpacity: 0.25,
190
+ radius: 10,
191
+ scaled: false,
192
+ stroke: true,
193
+ strokeColor: {r: 0, g: 0, b: 0},
194
+ strokeOpacity: 1,
195
+ strokeWidth: 3
196
+ },
197
+ createStyle: {
198
+ fillColor: {r: 0.3, g: 0.3, b: 0.3},
199
+ fillOpacity: 0.25,
200
+ strokeColor: {r: 0, g: 0, b: 1}
201
+ },
202
+ highlightStyle: {
203
+ fillColor: {r: 0, g: 1, b: 1},
204
+ fillOpacity: 0.5,
205
+ strokeWidth: 5
206
+ }
207
+ });
208
+
204
209
  var pointRequiredFeatures = {};
205
210
  pointRequiredFeatures[pointFeature.capabilities.feature] = true;
206
211
  registerAnnotation('point', pointAnnotation, pointRequiredFeatures);
@@ -43,27 +43,11 @@ var polygonAnnotation = function (args) {
43
43
  return new polygonAnnotation(args);
44
44
  }
45
45
 
46
- args = $.extend(true, {}, {
46
+ args = $.extend(true, {}, this.constructor.defaults, {
47
47
  style: {
48
- fill: true,
49
- fillColor: {r: 0, g: 1, b: 0},
50
- fillOpacity: 0.25,
51
- polygon: function (d) { return d.polygon; },
52
- stroke: true,
53
- strokeColor: {r: 0, g: 0, b: 0},
54
- strokeOpacity: 1,
55
- strokeWidth: 3,
56
- uniformPolygon: true
57
- },
58
- highlightStyle: {
59
- fillColor: {r: 0, g: 1, b: 1},
60
- fillOpacity: 0.5,
61
- strokeWidth: 5
48
+ polygon: function (d) { return d.polygon; }
62
49
  },
63
50
  createStyle: {
64
- closed: false,
65
- fillColor: {r: 0.3, g: 0.3, b: 0.3},
66
- fillOpacity: 0.25,
67
51
  line: function (d) {
68
52
  const coord = m_this._coordinates();
69
53
  /* Return an array that has the same number of items as we have
@@ -76,11 +60,9 @@ var polygonAnnotation = function (args) {
76
60
  return d.x;
77
61
  }
78
62
  return m_this.options('vertices')[i];
79
- },
80
- stroke: false,
81
- strokeColor: {r: 0, g: 0, b: 1}
63
+ }
82
64
  }
83
- }, args || {});
65
+ }, args);
84
66
  args.vertices = args.vertices || args.coordinates || [];
85
67
  delete args.coordinates;
86
68
  annotation.call(this, 'polygon', args);
@@ -135,6 +117,25 @@ var polygonAnnotation = function (args) {
135
117
  return features;
136
118
  };
137
119
 
120
+ /**
121
+ * Return this annotation as a polygon list.
122
+ *
123
+ * @param {geo.util.polyop.spec} [opts] Ignored.
124
+ * @returns {geo.polygonList} A list of polygons.
125
+ */
126
+ this.toPolygonList = function (opts) {
127
+ const coord = m_this._coordinates();
128
+ if (coord.outer) {
129
+ const result = [[coord.outer.map((pt) => [pt.x, pt.y])]];
130
+ (coord.inner || []).forEach((h) => result[0].push(h.map((pt) => [pt.x, pt.y])));
131
+ return result;
132
+ }
133
+ if (coord.length < 3) {
134
+ return [];
135
+ }
136
+ return [[coord.map((pt) => [pt.x, pt.y])]];
137
+ };
138
+
138
139
  /**
139
140
  * Get and optionally set coordinates associated with this annotation in the
140
141
  * map gcs coordinate system.
@@ -305,6 +306,35 @@ var polygonAnnotation = function (args) {
305
306
  };
306
307
  inherit(polygonAnnotation, annotation);
307
308
 
309
+ /**
310
+ * This object contains the default options to initialize the class.
311
+ */
312
+ polygonAnnotation.defaults = $.extend({}, annotation.defaults, {
313
+ style: {
314
+ fill: true,
315
+ fillColor: {r: 0, g: 1, b: 0},
316
+ fillOpacity: 0.25,
317
+ stroke: true,
318
+ strokeColor: {r: 0, g: 0, b: 0},
319
+ strokeOpacity: 1,
320
+ strokeWidth: 3,
321
+ uniformPolygon: true
322
+ },
323
+ highlightStyle: {
324
+ fillColor: {r: 0, g: 1, b: 1},
325
+ fillOpacity: 0.5,
326
+ strokeWidth: 5
327
+ },
328
+ createStyle: {
329
+ closed: false,
330
+ fillColor: {r: 0.3, g: 0.3, b: 0.3},
331
+ fillOpacity: 0.25,
332
+ stroke: false,
333
+ strokeColor: {r: 0, g: 0, b: 1}
334
+ },
335
+ allowBooleanOperations: true
336
+ });
337
+
308
338
  var polygonRequiredFeatures = {};
309
339
  polygonRequiredFeatures[polygonFeature.capabilities.feature] = true;
310
340
  polygonRequiredFeatures[lineFeature.capabilities.basic] = [annotationState.create];
@@ -48,29 +48,7 @@ var rectangleAnnotation = function (args, annotationName) {
48
48
  return new rectangleAnnotation(args, annotationName);
49
49
  }
50
50
 
51
- args = $.extend(true, {}, {
52
- style: {
53
- fill: true,
54
- fillColor: {r: 0, g: 1, b: 0},
55
- fillOpacity: 0.25,
56
- polygon: function (d) { return d.polygon; },
57
- stroke: true,
58
- strokeColor: {r: 0, g: 0, b: 0},
59
- strokeOpacity: 1,
60
- strokeWidth: 3,
61
- uniformPolygon: true
62
- },
63
- highlightStyle: {
64
- fillColor: {r: 0, g: 1, b: 1},
65
- fillOpacity: 0.5,
66
- strokeWidth: 5
67
- },
68
- createStyle: {
69
- fillColor: {r: 0.3, g: 0.3, b: 0.3},
70
- fillOpacity: 0.25,
71
- strokeColor: {r: 0, g: 0, b: 1}
72
- }
73
- }, args || {});
51
+ args = $.extend(true, {}, this.constructor.defaults, args);
74
52
  args.corners = args.corners || args.coordinates || [];
75
53
  delete args.coordinates;
76
54
  annotation.call(this, annotationName || 'rectangle', args);
@@ -167,6 +145,19 @@ var rectangleAnnotation = function (args, annotationName) {
167
145
  return features;
168
146
  };
169
147
 
148
+ /**
149
+ * Return this annotation as a polygon list.
150
+ *
151
+ * @param {geo.util.polyop.spec} [opts] Ignored.
152
+ * @returns {geo.polygonList} A list of polygons.
153
+ */
154
+ this.toPolygonList = function (opts) {
155
+ if (m_this._coordinates().length < 3) {
156
+ return [];
157
+ }
158
+ return [[m_this._coordinates().map((pt) => [pt.x, pt.y])]];
159
+ };
160
+
170
161
  /**
171
162
  * Get and optionally set coordinates associated with this annotation in the
172
163
  * map gcs coordinate system.
@@ -395,6 +386,34 @@ var rectangleAnnotation = function (args, annotationName) {
395
386
  };
396
387
  inherit(rectangleAnnotation, annotation);
397
388
 
389
+ /**
390
+ * This object contains the default options to initialize the class.
391
+ */
392
+ rectangleAnnotation.defaults = $.extend({}, annotation.defaults, {
393
+ style: {
394
+ fill: true,
395
+ fillColor: {r: 0, g: 1, b: 0},
396
+ fillOpacity: 0.25,
397
+ polygon: function (d) { return d.polygon; },
398
+ stroke: true,
399
+ strokeColor: {r: 0, g: 0, b: 0},
400
+ strokeOpacity: 1,
401
+ strokeWidth: 3,
402
+ uniformPolygon: true
403
+ },
404
+ highlightStyle: {
405
+ fillColor: {r: 0, g: 1, b: 1},
406
+ fillOpacity: 0.5,
407
+ strokeWidth: 5
408
+ },
409
+ createStyle: {
410
+ fillColor: {r: 0.3, g: 0.3, b: 0.3},
411
+ fillOpacity: 0.25,
412
+ strokeColor: {r: 0, g: 0, b: 1}
413
+ },
414
+ allowBooleanOperations: true
415
+ });
416
+
398
417
  var rectangleRequiredFeatures = {};
399
418
  rectangleRequiredFeatures[polygonFeature.capabilities.feature] = true;
400
419
  registerAnnotation('rectangle', rectangleAnnotation, rectangleRequiredFeatures);
@@ -19,13 +19,20 @@ const rectangleAnnotation = require('./rectangleAnnotation');
19
19
  */
20
20
  var squareAnnotation = function (args, annotationName) {
21
21
  'use strict';
22
- args = $.extend({}, args, {constraint: 1});
23
22
  if (!(this instanceof squareAnnotation)) {
24
23
  return new squareAnnotation(args, annotationName);
25
24
  }
25
+ args = $.extend(true, {}, this.constructor.defaults, args, {constraint: 1});
26
26
  rectangleAnnotation.call(this, args, annotationName || 'square');
27
27
  };
28
28
  inherit(squareAnnotation, rectangleAnnotation);
29
+
30
+ /**
31
+ * This object contains the default options to initialize the class.
32
+ */
33
+ squareAnnotation.defaults = $.extend({}, rectangleAnnotation.defaults, {
34
+ });
35
+
29
36
  var squareRequiredFeatures = {};
30
37
  squareRequiredFeatures[polygonFeature.capabilities.feature] = true;
31
38
  registerAnnotation('square', squareAnnotation, squareRequiredFeatures);