@dra2020/baseclient 1.0.5 → 1.0.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/dist/fsm/fsm.d.ts CHANGED
@@ -63,6 +63,7 @@ export declare class FsmOnDone extends Fsm {
63
63
  }
64
64
  export declare class FsmSleep extends Fsm {
65
65
  delay: number;
66
+ timeoutHandle: any;
66
67
  constructor(env: FsmEnvironment, delay: number);
67
68
  tick(): void;
68
69
  }
package/lib/fsm/fsm.ts CHANGED
@@ -291,6 +291,7 @@ export class FsmOnDone extends Fsm
291
291
  export class FsmSleep extends Fsm
292
292
  {
293
293
  delay: number;
294
+ timeoutHandle: any;
294
295
 
295
296
  constructor(env: FsmEnvironment, delay: number)
296
297
  {
@@ -300,10 +301,19 @@ export class FsmSleep extends Fsm
300
301
 
301
302
  tick(): void
302
303
  {
303
- if (this.ready && this.state === FSM_STARTING)
304
+ // This allows canceling by simply setting state to done
305
+ if (this.done && this.timeoutHandle !== undefined)
306
+ {
307
+ clearTimeout(this.timeoutHandle);
308
+ delete this.timeoutHandle;
309
+ }
310
+ else if (this.ready && this.state === FSM_STARTING)
304
311
  {
305
312
  this.setState(FSM_PENDING);
306
- setTimeout(() => { this.setState(FSM_DONE); }, this.delay);
313
+ this.timeoutHandle = setTimeout(() => {
314
+ delete this.timeoutHandle;
315
+ this.setState(FSM_DONE)
316
+ }, this.delay);
307
317
  }
308
318
  }
309
319
  }
package/lib/geo/geo.ts CHANGED
@@ -218,10 +218,8 @@ export class GeoMultiCollection
218
218
  if (n == 1)
219
219
  this.all.col = this._col(this.nthEntry(0));
220
220
  else
221
- {
222
- this.all.col = { type: 'FeatureCollection', features: [] };
223
- this.forEach(f => { this.all.col.features.push(f) });
224
- }
221
+ // Going from map to collection guarantees that any duplicates are removed
222
+ this.all.col = geoMapToCollection(this.allMap());
225
223
  }
226
224
  return this.all.col;
227
225
  }
@@ -236,7 +234,11 @@ export class GeoMultiCollection
236
234
  if (n == 1)
237
235
  this.all.map = this._map(this.nthEntry(0));
238
236
  else
239
- this.all.map = geoCollectionToMap(this.allCol());
237
+ {
238
+ let map: GeoFeatureMap = {};
239
+ this.all.map = map;
240
+ this.forEach(f => { map[String(f.properties.id)] = f });
241
+ }
240
242
  }
241
243
  return this.all.map;
242
244
  }
package/lib/poly/topo.ts CHANGED
@@ -184,6 +184,11 @@ export interface SimplifyOptions
184
184
 
185
185
  const DefaultSimplifyOptions: SimplifyOptions = { minArea: 500 };
186
186
 
187
+ function log(s: string): void
188
+ {
189
+ //console.log(s);
190
+ }
191
+
187
192
  //
188
193
  // topoSimplifyCollection:
189
194
  // This implements our simplification strategy for block/precinct level shapes. The basic idea is to
@@ -208,10 +213,10 @@ export function topoSimplifyCollection(col: any, options?: SimplifyOptions): any
208
213
  let elapsedTotal = new Util.Elapsed();
209
214
  let elapsed = new Util.Elapsed();
210
215
  let topo = topoFromCollection(col);
211
- console.log(`topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
216
+ log(`topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
212
217
  elapsed.start();
213
218
  topo = TopoSimplify.presimplify(topo, TopoSimplify['sphericalTriangleArea']);
214
- console.log(`topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
219
+ log(`topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
215
220
  elapsed.start();
216
221
 
217
222
  // Keep iterating on removing simplification from degenerate shapes
@@ -276,13 +281,13 @@ export function topoSimplifyCollection(col: any, options?: SimplifyOptions): any
276
281
  }
277
282
  }
278
283
  });
279
- console.log(`topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
284
+ log(`topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
280
285
 
281
286
  // If not making progress, keep more points
282
287
  if (nBad >= nBadLast)
283
288
  {
284
289
  keepweight /= 10;
285
- console.log(`topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
290
+ log(`topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
286
291
  }
287
292
  nBadLast = nBad;
288
293
 
@@ -298,7 +303,7 @@ export function topoSimplifyCollection(col: any, options?: SimplifyOptions): any
298
303
  nTries++;
299
304
  }
300
305
 
301
- console.log(`topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
306
+ log(`topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
302
307
 
303
308
  return col;
304
309
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",