@@ -12,9 +12,15 @@ import 'leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility
1212const props = defineProps <{
1313 fetchedData? : GeoJSON .FeatureCollection | null
1414}>();
15+
1516const emit = defineEmits <{
1617 (e : ' marker-click' , feature : GeoJSON .Feature ): void
1718}>();
19+
20+ const NO_VALUE_COLOR = ' #999999' ;
21+
22+ const { t } = useI18n ();
23+
1824let selectedMarker: L .Layer | null = null ;
1925const originalMarkerStyleMap = new Map <L .Layer , L .PathOptions >();
2026let legendControl: L .Control | null = null ;
@@ -57,16 +63,23 @@ function generateLabels(data: GeoJSON.FeatureCollection): Map<string, string> {
5763 );
5864 const labelKey: string | undefined = data .features [0 ]?.properties ?.options ?.label_option ;
5965 const key = labelKey ?? ' default' ;
66+ const legendDetail = (data .features [0 ].properties ?.options ?.legend_details || []) as LegendDetails [];
6067
61- const rawValues: ( string | number )[] = data .features .map (f => findValueByKey (f , key ) ?? ' default ' );
68+ const rawValues = data .features .map (f => findValueByKey (f , key ));
6269
63- const uniqueValues: string [] = Array .from (
64- new Set (rawValues .map (v => String (v ))),
70+ const uniqueValues = Array .from (
71+ new Set (rawValues .map (v => v === undefined ? undefined : String (v ))),
6572 );
6673
6774 if (legendDisplayOption [0 ] === ' default' ) {
68- uniqueValues .forEach ((value , i ) => {
69- colorMap .set (value , generateColor (i , uniqueValues .length ));
75+ uniqueValues .forEach ((value ) => {
76+ if (value === undefined ) {
77+ return ;
78+ }
79+ const match = legendDetail .find ((item : LegendDetails ) => item .label === value );
80+ if (match ?.color ) {
81+ colorMap .set (value , match .color );
82+ }
7083 });
7184
7285 legend .onAdd = function () {
@@ -76,36 +89,43 @@ function generateLabels(data: GeoJSON.FeatureCollection): Map<string, string> {
7689 ' background: white; padding: 8px; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,0.2);' ,
7790 );
7891
79- uniqueValues .forEach ((value ) => {
80- const color = colorMap .get (value );
81- div .innerHTML += `
82- <div style="color:black; margin-bottom:4px;">
83- <i style="background:${color }; width:12px; height:12px; display:inline-block; margin-right:4px;"></i> ${value }
84- </div> ` ;
92+ legendDetail .forEach (({ label , color }) => {
93+ if (uniqueValues .includes (label )) {
94+ div .innerHTML += `
95+ <div style="color:black; margin-bottom:4px;">
96+ <i style="background:${color }; width:12px; height:12px; display:inline-block; margin-right:4px;"></i> ${label }
97+ </div> ` ;
98+ }
8599 });
100+ if (uniqueValues .includes (undefined )) {
101+ div .innerHTML += `
102+ <div style="color:black; margin-bottom:4px;">
103+ <i style="background:${NO_VALUE_COLOR }; width:12px; height:12px; display:inline-block; margin-right:4px;"></i> ${t (' notDefined' )}
104+ </div> ` ;
105+ }
86106
87107 return div ;
88108 };
89109 }
90110 else if (legendDisplayOption [0 ] === ' colorVarient' ) {
91111 const numericValues: number [] = uniqueValues
112+ .filter (v => v !== undefined )
92113 .map (v => + v )
93114 .filter (v => ! Number .isNaN (v ));
94115
95- if (numericValues .length === 0 )
96- return colorMap ;
97-
98- const min = Math .min (... numericValues );
99- const max = Math .max (... numericValues );
116+ const bins: [number , number ][] = [];
117+ if (numericValues .length > 0 ) {
118+ const min = Math .min (... numericValues );
119+ const max = Math .max (... numericValues );
100120
101- const numBins = 5 ;
102- const step = (max - min ) / numBins ;
121+ const numBins = 5 ;
122+ const step = (max - min ) / numBins ;
103123
104- const bins : [ number , number ][] = [];
105- for ( let i = 0 ; i < numBins ; i ++ ) {
106- const start = min + i * step ;
107- const end = i === numBins - 1 ? max : start + step ;
108- bins . push ([ start , end ]);
124+ for ( let i = 0 ; i < numBins ; i ++ ) {
125+ const start = min + i * step ;
126+ const end = i === numBins - 1 ? max : start + step ;
127+ bins . push ([ start , end ]) ;
128+ }
109129 }
110130
111131 function getBinLabel(value : number ): string {
@@ -137,6 +157,13 @@ function generateLabels(data: GeoJSON.FeatureCollection): Map<string, string> {
137157 </div> ` ;
138158 });
139159
160+ if (uniqueValues .includes (undefined )) {
161+ div .innerHTML += `
162+ <div style="color:black; margin-bottom:4px;">
163+ <i style="background:${NO_VALUE_COLOR }; width:12px; height:12px; display:inline-block; margin-right:4px;"></i> ${t (' notDefined' )}
164+ </div> ` ;
165+ }
166+
140167 return div ;
141168 };
142169
@@ -188,7 +215,7 @@ function renderMarkers(data: GeoJSON.FeatureCollection | undefined) {
188215 key = feature .properties ?.__binLabel ;
189216 }
190217
191- const color = colorMap .get (key ) ?? ' #999 ' ;
218+ const color = colorMap .get (key ) ?? NO_VALUE_COLOR ;
192219
193220 const geoJsonLayer = L .geoJSON (feature , {
194221 style : () => ({
0 commit comments