Skip to content

Commit 2918a05

Browse files
author
Mr Martian
committed
improved nested key system
1 parent f88013e commit 2918a05

File tree

15 files changed

+141
-312
lines changed

15 files changed

+141
-312
lines changed

.vscode/extensions.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
33
"recommendations": [
44
"ms-playwright.playwright",
5-
"editorconfig.editorconfig",
65
"esbenp.prettier-vscode"
76
]
87
}

bun.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.mjs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,6 @@ export default tseslint.config(
126126
caughtErrorsIgnorePattern: '^_',
127127
},
128128
],
129-
'vue/multi-word-component-names': 'off',
130-
'vue/html-closing-bracket-newline': [
131-
'error',
132-
{
133-
singleline: 'never',
134-
multiline: 'never',
135-
},
136-
],
137129
},
138130
},
139131
);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"@vitejs/plugin-vue": "^5.2.3",
9898
"@vitest/browser": "^3.1.2",
9999
"@vitest/coverage-v8": "3.1.2",
100+
"@vitest/web-worker": "^3.1.2",
100101
"@webgpu/types": "^0.1.60",
101102
"ajv": "^8.17.1",
102103
"better-sqlite3": "^11.9.1",

s2/s2Map.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ declare global {
4848
/**
4949
* # The S2 Map GPU Engine 🌎 🗺️
5050
*
51+
* ```text
52+
* ad88888ba ad888888b, 88b d88
53+
* d8" "8b d8" "88 888b d888
54+
* Y8, a8P 88`8b d8'88
55+
* `Y8aaaaa, ,d8P" 88 `8b d8' 88 ,adPPYYba, 8b,dPPYba, ,adPPYba,
56+
* `"""""8b, a8P" 88 `8b d8' 88 "" `Y8 88P' "8a I8[ ""
57+
* `8b a8P' 88 `8b d8' 88 ,adPPPPP88 88 d8 `"Y8ba,
58+
* Y8a a8P d8" 88 `888' 88 88, ,88 88b, ,a8" aa ]8I
59+
* "Y88888P" 88888888888 88 `8' 88 `"8bbdP"Y8 88`YbbdP"' `"YbbdP"'
60+
* 88
61+
* 88
62+
* ```
63+
*
5164
* ## Description
5265
*
5366
* Both an **S2** and **WM** Projection Map Engine Powered by `WebGL1`, `WebGL2`, and `WebGPU`.

s2/s2maps.css

Lines changed: 0 additions & 235 deletions
Original file line numberDiff line numberDiff line change
@@ -263,238 +263,3 @@
263263
height: 26.93px;
264264
}
265265
}
266-
267-
/** INFO **/
268-
269-
#s2-card {
270-
position: absolute;
271-
display: flex;
272-
flex-direction: column;
273-
overflow: hidden;
274-
left: 16px;
275-
top: 16px;
276-
width: 425px;
277-
min-height: 100px;
278-
max-height: calc(100vh - 64px);
279-
background-color: #fff;
280-
border-radius: 10px;
281-
box-shadow: 0 8px 16px 0 rgb(0 0 0 / 28%);
282-
color: #52535d;
283-
}
284-
285-
#s2-card a:link {
286-
text-decoration: none!important;
287-
color: #007fff;
288-
}
289-
#s2-card a:hover {
290-
text-decoration: underline!important;
291-
color: #007fff;
292-
}
293-
#s2-card a:active {
294-
text-decoration: underline!important;
295-
color: #007fff;
296-
}
297-
#s2-card a:visited {
298-
text-decoration: none!important;
299-
color: #007fff;
300-
}
301-
302-
#s2-card-close-container {
303-
position: absolute;
304-
top: 0;
305-
right: 0;
306-
display: flex;
307-
justify-content: center;
308-
align-items: center;
309-
width: 36px;
310-
height: 36px;
311-
border-bottom-left-radius: 10px;
312-
}
313-
#s2-card-close-container:hover {
314-
background-color: #cc0202;
315-
cursor: pointer;
316-
}
317-
318-
#s2-card-close {
319-
box-sizing: border-box;
320-
position: relative;
321-
display: block;
322-
width: 22px;
323-
height: 22px;
324-
border: 2px solid transparent;
325-
border-radius: 40px
326-
}
327-
#s2-card-close::after,
328-
#s2-card-close::before {
329-
content: "";
330-
display: block;
331-
box-sizing: border-box;
332-
position: absolute;
333-
width: 16px;
334-
height: 2px;
335-
background: currentColor;
336-
transform: rotate(45deg);
337-
border-radius: 5px;
338-
top: 8px;
339-
left: 1px
340-
}
341-
#s2-card-close::after {
342-
transform: rotate(-45deg)
343-
}
344-
#s2-card-close-container:hover #s2-card-close {
345-
color: #fff;
346-
}
347-
348-
#s2-skeleton {
349-
margin-top: 10px;
350-
margin-bottom: 5px;
351-
}
352-
353-
.s2-skel-container {
354-
margin: 25px
355-
}
356-
357-
.s2-skel-header {
358-
height: 45px;
359-
width: 100%;
360-
background: #d9d9d9;
361-
border-radius: 25px;
362-
position: relative;
363-
overflow: hidden;
364-
}
365-
366-
.s2-skel-container .s2-skel-line::before,
367-
.s2-skel-header::before {
368-
position: absolute;
369-
content: "";
370-
height: 100%;
371-
width: 100%;
372-
left: 0;
373-
background-image: linear-gradient(to right, #d9d9d9 0%, rgba(0,0,0,0.05) 20%, #d9d9d9 40%, #d9d9d9 100%);
374-
background-repeat: no-repeat;
375-
background-size: 450px 400px;
376-
animation: shimmer 1s linear infinite;
377-
}
378-
.s2-skel-container .s2-skel-line {
379-
background: #d9d9d9;
380-
border-radius: 10px;
381-
height: 13px;
382-
margin: 10px 0;
383-
overflow: hidden;
384-
position: relative;
385-
}
386-
.s2-skel-container .s2-skel-line-1 {
387-
width: calc(100% - 15%);
388-
}
389-
.s2-skel-container .s2-skel-line-3 {
390-
width: calc(100% - 40%);
391-
}
392-
393-
@keyframes shimmer {
394-
0% {
395-
background-position: -450px 0;
396-
}
397-
100% {
398-
background-position: 450px 0;
399-
}
400-
}
401-
402-
#s2-card-body {
403-
max-height: calc(100vh - 64px);
404-
overflow-y: scroll;
405-
padding: 0 16px;
406-
padding-top: 20px;
407-
padding-bottom: 50px;
408-
text-align: left;
409-
}
410-
411-
.s2-card-item {
412-
font-size: 15.5px;
413-
line-height: 23px;
414-
padding: 7px 12px;
415-
padding-bottom: 7px;
416-
}
417-
418-
.s2-card-item p {
419-
margin: 0;
420-
}
421-
422-
.s2-card-item-flex {
423-
display: flex;
424-
justify-content: flex-start;
425-
align-items:flex-start;
426-
}
427-
428-
.s2-card-item-no-padding {
429-
padding: 0 12px;
430-
}
431-
432-
.s2-card-item-title {
433-
font-weight: bold;
434-
font-size: 27px;
435-
line-height: 28px;
436-
}
437-
438-
.s2-card-item-key {
439-
font-family: -apple-system, BlinkMacSystemFont, "RobotoMedium";
440-
padding-right: 10px;
441-
}
442-
443-
.s2-card-phone {
444-
display: flex;
445-
justify-content: space-between;
446-
margin: 5px 0;
447-
}
448-
449-
.s2-card-footer-container {
450-
position: relative;
451-
}
452-
453-
.s2-card-footer {
454-
padding: 0;
455-
margin: 0;
456-
background-color: #007fff;
457-
height: 52px;
458-
width: 100%;
459-
display: flex;
460-
justify-content: center;
461-
align-items: center;
462-
-webkit-user-select: none;
463-
user-select: none;
464-
color: #fff !important;
465-
font-weight: 500;
466-
}
467-
468-
#s2-mini-card {
469-
position: absolute;
470-
display: flex;
471-
flex-direction: column;
472-
overflow: hidden;
473-
left: 50%;
474-
bottom: 16px;
475-
transform: translateX(-50%);
476-
width: auto;
477-
height: auto;
478-
background-color: #fff;
479-
border-radius: 7px;
480-
box-shadow: 0 8px 16px 0 rgb(0 0 0 / 28%);
481-
color: #63646f;
482-
font-size: 14px;
483-
}
484-
485-
#s2-mini-card-body {
486-
padding: 15px 25px;
487-
}
488-
489-
@media only screen and (max-width: 750px) {
490-
.s2-card {
491-
left: 0px;
492-
right: 0px;
493-
bottom: 0px;
494-
top: auto;
495-
width: 100%;
496-
min-height: 100px;
497-
max-height: 50vh;
498-
border-radius: 0px;
499-
}
500-
}

s2/style/coalesceField.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ export default function coalesceField(
2929
properties: Properties,
3030
fieldIsKey = false,
3131
): string {
32-
// first dive into nested properties
33-
while (typeof field === 'object' && 'key' in field) {
34-
properties = (properties[field.nestedKey ?? ''] ?? {}) as Properties;
35-
field = field.key;
32+
// first dive into nested properties if field is an object
33+
while (typeof field === 'object' && 'nestedKey' in field) {
34+
const nestedKey = [...field.nestedKey];
35+
while (nestedKey.length > 1) {
36+
properties = (properties[nestedKey[0]] ?? {}) as Properties;
37+
nestedKey.shift();
38+
}
39+
field = nestedKey[0];
3640
}
3741
// now coalesce the field
3842
if (Array.isArray(field)) {

s2/style/parseFeature.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,21 @@ function inputValueFunction<T extends NotNullOrObject, U>(
6767
cb: Callback<ValueType<T>, U>,
6868
): LayerWorkerFunction<U> {
6969
return (code: number[], properties: Properties): U => {
70-
let endKey: string | NestedKey = inputValue.key;
70+
const { key, fallback } = inputValue;
7171
// dive into nested properties if needed
72-
while (typeof endKey === 'object' && 'key' in endKey) {
73-
properties = (properties[endKey.nestedKey ?? ''] ?? {}) as Properties;
74-
endKey = endKey.key;
72+
let endKey: string;
73+
if (typeof key === 'object') {
74+
const nestedKey = [...key.nestedKey];
75+
while (nestedKey.length > 1) {
76+
properties = (properties[nestedKey[0]] ?? {}) as Properties;
77+
nestedKey.shift();
78+
}
79+
endKey = nestedKey[0];
80+
} else {
81+
endKey = key;
7582
}
7683
// return the input if it exists, otherwise fallback
77-
const res = (properties[endKey] ?? inputValue.fallback) as ValueType<T>;
84+
const res = (properties[endKey] ?? fallback) as ValueType<T>;
7885
const cbValue = cb(res);
7986
if (typeof cbValue === 'number') code.push(1, cbValue);
8087
else if (Array.isArray(cbValue)) code.push(cbValue.length, ...cbValue);
@@ -144,9 +151,13 @@ function dataRangeFunction<T extends NotNullOrObject, U>(
144151
return (code: number[], properties: Properties, _zoom: number): U => {
145152
let endKey: string | NestedKey = key;
146153
// dive into nested properties if needed
147-
while (typeof endKey === 'object' && 'key' in endKey) {
148-
properties = (properties[endKey.nestedKey ?? ''] ?? {}) as Properties;
149-
endKey = endKey.key;
154+
while (typeof endKey === 'object' && 'nestedKey' in endKey) {
155+
const nestedKey = [...endKey.nestedKey];
156+
while (nestedKey.length > 1) {
157+
properties = (properties[nestedKey[0]] ?? {}) as Properties;
158+
nestedKey.shift();
159+
}
160+
endKey = nestedKey[0];
150161
}
151162
const dataInput =
152163
properties[endKey] !== undefined && !isNaN(properties[endKey] as number)

0 commit comments

Comments
 (0)