@corpsmap/corpsmap 4.1.17 → 4.1.18

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": "@corpsmap/corpsmap",
3
- "version": "4.1.17",
3
+ "version": "4.1.18",
4
4
  "main": "dist/corpsmap.umd.js",
5
5
  "module": "dist/corpsmap.es.js",
6
6
  "type": "module",
@@ -3,6 +3,9 @@ import flatten from "lodash/flatten";
3
3
  //import { Style, Fill, Stroke } from "ol/style";
4
4
  let req = null;
5
5
 
6
+ const safeRgba = (color, fallback = [0, 0, 0, 0]) =>
7
+ color ? `rgba(${color.join()})` : `rgba(${fallback.join()})`;
8
+
6
9
  export default {
7
10
  name: "legend",
8
11
 
@@ -233,7 +236,7 @@ export default {
233
236
  drawingInfo.renderer.symbol.style === "esriSFSSolid"
234
237
  ) {
235
238
  let img = new Image();
236
- const outlineColor = drawingInfo.renderer.symbol.outline.color;
239
+ const outlineColor = drawingInfo.renderer.symbol.outline?.color;
237
240
  const fillColor = drawingInfo.renderer.symbol.color;
238
241
 
239
242
  let canvas = document.createElement("canvas");
@@ -249,12 +252,10 @@ export default {
249
252
  // Draw polygon
250
253
  ctx.beginPath();
251
254
  ctx.lineWidth = "2";
252
- ctx.strokeStyle = outlineColor
253
- ? `rgba(${outlineColor.join()})`
254
- : null;
255
+ ctx.strokeStyle = safeRgba(outlineColor);
255
256
  ctx.rect(0, 0, 20, 20);
256
257
  ctx.stroke();
257
- ctx.fillStyle = fillColor ? `rgba(${fillColor.join()})` : null;
258
+ ctx.fillStyle = safeRgba(fillColor);
258
259
  ctx.fillRect(1, 1, 18, 18);
259
260
 
260
261
  img.src = canvas.toDataURL(); //set src using data URI from canvas
@@ -284,7 +285,7 @@ export default {
284
285
  drawingInfo.renderer.symbol.style === "esriSFSBackwardDiagonal"
285
286
  ) {
286
287
  let img = new Image();
287
- const outlineColor = drawingInfo.renderer.symbol.outline.color;
288
+ const outlineColor = drawingInfo.renderer.symbol.outline?.color;
288
289
  const fillColor = drawingInfo.renderer.symbol.color;
289
290
 
290
291
  let canvas = document.createElement("canvas");
@@ -306,7 +307,7 @@ export default {
306
307
  ctx.moveTo(10, 20);
307
308
  ctx.lineTo(20, 10);
308
309
  ctx.lineWidth = "2";
309
- ctx.strokeStyle = `rgba(${outlineColor.join()})`;
310
+ ctx.strokeStyle = safeRgba(outlineColor);
310
311
  ctx.rect(0, 0, 20, 20);
311
312
  ctx.stroke();
312
313
 
@@ -337,12 +338,12 @@ export default {
337
338
  drawingInfo.renderer.type === "uniqueValue" &&
338
339
  drawingInfo.renderer.uniqueValueInfos
339
340
  ) {
340
- // Compare
341
+ const seenLabels = new Set();
341
342
  drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
343
+ if (!val.label || seenLabels.has(val.label)) return;
344
+ seenLabels.add(val.label);
345
+
342
346
  let img = new Image();
343
- console.log(val.value);
344
- if (val.value === "BOEM") {
345
- }
346
347
 
347
348
  const fillColor = val.symbol.color;
348
349
  const outlineColor =
@@ -365,10 +366,10 @@ export default {
365
366
  // Draw polygon
366
367
  ctx.beginPath();
367
368
  ctx.lineWidth = "2";
368
- ctx.strokeStyle = `rgba(${outlineColor.join()})`;
369
+ ctx.strokeStyle = safeRgba(outlineColor);
369
370
  ctx.rect(0, 0, 20, 20);
370
371
  ctx.stroke();
371
- ctx.fillStyle = `rgba(${fillColor.join()})`;
372
+ ctx.fillStyle = safeRgba(fillColor);
372
373
  ctx.fillRect(1, 1, 18, 18);
373
374
 
374
375
  //add label to the right of image
@@ -421,7 +422,7 @@ export default {
421
422
 
422
423
  // Draw line
423
424
  ctx.beginPath();
424
- ctx.strokeStyle = `rgba(${lineColor.join()})`;
425
+ ctx.strokeStyle = safeRgba(lineColor);
425
426
  ctx.moveTo(0, 0);
426
427
  ctx.lineTo(20, 20);
427
428
  ctx.stroke();
@@ -452,7 +453,11 @@ export default {
452
453
  drawingInfo.renderer.type === "uniqueValue" &&
453
454
  drawingInfo.renderer.uniqueValueInfos
454
455
  ) {
456
+ const seenLineLabels = new Set();
455
457
  drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
458
+ if (!val.label || seenLineLabels.has(val.label)) return;
459
+ seenLineLabels.add(val.label);
460
+
456
461
  let img = new Image();
457
462
 
458
463
  let canvas = document.createElement("canvas");
@@ -470,7 +475,7 @@ export default {
470
475
 
471
476
  // Draw line
472
477
  ctx.beginPath();
473
- ctx.strokeStyle = `rgba(${lineColor.join()})`;
478
+ ctx.strokeStyle = safeRgba(lineColor);
474
479
  ctx.moveTo(0, 0);
475
480
  ctx.lineTo(20, 20);
476
481
  ctx.stroke();
@@ -559,8 +564,8 @@ export default {
559
564
  drawingInfo.renderer.symbol.type === "esriSMS"
560
565
  ) {
561
566
  let img = new Image();
562
- const outlineColor = drawingInfo.renderer.symbol.outline.color;
563
- const outlineWidth = drawingInfo.renderer.symbol.outline.width;
567
+ const outlineColor = drawingInfo.renderer.symbol.outline?.color;
568
+ const outlineWidth = drawingInfo.renderer.symbol.outline?.width ?? 1;
564
569
  const fillColor = drawingInfo.renderer.symbol.color;
565
570
  const size = drawingInfo.renderer.symbol.size;
566
571
 
@@ -575,10 +580,10 @@ export default {
575
580
 
576
581
  // circle
577
582
  ctx.beginPath();
578
- ctx.strokeStyle = `rgba(${outlineColor.join()})`;
583
+ ctx.strokeStyle = safeRgba(outlineColor);
579
584
  ctx.lineWidth = outlineWidth;
580
585
  ctx.arc(size, size, size / 1.5, 0, Math.PI * 2);
581
- ctx.fillStyle = `rgba(${fillColor.join()})`;
586
+ ctx.fillStyle = safeRgba(fillColor);
582
587
  ctx.fill();
583
588
  ctx.stroke();
584
589
 
@@ -696,8 +701,8 @@ export default {
696
701
  } else if (drawingInfo.renderer.classBreakInfos) {
697
702
  drawingInfo.renderer.classBreakInfos.forEach((val) => {
698
703
  let img = new Image();
699
- const outlineColor = val.symbol.outline.color;
700
- const outlineWidth = val.symbol.outline.width;
704
+ const outlineColor = val.symbol.outline?.color;
705
+ const outlineWidth = val.symbol.outline?.width ?? 1;
701
706
  const fillColor = val.symbol.color;
702
707
  const size = val.symbol.size;
703
708
  let canvas = document.createElement("canvas");
@@ -715,10 +720,10 @@ export default {
715
720
 
716
721
  // circle
717
722
  ctx.beginPath();
718
- ctx.strokeStyle = `rgba(${outlineColor.join()})`;
723
+ ctx.strokeStyle = safeRgba(outlineColor);
719
724
  ctx.lineWidth = outlineWidth;
720
725
  ctx.arc(size, size * 1.5, size / 1.5, 0, Math.PI * 2);
721
- ctx.fillStyle = `rgba(${fillColor.join()})`;
726
+ ctx.fillStyle = safeRgba(fillColor);
722
727
  ctx.fill();
723
728
  ctx.stroke();
724
729