@@ -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 ;
@@ -59,14 +65,17 @@ function generateLabels(data: GeoJSON.FeatureCollection): Map<string, string> {
5965 const key = labelKey ?? ' default' ;
6066 const legendDetail = (data .features [0 ].properties ?.options ?.legend_details || []) as LegendDetails [];
6167
62- const rawValues: ( string | number )[] = data .features .map (f => findValueByKey (f , key ) ?? ' default ' );
68+ const rawValues = data .features .map (f => findValueByKey (f , key ));
6369
64- const uniqueValues: string [] = Array .from (
65- new Set (rawValues .map (v => String (v ))),
70+ const uniqueValues = Array .from (
71+ new Set (rawValues .map (v => v === undefined ? undefined : String (v ))),
6672 );
6773
6874 if (legendDisplayOption [0 ] === ' default' ) {
6975 uniqueValues .forEach ((value ) => {
76+ if (value === undefined ) {
77+ return ;
78+ }
7079 const match = legendDetail .find ((item : LegendDetails ) => item .label === value );
7180 if (match ?.color ) {
7281 colorMap .set (value , match .color );
@@ -88,29 +97,35 @@ function generateLabels(data: GeoJSON.FeatureCollection): Map<string, string> {
8897 </div> ` ;
8998 }
9099 });
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+ }
91106
92107 return div ;
93108 };
94109 }
95110 else if (legendDisplayOption [0 ] === ' colorVarient' ) {
96111 const numericValues: number [] = uniqueValues
112+ .filter (v => v !== undefined )
97113 .map (v => + v )
98114 .filter (v => ! Number .isNaN (v ));
99115
100- if (numericValues .length === 0 )
101- return colorMap ;
102-
103- const min = Math .min (... numericValues );
104- 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 );
105120
106- const numBins = 5 ;
107- const step = (max - min ) / numBins ;
121+ const numBins = 5 ;
122+ const step = (max - min ) / numBins ;
108123
109- const bins : [ number , number ][] = [];
110- for ( let i = 0 ; i < numBins ; i ++ ) {
111- const start = min + i * step ;
112- const end = i === numBins - 1 ? max : start + step ;
113- 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+ }
114129 }
115130
116131 function getBinLabel(value : number ): string {
@@ -142,6 +157,13 @@ function generateLabels(data: GeoJSON.FeatureCollection): Map<string, string> {
142157 </div> ` ;
143158 });
144159
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+
145167 return div ;
146168 };
147169
@@ -193,7 +215,7 @@ function renderMarkers(data: GeoJSON.FeatureCollection | undefined) {
193215 key = feature .properties ?.__binLabel ;
194216 }
195217
196- const color = colorMap .get (key ) ?? ' #999 ' ;
218+ const color = colorMap .get (key ) ?? NO_VALUE_COLOR ;
197219
198220 const geoJsonLayer = L .geoJSON (feature , {
199221 style : () => ({
0 commit comments