geojs 1.8.2 → 1.8.3

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/geo.lean.js CHANGED
@@ -303,7 +303,7 @@ var annotation = function annotation(type, args) {
303
303
 
304
304
  this._rotateHandlePosition = function (offset, rotation) {
305
305
  var map = m_this.layer().map(),
306
- coor = m_this._coordinates(),
306
+ coord = m_this._coordinates(),
307
307
  center = util.centerFromPerimeter(m_this._coordinates()),
308
308
  dispCenter = center ? map.gcsToDisplay(center, null) : undefined,
309
309
  i,
@@ -317,9 +317,10 @@ var annotation = function annotation(type, args) {
317
317
 
318
318
  offset = offset || 0;
319
319
  rotation = rotation || 0;
320
+ coord = coord.outer ? coord.outer : coord;
320
321
 
321
- for (i = 0; i < coor.length; i += 1) {
322
- pos = map.gcsToDisplay(coor[i], null);
322
+ for (i = 0; i < coord.length; i += 1) {
323
+ pos = map.gcsToDisplay(coord[i], null);
323
324
  maxr2 = Math.max(maxr2, Math.pow(pos.x - dispCenter.x, 2) + Math.pow(pos.y - dispCenter.y, 2));
324
325
  }
325
326
 
@@ -511,6 +512,30 @@ var annotation = function annotation(type, args) {
511
512
  return m_this._processEditActionResize(evt);
512
513
  }
513
514
  };
515
+ /**
516
+ * Return a copy of the _coordinates or a geo.polygon record so that it
517
+ * doesn't share memory with the original.
518
+ *
519
+ * @param {geo.polygon} [coord] if specified, return a copy of this object.
520
+ * Otherwise, return a copy of this._coordinates.
521
+ * @returns {geo.polygon}
522
+ */
523
+
524
+
525
+ this._copyOfCoordinates = function (coord) {
526
+ coord = coord || m_this._coordinates();
527
+
528
+ if (!coord.outer) {
529
+ return coord.slice();
530
+ }
531
+
532
+ return {
533
+ outer: coord.outer.slice(),
534
+ inner: (coord.inner || []).map(function (h) {
535
+ return h.slice();
536
+ })
537
+ };
538
+ };
514
539
  /**
515
540
  * When an edit handle is selected or deselected (for instance, by moving the
516
541
  * mouse on or off of it), mark if it is selected and record the current
@@ -532,7 +557,7 @@ var annotation = function annotation(type, args) {
532
557
  var amountRotated = (m_this._editHandle || {}).amountRotated || 0;
533
558
  m_this._editHandle = {
534
559
  handle: handle,
535
- startCoordinates: m_this._coordinates().slice(),
560
+ startCoordinates: m_this._copyOfCoordinates(),
536
561
  center: util.centerFromPerimeter(m_this._coordinates()),
537
562
  rotatePosition: m_this._rotateHandlePosition(handle.style.rotateHandleOffset, handle.style.rotateHandleRotation + amountRotated),
538
563
  startAmountRotated: amountRotated,
@@ -592,10 +617,10 @@ var annotation = function annotation(type, args) {
592
617
  }
593
618
 
594
619
  if (m_options.coordinates) {
595
- var coor = m_options.coordinates;
620
+ var coord = m_options.coordinates;
596
621
  delete m_options.coordinates;
597
622
 
598
- m_this._coordinates(coor);
623
+ m_this._coordinates(coord);
599
624
  }
600
625
 
601
626
  if (m_options.name !== undefined) {
@@ -829,7 +854,7 @@ var annotation = function annotation(type, args) {
829
854
  gcs = gcs === null ? map.gcs() : gcs === undefined ? map.ingcs() : gcs;
830
855
 
831
856
  if (gcs !== map.gcs()) {
832
- coord = transform.transformCoordinates(map.gcs(), gcs, coord);
857
+ coord = m_this._convertCoordinates(map.gcs(), gcs, coord);
833
858
  }
834
859
  }
835
860
 
@@ -912,7 +937,7 @@ var annotation = function annotation(type, args) {
912
937
 
913
938
 
914
939
  this.geojson = function (gcs, includeCrs) {
915
- var coor = m_this._geojsonCoordinates(gcs),
940
+ var coord = m_this._geojsonCoordinates(gcs),
916
941
  geotype = m_this._geojsonGeometryType(),
917
942
  styles = m_this._geojsonStyles(),
918
943
  objStyle = m_this.options('style') || {},
@@ -921,7 +946,7 @@ var annotation = function annotation(type, args) {
921
946
  key,
922
947
  value;
923
948
 
924
- if (!coor || !coor.length || !geotype) {
949
+ if (!coord || !coord.length || !geotype) {
925
950
  return;
926
951
  }
927
952
 
@@ -929,7 +954,7 @@ var annotation = function annotation(type, args) {
929
954
  type: 'Feature',
930
955
  geometry: {
931
956
  type: geotype,
932
- coordinates: coor
957
+ coordinates: coord
933
958
  },
934
959
  properties: {
935
960
  annotationType: m_type,
@@ -1027,39 +1052,45 @@ var annotation = function annotation(type, args) {
1027
1052
  }
1028
1053
 
1029
1054
  editPoints = features[editHandleFeatureLevel].point;
1030
- vertices.forEach(function (pt, idx) {
1031
- if (opts.vertex !== false) {
1032
- editPoints.push($.extend({}, pt, {
1033
- type: 'vertex',
1034
- index: idx,
1035
- style: style,
1036
- editHandle: true
1037
- }));
1038
- }
1039
-
1040
- if (opts.edge !== false && idx !== vertices.length - 1 && (pt.x !== vertices[idx + 1].x || pt.y !== vertices[idx + 1].y)) {
1041
- editPoints.push($.extend({
1042
- x: (pt.x + vertices[idx + 1].x) / 2,
1043
- y: (pt.y + vertices[idx + 1].y) / 2
1044
- }, {
1045
- type: 'edge',
1046
- index: idx,
1047
- style: style,
1048
- editHandle: true
1049
- }));
1050
- }
1055
+ var vertexList = vertices.outer ? [vertices.outer].concat(vertices.inner || []) : [vertices];
1056
+ vertexList.forEach(function (vert, vidx) {
1057
+ vert.forEach(function (pt, idx) {
1058
+ if (opts.vertex !== false) {
1059
+ editPoints.push($.extend({}, pt, {
1060
+ type: 'vertex',
1061
+ index: idx,
1062
+ vindex: vidx,
1063
+ style: style,
1064
+ editHandle: true
1065
+ }));
1066
+ }
1051
1067
 
1052
- if (opts.edge !== false && !isOpen && idx === vertices.length - 1 && (pt.x !== vertices[0].x || pt.y !== vertices[0].y)) {
1053
- editPoints.push($.extend({
1054
- x: (pt.x + vertices[0].x) / 2,
1055
- y: (pt.y + vertices[0].y) / 2
1056
- }, {
1057
- type: 'edge',
1058
- index: idx,
1059
- style: style,
1060
- editHandle: true
1061
- }));
1062
- }
1068
+ if (opts.edge !== false && idx !== vert.length - 1 && (pt.x !== vert[idx + 1].x || pt.y !== vert[idx + 1].y)) {
1069
+ editPoints.push($.extend({
1070
+ x: (pt.x + vert[idx + 1].x) / 2,
1071
+ y: (pt.y + vert[idx + 1].y) / 2
1072
+ }, {
1073
+ type: 'edge',
1074
+ index: idx,
1075
+ vindex: vidx,
1076
+ style: style,
1077
+ editHandle: true
1078
+ }));
1079
+ }
1080
+
1081
+ if (opts.edge !== false && !isOpen && idx === vert.length - 1 && (pt.x !== vert[0].x || pt.y !== vert[0].y)) {
1082
+ editPoints.push($.extend({
1083
+ x: (pt.x + vert[0].x) / 2,
1084
+ y: (pt.y + vert[0].y) / 2
1085
+ }, {
1086
+ type: 'edge',
1087
+ index: idx,
1088
+ vindex: vidx,
1089
+ style: style,
1090
+ editHandle: true
1091
+ }));
1092
+ }
1093
+ });
1063
1094
  });
1064
1095
 
1065
1096
  if (opts.center !== false) {
@@ -1092,12 +1123,47 @@ var annotation = function annotation(type, args) {
1092
1123
 
1093
1124
  if (selected) {
1094
1125
  editPoints.forEach(function (pt) {
1095
- if (pt.type === selected.type && pt.index === selected.index) {
1126
+ if (pt.type === selected.type && pt.index === selected.index && pt.vindex === selected.vindex) {
1096
1127
  pt.selected = true;
1097
1128
  }
1098
1129
  });
1099
1130
  }
1100
1131
  };
1132
+ /**
1133
+ * Apply a map function of a geo.polygon.
1134
+ *
1135
+ * @param {geo.polygon} coord The polygon to apply the function to.
1136
+ * @param {function} func The function to apply.
1137
+ * @returns {array} The map results.
1138
+ */
1139
+
1140
+
1141
+ this._coordinatesMapFunc = function (coord, func) {
1142
+ if (!coord.outer) {
1143
+ return coord.map(func);
1144
+ }
1145
+
1146
+ return {
1147
+ outer: coord.outer.map(func),
1148
+ inner: (coord.inner || []).map(function (h) {
1149
+ return h.map(func);
1150
+ })
1151
+ };
1152
+ };
1153
+ /**
1154
+ * Check if two geo.polygons differ in their first point.
1155
+ *
1156
+ * @param {geo.polygon} coord1 One polygon to compare.
1157
+ * @param {geo.polygon} coord2 A second polygon to compare.
1158
+ * @returns {boolean} true if the first point matches.
1159
+ */
1160
+
1161
+
1162
+ this._firstPointDifferent = function (coord1, coord2) {
1163
+ coord1 = coord1.outer ? coord1.outer : coord1;
1164
+ coord2 = coord2.outer ? coord2.outer : coord2;
1165
+ return coord1[0].x !== coord2[0].x || coord1[0].y !== coord2[0].y;
1166
+ };
1101
1167
  /**
1102
1168
  * Process the edit center action for a general annotation.
1103
1169
  *
@@ -1115,14 +1181,14 @@ var annotation = function annotation(type, args) {
1115
1181
  },
1116
1182
  curPts = m_this._coordinates();
1117
1183
 
1118
- var pts = start.map(function (elem) {
1184
+ var pts = m_this._coordinatesMapFunc(start, function (elem) {
1119
1185
  return {
1120
1186
  x: elem.x + delta.x,
1121
1187
  y: elem.y + delta.y
1122
1188
  };
1123
1189
  });
1124
1190
 
1125
- if (pts[0].x !== curPts[0].x || pts[0].y !== curPts[0].y) {
1191
+ if (m_this._firstPointDifferent(pts, curPts)) {
1126
1192
  m_this._coordinates(pts);
1127
1193
 
1128
1194
  return true;
@@ -1151,7 +1217,7 @@ var annotation = function annotation(type, args) {
1151
1217
  ang = ang2 - ang1,
1152
1218
  curPts = m_this._coordinates();
1153
1219
 
1154
- var pts = start.map(function (elem) {
1220
+ var pts = m_this._coordinatesMapFunc(start, function (elem) {
1155
1221
  var delta = {
1156
1222
  x: elem.x - handle.center.x,
1157
1223
  y: elem.y - handle.center.y
@@ -1162,7 +1228,7 @@ var annotation = function annotation(type, args) {
1162
1228
  };
1163
1229
  });
1164
1230
 
1165
- if (pts[0].x !== curPts[0].x || pts[0].y !== curPts[0].y) {
1231
+ if (m_this._firstPointDifferent(pts, curPts)) {
1166
1232
  m_this._coordinates(pts);
1167
1233
 
1168
1234
  handle.amountRotated = handle.startAmountRotated + ang;
@@ -1200,14 +1266,15 @@ var annotation = function annotation(type, args) {
1200
1266
 
1201
1267
  if (d02 && d01) {
1202
1268
  var scale = d02 / d01;
1203
- var pts = start.map(function (elem) {
1269
+
1270
+ var pts = m_this._coordinatesMapFunc(start, function (elem) {
1204
1271
  return {
1205
1272
  x: (elem.x - handle.center.x) * scale + handle.center.x,
1206
1273
  y: (elem.y - handle.center.y) * scale + handle.center.y
1207
1274
  };
1208
1275
  });
1209
1276
 
1210
- if (pts[0].x !== curPts[0].x || pts[0].y !== curPts[0].y) {
1277
+ if (m_this._firstPointDifferent(pts, curPts)) {
1211
1278
  m_this._coordinates(pts);
1212
1279
 
1213
1280
  return true;
@@ -1228,15 +1295,25 @@ var annotation = function annotation(type, args) {
1228
1295
  this._processEditActionEdge = function (evt) {
1229
1296
  var handle = m_this._editHandle,
1230
1297
  index = handle.handle.index,
1298
+ vindex = handle.handle.vindex,
1231
1299
  curPts = m_this._coordinates();
1232
1300
 
1233
- curPts.splice(index + 1, 0, {
1234
- x: handle.handle.x,
1235
- y: handle.handle.y
1236
- });
1301
+ if (!curPts.outer) {
1302
+ curPts.splice(index + 1, 0, {
1303
+ x: handle.handle.x,
1304
+ y: handle.handle.y
1305
+ });
1306
+ } else {
1307
+ var loop = vindex ? curPts.inner[vindex - 1] : curPts.outer;
1308
+ loop.splice(index + 1, 0, {
1309
+ x: handle.handle.x,
1310
+ y: handle.handle.y
1311
+ });
1312
+ }
1313
+
1237
1314
  handle.handle.type = 'vertex';
1238
1315
  handle.handle.index += 1;
1239
- handle.startCoordinates = curPts.slice();
1316
+ handle.startCoordinates = m_this._copyOfCoordinates(curPts);
1240
1317
  m_this.modified();
1241
1318
  return true;
1242
1319
  };
@@ -1255,8 +1332,10 @@ var annotation = function annotation(type, args) {
1255
1332
  this._processEditActionVertex = function (evt, canClose) {
1256
1333
  var handle = m_this._editHandle,
1257
1334
  index = handle.handle.index,
1335
+ vindex = handle.handle.vindex,
1258
1336
  start = handle.startCoordinates,
1259
- curPts = m_this._coordinates(),
1337
+ ptsRef = m_this._coordinates(),
1338
+ curPts = ptsRef.outer ? vindex ? ptsRef.inner[vindex - 1] : ptsRef.outer : ptsRef,
1260
1339
  origLen = curPts.length,
1261
1340
  origPt = curPts[index],
1262
1341
  delta = {
@@ -1268,6 +1347,10 @@ var annotation = function annotation(type, args) {
1268
1347
  near,
1269
1348
  atEnd;
1270
1349
 
1350
+ if (start.outer) {
1351
+ start = vindex ? start.inner[vindex - 1] : start.outer;
1352
+ }
1353
+
1271
1354
  curPts[index] = {
1272
1355
  x: start[index].x + delta.x,
1273
1356
  y: start[index].y + delta.y
@@ -1308,10 +1391,43 @@ var annotation = function annotation(type, args) {
1308
1391
  return false;
1309
1392
  }
1310
1393
 
1311
- m_this._coordinates(curPts);
1394
+ m_this._coordinates(ptsRef);
1312
1395
 
1313
1396
  return true;
1314
1397
  };
1398
+ /**
1399
+ * Transform the annotations coordinates from one gcs to another.
1400
+ *
1401
+ * @param {string|geo.transform} oldgcs The current gcs.
1402
+ * @param {string|geo.transform} newgcs The new gcs.
1403
+ * @param {geo.polygon} [coord] If not specified, convert the coordinates in
1404
+ * place. If specified, convert these coordinates and return them (don't
1405
+ * alter the existing values).
1406
+ * @returns {geo.polygon}
1407
+ */
1408
+
1409
+
1410
+ this._convertCoordinates = function (oldgcs, newgcs, coord) {
1411
+ var store = !coord;
1412
+ coord = coord || m_this._coordinates();
1413
+
1414
+ if (!coord.outer) {
1415
+ coord = transform.transformCoordinates(oldgcs, newgcs, coord);
1416
+ } else {
1417
+ coord = {
1418
+ outer: transform.transformCoordinates(oldgcs, newgcs, coord.outer),
1419
+ inner: (coord.inner || []).map(function (h) {
1420
+ return transform.transformCoordinates(oldgcs, newgcs, h);
1421
+ })
1422
+ };
1423
+ }
1424
+
1425
+ if (store) {
1426
+ m_this._coordinates(coord);
1427
+ }
1428
+
1429
+ return coord;
1430
+ };
1315
1431
  };
1316
1432
  /* Functions used by multiple annotations */
1317
1433
 
@@ -1664,14 +1780,14 @@ var rectangleAnnotation = function rectangleAnnotation(args, annotationName) {
1664
1780
  return;
1665
1781
  }
1666
1782
 
1667
- var coor = [];
1783
+ var coord = [];
1668
1784
 
1669
1785
  for (var i = 0; i < 4; i += 1) {
1670
- coor.push([src[i].x, src[i].y]);
1786
+ coord.push([src[i].x, src[i].y]);
1671
1787
  }
1672
1788
 
1673
- coor.push([src[0].x, src[0].y]);
1674
- return [coor];
1789
+ coord.push([src[0].x, src[0].y]);
1790
+ return [coord];
1675
1791
  };
1676
1792
  /**
1677
1793
  * Return the geometry type that is used to store this annotation in geojson.
@@ -2115,13 +2231,20 @@ var polygonAnnotation = function polygonAnnotation(args) {
2115
2231
  },
2116
2232
  fillOpacity: 0.25,
2117
2233
  line: function line(d) {
2234
+ var coord = m_this._coordinates();
2118
2235
  /* Return an array that has the same number of items as we have
2119
2236
  * vertices. */
2120
- return Array.apply(null, Array(m_this.options('vertices').length)).map(function () {
2237
+
2238
+
2239
+ return Array.apply(null, Array((coord.outer || coord).length)).map(function () {
2121
2240
  return d;
2122
2241
  });
2123
2242
  },
2124
2243
  position: function position(d, i) {
2244
+ if (d.x !== undefined) {
2245
+ return d.x;
2246
+ }
2247
+
2125
2248
  return m_this.options('vertices')[i];
2126
2249
  },
2127
2250
  stroke: false,
@@ -2155,7 +2278,7 @@ var polygonAnnotation = function polygonAnnotation(args) {
2155
2278
  case annotationState.create:
2156
2279
  features = [];
2157
2280
 
2158
- if (opt.vertices && opt.vertices.length >= 3) {
2281
+ if (opt.vertices && (opt.vertices.outer || opt.vertices.length >= 3)) {
2159
2282
  features[1] = {
2160
2283
  polygon: {
2161
2284
  polygon: opt.vertices,
@@ -2340,18 +2463,32 @@ var polygonAnnotation = function polygonAnnotation(args) {
2340
2463
  this._geojsonCoordinates = function (gcs) {
2341
2464
  var src = m_this.coordinates(gcs);
2342
2465
 
2343
- if (!src || src.length < 3 || m_this.state() === annotationState.create) {
2466
+ if (!src || !src.outer && src.length < 3 || m_this.state() === annotationState.create) {
2344
2467
  return;
2345
2468
  }
2346
2469
 
2347
- var coor = [];
2470
+ var coord = [];
2348
2471
 
2349
- for (var i = 0; i < src.length; i += 1) {
2350
- coor.push([src[i].x, src[i].y]);
2472
+ if (!src.outer) {
2473
+ coord = [src.map(function (pt) {
2474
+ return [pt.x, pt.y];
2475
+ })];
2476
+ coord[0].push(coord[0][0].slice());
2477
+ } else {
2478
+ coord = [src.outer.map(function (pt) {
2479
+ return [pt.x, pt.y];
2480
+ })];
2481
+ coord[0].push(coord[0][0].slice());
2482
+ (src.inner || []).forEach(function (h) {
2483
+ var poly = h.map(function (pt) {
2484
+ return [pt.x, pt.y];
2485
+ });
2486
+ poly.push(poly[0].slice());
2487
+ coord.push(poly);
2488
+ });
2351
2489
  }
2352
2490
 
2353
- coor.push([src[0].x, src[0].y]);
2354
- return [coor];
2491
+ return coord;
2355
2492
  };
2356
2493
  /**
2357
2494
  * Return the geometry type that is used to store this annotation in geojson.
@@ -2659,13 +2796,13 @@ var lineAnnotation = function lineAnnotation(args) {
2659
2796
  return;
2660
2797
  }
2661
2798
 
2662
- var coor = [];
2799
+ var coord = [];
2663
2800
 
2664
2801
  for (var i = 0; i < src.length; i += 1) {
2665
- coor.push([src[i].x, src[i].y]);
2802
+ coord.push([src[i].x, src[i].y]);
2666
2803
  }
2667
2804
 
2668
- return coor;
2805
+ return coord;
2669
2806
  };
2670
2807
  /**
2671
2808
  * Return the geometry type that is used to store this annotation in geojson.
@@ -3675,7 +3812,7 @@ var annotationLayer = function annotationLayer(arg) {
3675
3812
  gcs = gcs === null ? map.gcs() : gcs === undefined ? map.ingcs() : gcs;
3676
3813
 
3677
3814
  if (gcs !== map.gcs()) {
3678
- annotation._coordinates(transform.transformCoordinates(gcs, map.gcs(), annotation._coordinates()));
3815
+ annotation._convertCoordinates(gcs, map.gcs());
3679
3816
  }
3680
3817
 
3681
3818
  if (update !== false) {
@@ -26667,7 +26804,7 @@ module.exports = sceneObject;
26667
26804
  * @constant
26668
26805
  * @type {string}
26669
26806
  */
26670
- module.exports = "0232ecc9dd2b5096d1f715cf71b0fc1ffc8cf8cf";
26807
+ module.exports = "06c78d577d1a9dd6332ee47b20fe441d239225ca";
26671
26808
 
26672
26809
  /***/ }),
26673
26810
 
@@ -37216,7 +37353,9 @@ var util = {
37216
37353
  * this is the same as the average of all the points of the lines of the
37217
37354
  * perimeter.
37218
37355
  *
37219
- * @param {geo.geoPosition[]} coor An array of coordinates.
37356
+ * @param {geo.geoPolygon} coor An array of coordinates. This can also be
37357
+ * a polygon object with an ``outer`` element with an array of
37358
+ * coordinates.
37220
37359
  * @returns {geo.geoPosition|undefined} The position for the center, or
37221
37360
  * `undefined` if no such position exists.
37222
37361
  * @memberof geo.util
@@ -37224,6 +37363,10 @@ var util = {
37224
37363
  centerFromPerimeter: function centerFromPerimeter(coor) {
37225
37364
  var position, p0, p1, w, sumw, i;
37226
37365
 
37366
+ if (coor && coor.outer) {
37367
+ coor = coor.outer;
37368
+ }
37369
+
37227
37370
  if (!coor || !coor.length) {
37228
37371
  return;
37229
37372
  }
@@ -39131,7 +39274,7 @@ module.exports = vectorFeature;
39131
39274
  * @constant
39132
39275
  * @type {string}
39133
39276
  */
39134
- module.exports = "1.8.2";
39277
+ module.exports = "1.8.3";
39135
39278
 
39136
39279
  /***/ }),
39137
39280