@focus-daima/gis-workbench 0.0.0-stage → 0.9.9
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/README.md +349 -2
- package/assets/glyphs/0-255.pbf +0 -0
- package/assets/glyphs/1024-1279.pbf +0 -0
- package/assets/glyphs/256-511.pbf +0 -0
- package/assets/glyphs/512-767.pbf +0 -0
- package/assets/glyphs/768-1023.pbf +0 -0
- package/client.js +1516 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +20 -0
- package/index.js +417 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +48 -4
- package/server/api.js +456 -0
- package/server/drop_layer.py +12 -0
- package/server/pg_tables.py +52 -0
- package/server/store.js +1854 -0
- package/server/unzip.py +30 -0
- package/server/vector_edit.py +133 -0
- package/server/vector_info.py +48 -0
- package/shared.js +37 -0
- package/src/api.js +269 -0
- package/src/client.entry.js +9 -0
- package/src/plugin.js +4503 -0
- package/src/store.js +189 -0
- package/src/styles.js +710 -0
- package/style-schema.js +199 -0
package/style-schema.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
export const STYLE_SCHEMA_VERSION = 1;
|
|
2
|
+
export const DEFAULT_LABEL_FONT = ['Open Sans Regular'];
|
|
3
|
+
export const MAP_GLYPHS_URL = '/api/gis-workbench/glyphs/{fontstack}/{range}.pbf';
|
|
4
|
+
|
|
5
|
+
const STYLE_KEYS = new Set([
|
|
6
|
+
'fillColor', 'fillOpacity',
|
|
7
|
+
'lineColor', 'lineWidth', 'lineOpacity',
|
|
8
|
+
'circleColor', 'circleRadius', 'circleOpacity',
|
|
9
|
+
'lineVisible', 'circleVisible',
|
|
10
|
+
'categorical', 'opacity', 'label',
|
|
11
|
+
]);
|
|
12
|
+
const LABEL_KEYS = new Set([
|
|
13
|
+
'field', 'valueMap', 'fallback', 'size', 'color', 'haloColor', 'haloWidth',
|
|
14
|
+
'minzoom', 'maxzoom', 'allowOverlap', 'font', 'anchor', 'onePerFeature',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
function assertObject(value, name) {
|
|
18
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
19
|
+
throw new Error(name + ' must be an object');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function number(value, name, min, max) {
|
|
24
|
+
if (value === undefined) return undefined;
|
|
25
|
+
const result = typeof value === 'number' ? value : Number(value);
|
|
26
|
+
if (!Number.isFinite(result)) throw new Error(name + ' must be a number');
|
|
27
|
+
if (result < min || result > max) throw new Error(name + ' must be between ' + min + ' and ' + max);
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function color(value, name) {
|
|
32
|
+
if (value === undefined) return undefined;
|
|
33
|
+
const text = String(value).trim();
|
|
34
|
+
if (!text || text.length > 80 || /[\u0000-\u001f;{}]/.test(text)) {
|
|
35
|
+
throw new Error(name + ' is not a valid color');
|
|
36
|
+
}
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function boolean(value, name) {
|
|
41
|
+
if (value === undefined) return undefined;
|
|
42
|
+
if (typeof value !== 'boolean') throw new Error(name + ' must be a boolean');
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizeLabel(input) {
|
|
47
|
+
if (input === null || input === false) return null;
|
|
48
|
+
assertObject(input, 'style.label');
|
|
49
|
+
for (const key of Object.keys(input)) {
|
|
50
|
+
if (!LABEL_KEYS.has(key)) throw new Error('Unknown style.label key: ' + key);
|
|
51
|
+
}
|
|
52
|
+
const field = String(input.field || '').trim();
|
|
53
|
+
if (!field) throw new Error('style.label.field is required');
|
|
54
|
+
if (field.length > 80) throw new Error('style.label.field is too long');
|
|
55
|
+
const output = { field };
|
|
56
|
+
if (input.valueMap !== undefined) {
|
|
57
|
+
assertObject(input.valueMap, 'style.label.valueMap');
|
|
58
|
+
const entries = Object.entries(input.valueMap);
|
|
59
|
+
if (entries.length > 500) throw new Error('style.label.valueMap supports at most 500 entries');
|
|
60
|
+
output.valueMap = {};
|
|
61
|
+
for (const [key, value] of entries) {
|
|
62
|
+
output.valueMap[String(key)] = String(value).slice(0, 200);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (input.fallback !== undefined) output.fallback = String(input.fallback).slice(0, 200);
|
|
66
|
+
if (input.size !== undefined) output.size = number(input.size, 'style.label.size', 6, 48);
|
|
67
|
+
if (input.color !== undefined) output.color = color(input.color, 'style.label.color');
|
|
68
|
+
if (input.haloColor !== undefined) output.haloColor = color(input.haloColor, 'style.label.haloColor');
|
|
69
|
+
if (input.haloWidth !== undefined) output.haloWidth = number(input.haloWidth, 'style.label.haloWidth', 0, 4);
|
|
70
|
+
if (input.minzoom !== undefined) output.minzoom = number(input.minzoom, 'style.label.minzoom', 0, 24);
|
|
71
|
+
if (input.maxzoom !== undefined) output.maxzoom = number(input.maxzoom, 'style.label.maxzoom', 0, 24);
|
|
72
|
+
if (output.minzoom !== undefined && output.maxzoom !== undefined && output.maxzoom < output.minzoom) {
|
|
73
|
+
throw new Error('style.label.maxzoom must be greater than or equal to minzoom');
|
|
74
|
+
}
|
|
75
|
+
if (input.allowOverlap !== undefined) output.allowOverlap = boolean(input.allowOverlap, 'style.label.allowOverlap');
|
|
76
|
+
if (input.onePerFeature !== undefined) output.onePerFeature = boolean(input.onePerFeature, 'style.label.onePerFeature');
|
|
77
|
+
if (input.font !== undefined) {
|
|
78
|
+
if (!Array.isArray(input.font) || input.font.length === 0) throw new Error('style.label.font must be a non-empty array');
|
|
79
|
+
output.font = input.font.map((item) => String(item).slice(0, 80));
|
|
80
|
+
}
|
|
81
|
+
if (input.anchor !== undefined) {
|
|
82
|
+
const anchor = String(input.anchor);
|
|
83
|
+
if (!['center', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right'].includes(anchor)) {
|
|
84
|
+
throw new Error('Invalid style.label.anchor');
|
|
85
|
+
}
|
|
86
|
+
output.anchor = anchor;
|
|
87
|
+
}
|
|
88
|
+
return output;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Validate and normalize a semantic style patch. Unknown keys are rejected. */
|
|
92
|
+
export function normalizeStylePatch(input) {
|
|
93
|
+
assertObject(input, 'stylePatch');
|
|
94
|
+
const output = {};
|
|
95
|
+
for (const key of Object.keys(input)) {
|
|
96
|
+
if (!STYLE_KEYS.has(key)) throw new Error('Unknown style key: ' + key);
|
|
97
|
+
}
|
|
98
|
+
if (input.fillColor !== undefined) output.fillColor = color(input.fillColor, 'style.fillColor');
|
|
99
|
+
if (input.fillOpacity !== undefined) output.fillOpacity = number(input.fillOpacity, 'style.fillOpacity', 0, 1);
|
|
100
|
+
if (input.lineColor !== undefined) output.lineColor = color(input.lineColor, 'style.lineColor');
|
|
101
|
+
if (input.lineWidth !== undefined) output.lineWidth = number(input.lineWidth, 'style.lineWidth', 0, 20);
|
|
102
|
+
if (input.lineOpacity !== undefined) output.lineOpacity = number(input.lineOpacity, 'style.lineOpacity', 0, 1);
|
|
103
|
+
if (input.circleColor !== undefined) output.circleColor = color(input.circleColor, 'style.circleColor');
|
|
104
|
+
if (input.circleRadius !== undefined) output.circleRadius = number(input.circleRadius, 'style.circleRadius', 0, 30);
|
|
105
|
+
if (input.circleOpacity !== undefined) output.circleOpacity = number(input.circleOpacity, 'style.circleOpacity', 0, 1);
|
|
106
|
+
if (input.lineVisible !== undefined) output.lineVisible = boolean(input.lineVisible, 'style.lineVisible');
|
|
107
|
+
if (input.circleVisible !== undefined) output.circleVisible = boolean(input.circleVisible, 'style.circleVisible');
|
|
108
|
+
if (input.categorical !== undefined) {
|
|
109
|
+
const categorical = input.categorical;
|
|
110
|
+
assertObject(categorical, 'style.categorical');
|
|
111
|
+
const field = String(categorical.field || '').trim();
|
|
112
|
+
if (!field) throw new Error('style.categorical.field is required');
|
|
113
|
+
assertObject(categorical.values, 'style.categorical.values');
|
|
114
|
+
const entries = Object.entries(categorical.values);
|
|
115
|
+
if (entries.length > 500) throw new Error('style.categorical.values supports at most 500 entries');
|
|
116
|
+
const values = {};
|
|
117
|
+
for (const [key, item] of entries) {
|
|
118
|
+
assertObject(item, 'style.categorical.values.' + key);
|
|
119
|
+
const entry = { color: color(item.color, 'style.categorical.values.' + key + '.color') };
|
|
120
|
+
if (!entry.color) throw new Error('style.categorical.values.' + key + '.color is required');
|
|
121
|
+
if (item.label !== undefined) entry.label = String(item.label).slice(0, 120);
|
|
122
|
+
values[String(key)] = entry;
|
|
123
|
+
}
|
|
124
|
+
output.categorical = { field, values };
|
|
125
|
+
if (categorical.fallbackColor !== undefined) {
|
|
126
|
+
output.categorical.fallbackColor = color(categorical.fallbackColor, 'style.categorical.fallbackColor');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (input.opacity !== undefined) output.opacity = number(input.opacity, 'style.opacity', 0, 1);
|
|
130
|
+
if (input.label !== undefined) output.label = normalizeLabel(input.label);
|
|
131
|
+
return output;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Merge a normalized patch into an existing layer style. */
|
|
135
|
+
export function mergeLayerStyle(baseStyle, patch) {
|
|
136
|
+
const base = baseStyle && typeof baseStyle === 'object' ? baseStyle : {};
|
|
137
|
+
const normalized = normalizeStylePatch(patch || {});
|
|
138
|
+
const merged = Object.assign({}, base);
|
|
139
|
+
for (const [key, value] of Object.entries(normalized)) {
|
|
140
|
+
if (key === 'label') {
|
|
141
|
+
if (value === null) delete merged.label;
|
|
142
|
+
else if (!base.label || typeof base.label !== 'object' || base.label.field !== value.field) merged.label = value;
|
|
143
|
+
else merged.label = Object.assign({}, base.label, value);
|
|
144
|
+
} else {
|
|
145
|
+
merged[key] = value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return merged;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export const STYLE_SCHEMA = {
|
|
152
|
+
version: STYLE_SCHEMA_VERSION,
|
|
153
|
+
description: 'Semantic vector layer style patch. Style is persisted in the project layer record; the browser applies it to MapLibre.',
|
|
154
|
+
properties: {
|
|
155
|
+
fillColor: 'CSS color for polygon fill',
|
|
156
|
+
fillOpacity: '0..1 polygon fill opacity',
|
|
157
|
+
lineColor: 'CSS color for line and polygon outline',
|
|
158
|
+
lineWidth: '0..20 line width in pixels',
|
|
159
|
+
lineOpacity: '0..1 line opacity',
|
|
160
|
+
circleColor: 'CSS color for point circles',
|
|
161
|
+
circleRadius: '0..30 circle radius in pixels',
|
|
162
|
+
circleOpacity: '0..1 circle opacity',
|
|
163
|
+
lineVisible: 'set false to hide the line/outline layer',
|
|
164
|
+
circleVisible: 'set false to hide the point-circle layer',
|
|
165
|
+
categorical: {
|
|
166
|
+
field: 'Attribute field for per-value fill colors',
|
|
167
|
+
values: 'Map of field value to {color, label}',
|
|
168
|
+
fallbackColor: 'Fill color used for values not present in the map',
|
|
169
|
+
},
|
|
170
|
+
opacity: '0..1 overall opacity hint for the layer',
|
|
171
|
+
label: {
|
|
172
|
+
field: 'Attribute field used as label text',
|
|
173
|
+
valueMap: 'Optional exact-value map, e.g. {"R":"住宅","C":"商业"}; unknown values use fallback/original',
|
|
174
|
+
fallback: 'Text used for values missing from valueMap; defaults to the original value',
|
|
175
|
+
size: '6..48 text size in pixels',
|
|
176
|
+
color: 'text color',
|
|
177
|
+
haloColor: 'halo color',
|
|
178
|
+
haloWidth: '0..4 halo width',
|
|
179
|
+
minzoom: '0..24 minimum zoom',
|
|
180
|
+
maxzoom: '0..24 maximum zoom',
|
|
181
|
+
allowOverlap: 'true to allow colliding labels',
|
|
182
|
+
onePerFeature: 'true to place exactly one centered label per feature (uses the largest polygon centroid)',
|
|
183
|
+
anchor: 'center|top|bottom|left|right|corner variants',
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
example: {
|
|
187
|
+
label: {
|
|
188
|
+
field: 'CODE',
|
|
189
|
+
valueMap: { Building: '建筑', Deck: '露台', Patio: '庭院' },
|
|
190
|
+
size: 12,
|
|
191
|
+
color: '#16423a',
|
|
192
|
+
haloColor: '#ffffff',
|
|
193
|
+
haloWidth: 1.2,
|
|
194
|
+
minzoom: 15,
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
fonts: DEFAULT_LABEL_FONT,
|
|
198
|
+
glyphsUrl: MAP_GLYPHS_URL,
|
|
199
|
+
};
|