@corpsmap/corpsmap 4.1.17 → 4.1.20
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
|
@@ -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
|
|
|
@@ -92,7 +95,6 @@ export default {
|
|
|
92
95
|
} else {
|
|
93
96
|
try {
|
|
94
97
|
const data = JSON.parse(body);
|
|
95
|
-
console.log(data);
|
|
96
98
|
if (type === "EsriFeatureService") {
|
|
97
99
|
if (legendOverride === true) {
|
|
98
100
|
store.doGenerateArcImages(data, lyr);
|
|
@@ -184,7 +186,7 @@ export default {
|
|
|
184
186
|
},
|
|
185
187
|
});
|
|
186
188
|
},
|
|
187
|
-
false
|
|
189
|
+
false,
|
|
188
190
|
);
|
|
189
191
|
img.src = `data:${legend.contentType};base64,${legend.imageData}`;
|
|
190
192
|
img.alt = `Style for ${legend.label}`;
|
|
@@ -212,6 +214,7 @@ export default {
|
|
|
212
214
|
let legendLayers = store.selectLegendLayers();
|
|
213
215
|
let legendCanvases = store.selectLegendCanvases();
|
|
214
216
|
const drawingInfo = data.drawingInfo;
|
|
217
|
+
console.log("[legend] doGenerateEsriImages", displayName, data.geometryType, drawingInfo?.renderer?.type, "uniqueValueInfos:", drawingInfo?.renderer?.uniqueValueInfos?.length);
|
|
215
218
|
legendCanvases[uid] = {
|
|
216
219
|
displayName: displayName,
|
|
217
220
|
layerDescription: layerDescription,
|
|
@@ -221,10 +224,6 @@ export default {
|
|
|
221
224
|
heights: [],
|
|
222
225
|
};
|
|
223
226
|
legendLayers[uid] = [];
|
|
224
|
-
//TODO Logic below is needs to include other Esri styles.
|
|
225
|
-
console.log(drawingInfo.renderer);
|
|
226
|
-
console.log(drawingInfo.renderer.symbol);
|
|
227
|
-
// debugger;
|
|
228
227
|
switch (data.geometryType) {
|
|
229
228
|
case "esriGeometryPolygon":
|
|
230
229
|
if (
|
|
@@ -233,8 +232,9 @@ export default {
|
|
|
233
232
|
drawingInfo.renderer.symbol.style === "esriSFSSolid"
|
|
234
233
|
) {
|
|
235
234
|
let img = new Image();
|
|
236
|
-
const outlineColor = drawingInfo.renderer.symbol.outline.color;
|
|
237
235
|
const fillColor = drawingInfo.renderer.symbol.color;
|
|
236
|
+
const outlineColor =
|
|
237
|
+
drawingInfo.renderer.symbol.outline?.color ?? fillColor;
|
|
238
238
|
|
|
239
239
|
let canvas = document.createElement("canvas");
|
|
240
240
|
let ctx = canvas.getContext("2d");
|
|
@@ -249,12 +249,10 @@ export default {
|
|
|
249
249
|
// Draw polygon
|
|
250
250
|
ctx.beginPath();
|
|
251
251
|
ctx.lineWidth = "2";
|
|
252
|
-
ctx.strokeStyle = outlineColor
|
|
253
|
-
? `rgba(${outlineColor.join()})`
|
|
254
|
-
: null;
|
|
252
|
+
ctx.strokeStyle = safeRgba(outlineColor);
|
|
255
253
|
ctx.rect(0, 0, 20, 20);
|
|
256
254
|
ctx.stroke();
|
|
257
|
-
ctx.fillStyle =
|
|
255
|
+
ctx.fillStyle = safeRgba(fillColor);
|
|
258
256
|
ctx.fillRect(1, 1, 18, 18);
|
|
259
257
|
|
|
260
258
|
img.src = canvas.toDataURL(); //set src using data URI from canvas
|
|
@@ -284,8 +282,9 @@ export default {
|
|
|
284
282
|
drawingInfo.renderer.symbol.style === "esriSFSBackwardDiagonal"
|
|
285
283
|
) {
|
|
286
284
|
let img = new Image();
|
|
287
|
-
const outlineColor = drawingInfo.renderer.symbol.outline.color;
|
|
288
285
|
const fillColor = drawingInfo.renderer.symbol.color;
|
|
286
|
+
const outlineColor =
|
|
287
|
+
drawingInfo.renderer.symbol.outline?.color ?? fillColor;
|
|
289
288
|
|
|
290
289
|
let canvas = document.createElement("canvas");
|
|
291
290
|
let ctx = canvas.getContext("2d");
|
|
@@ -306,7 +305,7 @@ export default {
|
|
|
306
305
|
ctx.moveTo(10, 20);
|
|
307
306
|
ctx.lineTo(20, 10);
|
|
308
307
|
ctx.lineWidth = "2";
|
|
309
|
-
ctx.strokeStyle =
|
|
308
|
+
ctx.strokeStyle = safeRgba(outlineColor);
|
|
310
309
|
ctx.rect(0, 0, 20, 20);
|
|
311
310
|
ctx.stroke();
|
|
312
311
|
|
|
@@ -337,18 +336,15 @@ export default {
|
|
|
337
336
|
drawingInfo.renderer.type === "uniqueValue" &&
|
|
338
337
|
drawingInfo.renderer.uniqueValueInfos
|
|
339
338
|
) {
|
|
340
|
-
|
|
339
|
+
const seenLabels = new Set();
|
|
341
340
|
drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
|
|
341
|
+
if (!val.label || seenLabels.has(val.label)) return;
|
|
342
|
+
seenLabels.add(val.label);
|
|
343
|
+
|
|
342
344
|
let img = new Image();
|
|
343
|
-
console.log(val.value);
|
|
344
|
-
if (val.value === "BOEM") {
|
|
345
|
-
}
|
|
346
345
|
|
|
347
346
|
const fillColor = val.symbol.color;
|
|
348
|
-
const outlineColor =
|
|
349
|
-
val.symbol.outline && val.symbol.outline.color
|
|
350
|
-
? val.symbol.outline.color
|
|
351
|
-
: fillColor;
|
|
347
|
+
const outlineColor = val.symbol.outline?.color ?? fillColor;
|
|
352
348
|
|
|
353
349
|
let canvas = document.createElement("canvas");
|
|
354
350
|
let ctx = canvas.getContext("2d");
|
|
@@ -365,10 +361,10 @@ export default {
|
|
|
365
361
|
// Draw polygon
|
|
366
362
|
ctx.beginPath();
|
|
367
363
|
ctx.lineWidth = "2";
|
|
368
|
-
ctx.strokeStyle =
|
|
364
|
+
ctx.strokeStyle = safeRgba(outlineColor);
|
|
369
365
|
ctx.rect(0, 0, 20, 20);
|
|
370
366
|
ctx.stroke();
|
|
371
|
-
ctx.fillStyle =
|
|
367
|
+
ctx.fillStyle = safeRgba(fillColor);
|
|
372
368
|
ctx.fillRect(1, 1, 18, 18);
|
|
373
369
|
|
|
374
370
|
//add label to the right of image
|
|
@@ -421,7 +417,7 @@ export default {
|
|
|
421
417
|
|
|
422
418
|
// Draw line
|
|
423
419
|
ctx.beginPath();
|
|
424
|
-
ctx.strokeStyle =
|
|
420
|
+
ctx.strokeStyle = safeRgba(lineColor);
|
|
425
421
|
ctx.moveTo(0, 0);
|
|
426
422
|
ctx.lineTo(20, 20);
|
|
427
423
|
ctx.stroke();
|
|
@@ -452,7 +448,11 @@ export default {
|
|
|
452
448
|
drawingInfo.renderer.type === "uniqueValue" &&
|
|
453
449
|
drawingInfo.renderer.uniqueValueInfos
|
|
454
450
|
) {
|
|
451
|
+
const seenLineLabels = new Set();
|
|
455
452
|
drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
|
|
453
|
+
if (!val.label || seenLineLabels.has(val.label)) return;
|
|
454
|
+
seenLineLabels.add(val.label);
|
|
455
|
+
|
|
456
456
|
let img = new Image();
|
|
457
457
|
|
|
458
458
|
let canvas = document.createElement("canvas");
|
|
@@ -470,7 +470,7 @@ export default {
|
|
|
470
470
|
|
|
471
471
|
// Draw line
|
|
472
472
|
ctx.beginPath();
|
|
473
|
-
ctx.strokeStyle =
|
|
473
|
+
ctx.strokeStyle = safeRgba(lineColor);
|
|
474
474
|
ctx.moveTo(0, 0);
|
|
475
475
|
ctx.lineTo(20, 20);
|
|
476
476
|
ctx.stroke();
|
|
@@ -541,7 +541,7 @@ export default {
|
|
|
541
541
|
},
|
|
542
542
|
});
|
|
543
543
|
},
|
|
544
|
-
false
|
|
544
|
+
false,
|
|
545
545
|
);
|
|
546
546
|
|
|
547
547
|
img.alt = `Style for ${displayName}`;
|
|
@@ -559,9 +559,11 @@ export default {
|
|
|
559
559
|
drawingInfo.renderer.symbol.type === "esriSMS"
|
|
560
560
|
) {
|
|
561
561
|
let img = new Image();
|
|
562
|
-
const outlineColor = drawingInfo.renderer.symbol.outline.color;
|
|
563
|
-
const outlineWidth = drawingInfo.renderer.symbol.outline.width;
|
|
564
562
|
const fillColor = drawingInfo.renderer.symbol.color;
|
|
563
|
+
const outlineColor =
|
|
564
|
+
drawingInfo.renderer.symbol.outline?.color ?? fillColor;
|
|
565
|
+
const outlineWidth =
|
|
566
|
+
drawingInfo.renderer.symbol.outline?.width ?? 1;
|
|
565
567
|
const size = drawingInfo.renderer.symbol.size;
|
|
566
568
|
|
|
567
569
|
let canvas = document.createElement("canvas");
|
|
@@ -575,10 +577,10 @@ export default {
|
|
|
575
577
|
|
|
576
578
|
// circle
|
|
577
579
|
ctx.beginPath();
|
|
578
|
-
ctx.strokeStyle =
|
|
580
|
+
ctx.strokeStyle = safeRgba(outlineColor);
|
|
579
581
|
ctx.lineWidth = outlineWidth;
|
|
580
582
|
ctx.arc(size, size, size / 1.5, 0, Math.PI * 2);
|
|
581
|
-
ctx.fillStyle =
|
|
583
|
+
ctx.fillStyle = safeRgba(fillColor);
|
|
582
584
|
ctx.fill();
|
|
583
585
|
ctx.stroke();
|
|
584
586
|
|
|
@@ -606,73 +608,43 @@ export default {
|
|
|
606
608
|
}
|
|
607
609
|
//___________________________________________________________________________________________________________________________________
|
|
608
610
|
else if (drawingInfo.renderer.uniqueValueInfos) {
|
|
609
|
-
// let canvas = document.createElement("canvas");
|
|
610
|
-
// let ctx = canvas.getContext("2d");
|
|
611
611
|
let result = [];
|
|
612
|
-
|
|
612
|
+
console.log("[legend] esriGeometryPoint uniqueValueInfos count:", drawingInfo.renderer.uniqueValueInfos.length);
|
|
613
613
|
drawingInfo.renderer.uniqueValueInfos.forEach((val) => {
|
|
614
614
|
let label = val.label;
|
|
615
|
-
let wkCanvas;
|
|
616
615
|
let img = new Image();
|
|
617
|
-
img.src = `data:image/png;base64,${val.symbol.imageData}`;
|
|
618
|
-
|
|
619
|
-
// img.addEventListener(
|
|
620
|
-
// "load",
|
|
621
|
-
// function () {
|
|
622
616
|
let canvas = document.createElement("canvas");
|
|
623
617
|
let ctx = canvas.getContext("2d");
|
|
624
|
-
|
|
625
618
|
const labelWidth = Number(ctx.measureText(label).width);
|
|
619
|
+
console.log("[legend] processing val:", label, "symbol type:", val.symbol.type);
|
|
626
620
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
// dispatch({
|
|
651
|
-
// type: "LEGEND_CANVAS_ADDED",
|
|
652
|
-
// payload: {
|
|
653
|
-
// legendCanvases: legendCanvases,
|
|
654
|
-
// loading: false,
|
|
655
|
-
// },
|
|
656
|
-
// });
|
|
657
|
-
// result.push(canvas)
|
|
658
|
-
// },
|
|
659
|
-
// false
|
|
660
|
-
// );
|
|
661
|
-
// img.src = `data:${val.symbol.url};base64,${val.symbol.imageData}`
|
|
662
|
-
// img.src = canvas.toDataURL()
|
|
621
|
+
if (val.symbol.type === "esriPMS") {
|
|
622
|
+
img.src = `data:image/png;base64,${val.symbol.imageData}`;
|
|
623
|
+
canvas.width = Number(val.symbol.width) + labelWidth + 4;
|
|
624
|
+
canvas.height = val.symbol.height;
|
|
625
|
+
ctx.fillStyle = "white";
|
|
626
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
627
|
+
ctx.drawImage(img, 0, 0);
|
|
628
|
+
} else if (val.symbol.type === "esriSMS") {
|
|
629
|
+
const size = val.symbol.size || 10;
|
|
630
|
+
canvas.width = size * 2;
|
|
631
|
+
canvas.height = size * 2;
|
|
632
|
+
ctx.fillStyle = safeRgba(val.symbol.color);
|
|
633
|
+
ctx.beginPath();
|
|
634
|
+
ctx.arc(size, size, size / 1.5, 0, Math.PI * 2);
|
|
635
|
+
ctx.fill();
|
|
636
|
+
if (val.symbol.outline) {
|
|
637
|
+
ctx.strokeStyle = safeRgba(val.symbol.outline.color);
|
|
638
|
+
ctx.lineWidth = val.symbol.outline.width;
|
|
639
|
+
ctx.stroke();
|
|
640
|
+
}
|
|
641
|
+
img.src = canvas.toDataURL();
|
|
642
|
+
console.log("[legend] esriSMS canvas size:", canvas.width, "x", canvas.height, "src length:", img.src.length);
|
|
643
|
+
}
|
|
663
644
|
|
|
664
645
|
img.alt = `Style for ${label}`;
|
|
665
646
|
img.crossOrigin = "anonymous";
|
|
666
647
|
img.title = label;
|
|
667
|
-
// legendLayers[uid] = [img]; //TODO: Update to possibly push multiple images into array
|
|
668
|
-
// images.push(img)
|
|
669
|
-
|
|
670
|
-
// dispatch({
|
|
671
|
-
// type: "LEGEND_LAYERS_UPDATED",
|
|
672
|
-
// payload: {
|
|
673
|
-
// legendLayers: legendLayers,
|
|
674
|
-
// },
|
|
675
|
-
// });
|
|
676
648
|
result.push({
|
|
677
649
|
canvas: canvas,
|
|
678
650
|
image: img,
|
|
@@ -693,12 +665,20 @@ export default {
|
|
|
693
665
|
},
|
|
694
666
|
});
|
|
695
667
|
});
|
|
668
|
+
console.log("[legend] dispatching LEGEND_LAYERS_UPDATED, legendLayers[uid] count:", legendLayers[uid]?.length, "img srcs:", legendLayers[uid]?.map(i => i.src?.substring(0, 30)));
|
|
669
|
+
dispatch({
|
|
670
|
+
type: "LEGEND_LAYERS_UPDATED",
|
|
671
|
+
payload: {
|
|
672
|
+
legendLayers: legendLayers,
|
|
673
|
+
loading: false,
|
|
674
|
+
},
|
|
675
|
+
});
|
|
696
676
|
} else if (drawingInfo.renderer.classBreakInfos) {
|
|
697
677
|
drawingInfo.renderer.classBreakInfos.forEach((val) => {
|
|
698
678
|
let img = new Image();
|
|
699
|
-
const outlineColor = val.symbol.outline.color;
|
|
700
|
-
const outlineWidth = val.symbol.outline.width;
|
|
701
679
|
const fillColor = val.symbol.color;
|
|
680
|
+
const outlineColor = val.symbol.outline?.color ?? fillColor;
|
|
681
|
+
const outlineWidth = val.symbol.outline?.width ?? 1;
|
|
702
682
|
const size = val.symbol.size;
|
|
703
683
|
let canvas = document.createElement("canvas");
|
|
704
684
|
let ctx = canvas.getContext("2d");
|
|
@@ -715,10 +695,10 @@ export default {
|
|
|
715
695
|
|
|
716
696
|
// circle
|
|
717
697
|
ctx.beginPath();
|
|
718
|
-
ctx.strokeStyle =
|
|
698
|
+
ctx.strokeStyle = safeRgba(outlineColor);
|
|
719
699
|
ctx.lineWidth = outlineWidth;
|
|
720
700
|
ctx.arc(size, size * 1.5, size / 1.5, 0, Math.PI * 2);
|
|
721
|
-
ctx.fillStyle =
|
|
701
|
+
ctx.fillStyle = safeRgba(fillColor);
|
|
722
702
|
ctx.fill();
|
|
723
703
|
ctx.stroke();
|
|
724
704
|
|
|
@@ -792,7 +772,7 @@ export default {
|
|
|
792
772
|
},
|
|
793
773
|
});
|
|
794
774
|
},
|
|
795
|
-
false
|
|
775
|
+
false,
|
|
796
776
|
);
|
|
797
777
|
|
|
798
778
|
img.alt = `Style for ${displayName}`;
|
|
@@ -918,7 +898,7 @@ export default {
|
|
|
918
898
|
},
|
|
919
899
|
});
|
|
920
900
|
},
|
|
921
|
-
false
|
|
901
|
+
false,
|
|
922
902
|
);
|
|
923
903
|
let legendParams = `service=WMS&version=1.1.1&request=GetLegendGraphic&format=image/png&sld_version=1.1.0&layer=${lyr}`;
|
|
924
904
|
if (layer.url.indexOf(".map") !== -1) {
|
|
@@ -983,7 +963,7 @@ export default {
|
|
|
983
963
|
},
|
|
984
964
|
});
|
|
985
965
|
},
|
|
986
|
-
false
|
|
966
|
+
false,
|
|
987
967
|
);
|
|
988
968
|
img.src = layer.src;
|
|
989
969
|
img.alt = `Style for ${layer.displayName}`;
|
|
@@ -15,7 +15,7 @@ class LegendItemMultiple extends React.Component {
|
|
|
15
15
|
{typeof image === "string" ? (
|
|
16
16
|
image
|
|
17
17
|
) : (
|
|
18
|
-
<img alt={image.alt} src={image.src}></img>
|
|
18
|
+
<img alt={image.alt} src={image.src} style={{ marginRight: "5px" }}></img>
|
|
19
19
|
)}
|
|
20
20
|
{layer.type === "WMS" ? null : image.title}
|
|
21
21
|
<br></br>
|