geojs 1.8.6 → 1.8.9

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.6",
3
+ "version": "1.8.9",
4
4
  "description": "JavaScript Geo Visualization and Analysis Library",
5
5
  "homepage": "https://github.com/OpenGeoscience/geojs",
6
6
  "license": "Apache-2.0",
@@ -80,7 +80,7 @@ var graphFeature = function (arg) {
80
80
  arg.style === undefined ? {} : arg.style);
81
81
 
82
82
  m_this.style(defaultStyle);
83
- m_this.nodes(function (d) { return d; });
83
+ m_this.nodes(util.identityFunction);
84
84
  return m_this;
85
85
  };
86
86
 
@@ -2,6 +2,7 @@ var $ = require('jquery');
2
2
  var inherit = require('./inherit');
3
3
  var feature = require('./feature');
4
4
  var transform = require('./transform');
5
+ var util = require('./util');
5
6
 
6
7
  /**
7
8
  * Heatmap feature specification.
@@ -79,7 +80,7 @@ var heatmapFeature = function (arg) {
79
80
 
80
81
  this.featureType = 'heatmap';
81
82
 
82
- m_position = arg.position || function (d) { return d; };
83
+ m_position = arg.position || util.identityFunction;
83
84
  m_intensity = arg.intensity || function (d) { return 1; };
84
85
  m_maxIntensity = arg.maxIntensity !== undefined ? arg.maxIntensity : null;
85
86
  m_minIntensity = arg.minIntensity !== undefined ? arg.minIntensity : null;
@@ -438,8 +438,8 @@ var lineFeature = function (arg) {
438
438
  });
439
439
 
440
440
  /* Set the reduced lines as the data and use simple accessors. */
441
- m_this.style('position', function (d) { return d; });
442
- m_this.style('line', function (d) { return d; });
441
+ m_this.style('position', util.identityFunction);
442
+ m_this.style('line', util.identityFunction);
443
443
  m_this.data(data);
444
444
  return m_this;
445
445
  };
@@ -465,7 +465,7 @@ var lineFeature = function (arg) {
465
465
  // Values of 2 and above appear smoothest.
466
466
  antialiasing: 2.0,
467
467
  closed: false,
468
- line: function (d) { return d; },
468
+ line: util.identityFunction,
469
469
  position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d,
470
470
  origin: (p) => (p.length >= 3 ? p.slice(0, 3) : [0, 0, 0])
471
471
  },
@@ -285,7 +285,7 @@ var pixelmapFeature = function (arg) {
285
285
  a: 1
286
286
  };
287
287
  },
288
- position: function (d) { return d; }
288
+ position: util.identityFunction
289
289
  },
290
290
  arg.style === undefined ? {} : arg.style
291
291
  );
@@ -634,8 +634,8 @@ var polygonFeature = function (arg) {
634
634
  });
635
635
 
636
636
  /* Set the reduced polgons as the data and use simple accessors. */
637
- m_this.style('position', function (d) { return d; });
638
- m_this.style('polygon', function (d) { return d; });
637
+ m_this.style('position', util.identityFunction);
638
+ m_this.style('polygon', util.identityFunction);
639
639
  m_this.data(data);
640
640
  return m_this;
641
641
  };
@@ -719,7 +719,7 @@ var polygonFeature = function (arg) {
719
719
  strokeStyle: 'solid',
720
720
  strokeColor: {r: 0.0, g: 1.0, b: 1.0},
721
721
  strokeOpacity: 1.0,
722
- polygon: function (d) { return d; },
722
+ polygon: util.identityFunction,
723
723
  position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d,
724
724
  origin: (items) => {
725
725
  for (let i = 0; i < items.length; i += 1) {
@@ -699,7 +699,7 @@ var quadFeature = function (arg) {
699
699
  previewImage: null,
700
700
  image: function (d) { return d.image; },
701
701
  video: function (d) { return d.video; },
702
- position: function (d) { return d; }
702
+ position: util.identityFunction
703
703
  },
704
704
  arg.style === undefined ? {} : arg.style
705
705
  );
@@ -814,8 +814,8 @@ var trackFeature = function (arg) {
814
814
  true,
815
815
  {},
816
816
  {
817
- track: (d) => d,
818
- position: (d) => d,
817
+ track: util.identityFunction,
818
+ position: util.identityFunction,
819
819
  time: (d, i) => (d.t !== undefined ? d.t : i)
820
820
  },
821
821
  arg.style === undefined ? {} : arg.style
package/src/transform.js CHANGED
@@ -19,7 +19,7 @@ var maxTransformCacheSize = 10;
19
19
 
20
20
  /* A RegExp to detect if two transforms only different by the middle axis's
21
21
  * direction. */
22
- var axisPattern = /^(.* |)\\+axis=e(n|s)u(| .*)$/;
22
+ var axisPattern = /^(.* |)\+axis=e(n|s)u(| .*)$/;
23
23
  var affinePattern = /(^|\s)\+(s[1-3][1-3]|[xyz]off)=\S/;
24
24
 
25
25
  /**
@@ -767,6 +767,21 @@ transform.vincentyDistance = function (pt1, pt2, gcs, baseGcs, ellipsoid, maxIte
767
767
  };
768
768
  };
769
769
 
770
+ /**
771
+ * Return a boolean indicating if the projections only differ in their y
772
+ * coordinate.
773
+ *
774
+ * @param {string} srcPrj The source projection.
775
+ * @param {string} tgtPrj The destination projection.
776
+ * @returns {boolean} truthy if only the y coordinate is different between
777
+ * projections.
778
+ */
779
+ transform.onlyInvertedY = function (srcPrj, tgtPrj) {
780
+ const smatch = srcPrj.match(axisPattern),
781
+ tmatch = tgtPrj.match(axisPattern);
782
+ return smatch && tmatch && smatch[1] === tmatch[1] && smatch[3] === tmatch[3];
783
+ };
784
+
770
785
  /* Expose proj4 to make it easier to debug */
771
786
  transform.proj4 = proj4;
772
787
 
@@ -1443,6 +1443,17 @@ var util = {
1443
1443
  return value !== null && value !== undefined && (type === 'object' || type === 'function');
1444
1444
  },
1445
1445
 
1446
+ /**
1447
+ * Return the first value passed to the function. Using this function for
1448
+ * identity calls can allow some code to bypass making such a call entirely.
1449
+ *
1450
+ * @param {*} d Any value.
1451
+ * @returns {*} The passed value.
1452
+ */
1453
+ identityFunction: function (d) {
1454
+ return d;
1455
+ },
1456
+
1446
1457
  ///////////////////////////////////////////////////////////////////////////
1447
1458
  /*
1448
1459
  * Utility member properties.
@@ -1,5 +1,6 @@
1
1
  var inherit = require('./inherit');
2
2
  var feature = require('./feature');
3
+ var util = require('./util');
3
4
 
4
5
  /**
5
6
  * Object specification for a graph feature.
@@ -120,7 +121,7 @@ var vectorFeature = function (arg) {
120
121
  originStyle: 'none',
121
122
  endStyle: 'arrow',
122
123
  origin: {x: 0, y: 0, z: 0},
123
- delta: function (d) { return d; },
124
+ delta: util.identityFunction,
124
125
  scale: null // size scaling factor (null -> renderer decides)
125
126
  },
126
127
  arg.style === undefined ? {} : arg.style
@@ -134,6 +134,8 @@ var webgl_lineFeature = function (arg) {
134
134
  strokeOffset: 0, posStrokeOffset: 0, negStrokeOffset: 0
135
135
  }],
136
136
  v = vert[1],
137
+ target_gcs = m_this.gcs(),
138
+ map_gcs = m_this.layer().map().gcs(),
137
139
  pos, posIdx3, firstpos, firstPosIdx3,
138
140
  lineFunc = m_this.line(),
139
141
  strokeWidthFunc = m_this.style.get('strokeWidth'), strokeWidthVal,
@@ -175,6 +177,7 @@ var webgl_lineFeature = function (arg) {
175
177
  if (!onlyStyle) {
176
178
  var position = [],
177
179
  posFunc = m_this.position();
180
+ posFunc = posFunc === util.identityFunction ? null : posFunc;
178
181
  lineItemList = new Array(data.length);
179
182
  closed = new Array(data.length);
180
183
  for (i = 0; i < data.length; i += 1) {
@@ -186,7 +189,7 @@ var webgl_lineFeature = function (arg) {
186
189
  }
187
190
  numSegments += lineItem.length - 1;
188
191
  for (j = 0; j < lineItem.length; j += 1) {
189
- pos = posFunc(lineItem[j], j, d, i);
192
+ pos = posFunc ? posFunc(lineItem[j], j, d, i) : lineItem[j];
190
193
  position.push(pos.x);
191
194
  position.push(pos.y);
192
195
  position.push(pos.z || 0.0);
@@ -208,8 +211,7 @@ var webgl_lineFeature = function (arg) {
208
211
  }
209
212
  }
210
213
 
211
- position = transform.transformCoordinates(
212
- m_this.gcs(), m_this.layer().map().gcs(), position, 3);
214
+ position = transform.transformCoordinates(target_gcs, map_gcs, position, 3);
213
215
  m_origin = new Float32Array(m_this.style.get('origin')(position));
214
216
  if (m_origin[0] || m_origin[1] || m_origin[2]) {
215
217
  for (i = 0; i < position.length; i += 3) {
@@ -97,11 +97,13 @@ var webgl_polygonFeature = function (arg) {
97
97
 
98
98
  if (!onlyStyle) {
99
99
  posFunc = m_this.style.get('position');
100
+ posFunc = posFunc === util.identityFunction ? null : posFunc;
100
101
  polyFunc = m_this.style.get('polygon');
102
+ polyFunc = polyFunc === util.identityFunction ? null : polyFunc;
101
103
  m_this.data().forEach(function (item, itemIndex) {
102
104
  var polygon, outer, geometry, c;
103
105
 
104
- polygon = polyFunc(item, itemIndex);
106
+ polygon = polyFunc ? polyFunc(item, itemIndex) : item;
105
107
  if (!polygon) {
106
108
  return;
107
109
  }
@@ -115,7 +117,7 @@ var webgl_polygonFeature = function (arg) {
115
117
  * test). */
116
118
  geometry = new Array(outer.length * 3);
117
119
  for (i = d3 = 0; i < outer.length; i += 1, d3 += 3) {
118
- c = posFunc(outer[i], i, item, itemIndex);
120
+ c = posFunc ? posFunc(outer[i], i, item, itemIndex) : outer[i];
119
121
  geometry[d3] = c.x;
120
122
  geometry[d3 + 1] = c.y;
121
123
  // ignore the z values until we support them
@@ -132,7 +134,7 @@ var webgl_polygonFeature = function (arg) {
132
134
  original = original.concat(hole);
133
135
  geometry.holes.push(d3 / 3);
134
136
  for (i = 0; i < hole.length; i += 1, d3 += 3) {
135
- c = posFunc(hole[i], i, item, itemIndex);
137
+ c = posFunc ? posFunc(hole[i], i, item, itemIndex) : hole[i];
136
138
  geometry.vertices[d3] = c.x;
137
139
  geometry.vertices[d3 + 1] = c.y;
138
140
  // ignore the z values until we support them