geojs 1.8.9 → 1.8.10

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.9",
3
+ "version": "1.8.10",
4
4
  "description": "JavaScript Geo Visualization and Analysis Library",
5
5
  "homepage": "https://github.com/OpenGeoscience/geojs",
6
6
  "license": "Apache-2.0",
@@ -55,6 +55,7 @@ var geojsonReader = function (arg) {
55
55
  strokeOffset: 0,
56
56
  lineCap: 'butt',
57
57
  lineJoin: 'miter',
58
+ uniformLine: true,
58
59
  closed: false,
59
60
  ...arg.lineStyle
60
61
  },
@@ -66,6 +67,7 @@ var geojsonReader = function (arg) {
66
67
  strokeColor: '#999999',
67
68
  strokeWidth: 2,
68
69
  strokeOpacity: 1,
70
+ uniformPolygon: true,
69
71
  ...arg.polygonStyle
70
72
  }
71
73
  };
@@ -46,6 +46,9 @@ var util = require('./util');
46
46
  * divided by the sine of half the angle between segments, then a bevel join
47
47
  * is used instead. This is a single value that applies to all lines. If a
48
48
  * function, it is called with `(data)`.
49
+ * @property {boolean|function} [uniformLine=false] Boolean indicating if each
50
+ * line has a uniform style (uniform stroke color, opacity, and width). Can
51
+ * vary by line.
49
52
  * @property {number|function} [antialiasing] Antialiasing distance in pixels.
50
53
  * Values must be non-negative. A value greater than 1 will produce a
51
54
  * visible gradient. This is a single value that applies to all lines.
@@ -157,18 +160,30 @@ var lineFeature = function (arg) {
157
160
  var data = m_this.data(),
158
161
  line = m_this.line(),
159
162
  widthFunc = m_this.style.get('strokeWidth'),
163
+ widthVal = util.isFunction(m_this.style('strokeWidth')) ? undefined : widthFunc(),
160
164
  posFunc = m_this.position(),
161
165
  closedFunc = m_this.style.get('closed'),
166
+ closedVal = util.isFunction(m_this.style('closed')) ? undefined : closedFunc(),
167
+ uniformFunc = m_this.style.get('uniformLine'),
168
+ uniformVal = util.isFunction(m_this.style('uniformLine')) ? undefined : uniformFunc(),
162
169
  gcs = m_this.gcs(),
163
- mapgcs = m_this.layer().map().gcs();
170
+ mapgcs = m_this.layer().map().gcs(),
171
+ onlyInvertedY = transform.onlyInvertedY(gcs, mapgcs);
164
172
 
165
- data.forEach(function (d, index) {
166
- var closed = closedFunc(d, index),
167
- last, lasti, lastr, lastr2, first, record = [], min, max;
173
+ for (let index = 0; index < data.length; index += 1) {
174
+ const d = data[index];
175
+ const closed = closedVal === undefined ? closedFunc(d, index) : closedVal;
176
+ let last, lasti, lastr, lastr2, first, min, max, width;
177
+ const record = [];
178
+ const uniform = uniformVal === undefined ? uniformFunc(d, index) : uniformVal;
168
179
 
169
- line(d, index).forEach(function (current, j) {
170
- var p = posFunc(current, j, d, index);
171
- if (gcs !== mapgcs) {
180
+ const lineRecord = line(d, index);
181
+ for (let j = 0; j < lineRecord.length; j += 1) {
182
+ const current = lineRecord[j];
183
+ let p = posFunc(current, j, d, index);
184
+ if (onlyInvertedY) {
185
+ p.y = -p.y;
186
+ } else if (gcs !== mapgcs) {
172
187
  p = transform.transformCoordinates(gcs, mapgcs, p);
173
188
  }
174
189
  if (min === undefined) { min = {x: p.x, y: p.y}; }
@@ -177,9 +192,12 @@ var lineFeature = function (arg) {
177
192
  if (p.x > max.x) { max.x = p.x; }
178
193
  if (p.y < min.y) { min.y = p.y; }
179
194
  if (p.y > max.y) { max.y = p.y; }
180
- var r = Math.ceil(widthFunc(current, j, d, index) / 2) + 2;
195
+ if (!uniform || !j) {
196
+ width = widthVal === undefined ? widthFunc(current, j, d, index) : widthVal;
197
+ }
198
+ const r = Math.ceil(width / 2) + 2;
181
199
  if (max.r === undefined || r > max.r) { max.r = r; }
182
- var r2 = r * r;
200
+ const r2 = r * r;
183
201
  if (last) {
184
202
  record.push({u: p, v: last, r: lastr > r ? lastr : r, r2: lastr2 > r2 ? lastr2 : r2, i: j, j: lasti});
185
203
  }
@@ -190,14 +208,14 @@ var lineFeature = function (arg) {
190
208
  if (!first && closed) {
191
209
  first = {p: p, r: r, r2: r2, i: j};
192
210
  }
193
- });
211
+ }
194
212
  if (closed && first && (last.x !== first.p.x || last.y !== first.p.y)) {
195
213
  record.push({u: last, v: first.p, r: lastr > first.r ? lastr : first.r, r2: lastr2 > first.r2 ? lastr2 : first.r2, i: lasti, j: first.i});
196
214
  }
197
215
  record.min = min;
198
216
  record.max = max;
199
217
  m_pointSearchInfo.push(record);
200
- });
218
+ }
201
219
  return m_pointSearchInfo;
202
220
  };
203
221
 
@@ -495,7 +495,8 @@ var polygonFeature = function (arg) {
495
495
  strokeStyle: linePolyStyle(polyStyle.strokeStyle),
496
496
  strokeColor: linePolyStyle(polyStyle.strokeColor),
497
497
  strokeOffset: linePolyStyle(polyStyle.strokeOffset),
498
- strokeOpacity: strokeOpacity
498
+ strokeOpacity: strokeOpacity,
499
+ uniformLine: linePolyStyle(polyStyle.uniformPolygon)
499
500
  });
500
501
  var data = m_this.data(),
501
502
  posVal = m_this.style('position');
@@ -146,6 +146,7 @@ var webgl_lineFeature = function (arg) {
146
146
  strokeOffsetFunc = m_this.style.get('strokeOffset'), strokeOffsetVal,
147
147
  miterLimit = m_this.style.get('miterLimit')(data),
148
148
  antialiasing = m_this.style.get('antialiasing')(data) || 0,
149
+ uniformFunc = m_this.style.get('uniformLine'), uniformVal, uniform,
149
150
  order = m_this.featureVertices(), orderk0, prevkey, nextkey, offkey,
150
151
  orderLen = order.length,
151
152
  // webgl buffers; see _init for details
@@ -164,6 +165,7 @@ var webgl_lineFeature = function (arg) {
164
165
  strokeOffsetVal = util.isFunction(m_this.style('strokeOffset')) ? undefined : (strokeOffsetFunc() || 0);
165
166
  strokeOpacityVal = util.isFunction(m_this.style('strokeOpacity')) ? undefined : strokeOpacityFunc();
166
167
  strokeWidthVal = util.isFunction(m_this.style('strokeWidth')) ? undefined : strokeWidthFunc();
168
+ uniformVal = util.isFunction(m_this.style('uniformLine')) ? undefined : uniformFunc();
167
169
 
168
170
  if (miterLimit !== undefined) {
169
171
  /* We impose a limit no matter what, since otherwise the growth is
@@ -262,6 +264,7 @@ var webgl_lineFeature = function (arg) {
262
264
  if (lineItem.length < 2) {
263
265
  continue;
264
266
  }
267
+ uniform = uniformVal === undefined ? uniformFunc(lineItem, i) : uniformVal;
265
268
  d = data[i];
266
269
  closedVal = closed[i];
267
270
  firstPosIdx3 = posIdx3;
@@ -288,12 +291,26 @@ var webgl_lineFeature = function (arg) {
288
291
  (j !== lidx ? firstPosIdx3 + 3 : firstPosIdx3 + 6 - closedVal * 3) :
289
292
  posIdx3);
290
293
  }
291
- v.strokeWidth = strokeWidthVal === undefined ? strokeWidthFunc(lineItemData, lidx, d, i) : strokeWidthVal;
292
- v.strokeColor = strokeColorVal === undefined ? strokeColorFunc(lineItemData, lidx, d, i) : strokeColorVal;
293
- v.strokeOpacity = strokeOpacityVal === undefined ? strokeOpacityFunc(lineItemData, lidx, d, i) : strokeOpacityVal;
294
+ if (uniform && j > 0) {
295
+ if (j === 1) {
296
+ v.strokeWidth = vert[0].strokeWidth;
297
+ v.strokeColor = vert[0].strokeColor;
298
+ v.strokeOpacity = vert[0].strokeOpacity;
299
+ }
300
+ } else {
301
+ v.strokeWidth = strokeWidthVal === undefined ? strokeWidthFunc(lineItemData, lidx, d, i) : strokeWidthVal;
302
+ v.strokeColor = strokeColorVal === undefined ? strokeColorFunc(lineItemData, lidx, d, i) : strokeColorVal;
303
+ v.strokeOpacity = strokeOpacityVal === undefined ? strokeOpacityFunc(lineItemData, lidx, d, i) : strokeOpacityVal;
304
+ }
294
305
  if (updateFlags) {
295
306
  if (strokeOffsetVal !== 0) {
296
- v.strokeOffset = (strokeOffsetVal === undefined ? strokeOffsetFunc(lineItemData, lidx, d, i) : strokeOffsetVal) || 0;
307
+ if (uniform && j > 0) {
308
+ if (j === 1) {
309
+ v.strokeOffset = vert[0].strokeOffset;
310
+ }
311
+ } else {
312
+ v.strokeOffset = (strokeOffsetVal === undefined ? strokeOffsetFunc(lineItemData, lidx, d, i) : strokeOffsetVal) || 0;
313
+ }
297
314
  if (v.strokeOffset) {
298
315
  /* we use 11 bits to store the offset, and we want to store values
299
316
  * from -1 to 1, so multiply our values by 1023, and use some bit
@@ -77,7 +77,7 @@ var webgl_polygonFeature = function (arg) {
77
77
  fillColor, fillColorFunc, fillColorVal,
78
78
  fillOpacity, fillOpacityFunc, fillOpacityVal,
79
79
  fillFunc, fillVal,
80
- uniformPolyFunc, uniform,
80
+ uniformFunc, uniformVal, uniform,
81
81
  indices,
82
82
  items = [],
83
83
  target_gcs = m_this.gcs(),
@@ -93,7 +93,8 @@ var webgl_polygonFeature = function (arg) {
93
93
  fillOpacityVal = util.isFunction(m_this.style('fillOpacity')) ? undefined : fillOpacityFunc();
94
94
  fillFunc = m_this.style.get('fill');
95
95
  fillVal = util.isFunction(m_this.style('fill')) ? undefined : fillFunc();
96
- uniformPolyFunc = m_this.style.get('uniformPolygon');
96
+ uniformFunc = m_this.style.get('uniformPolygon');
97
+ uniformVal = util.isFunction(m_this.style('uniformPolygon')) ? undefined : uniformFunc();
97
98
 
98
99
  if (!onlyStyle) {
99
100
  posFunc = m_this.style.get('position');
@@ -188,7 +189,7 @@ var webgl_polygonFeature = function (arg) {
188
189
  item = items[k].item;
189
190
  itemIndex = items[k].itemIndex;
190
191
  original = items[k].original;
191
- uniform = uniformPolyFunc(item, itemIndex);
192
+ uniform = uniformVal === undefined ? uniformFunc(item, itemIndex) : uniformVal;
192
193
  opacity = fillOpacityVal;
193
194
  if (uniform) {
194
195
  if (fillColorVal === undefined) {