-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTilequeryTool.output.schema.ts
More file actions
83 lines (76 loc) · 2.53 KB
/
Copy pathTilequeryTool.output.schema.ts
File metadata and controls
83 lines (76 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.
import { z } from 'zod';
// Coordinate pair schema
const CoordinatesSchema = z.tuple([z.number(), z.number()]);
// Vector Tileset Feature Schema
const VectorTilequeryFeatureSchema = z.object({
type: z.literal('Feature'),
id: z
.union([z.string(), z.number()])
.describe('Feature identifier (string or number per GeoJSON spec)'),
geometry: z.object({
type: z.literal('Point'),
coordinates: CoordinatesSchema
}),
properties: z
.object({
tilequery: z.object({
distance: z
.number()
.describe(
'Approximate surface distance from feature to queried point, in meters'
),
geometry: z
.enum(['point', 'linestring', 'polygon'])
.describe('Original geometry type of the feature'),
layer: z
.string()
.describe('The vector tile layer of the feature result')
})
})
.and(z.record(z.string(), z.any())) // Allow additional properties from the original feature
});
// Rasterarray Tileset Feature Schema
const RasterarrayTilequeryFeatureSchema = z.object({
type: z.literal('Feature'),
id: z.null(),
geometry: z.object({
type: z.literal('Point'),
coordinates: CoordinatesSchema
}),
properties: z.object({
tilequery: z.object({
layer: z.string().describe('The layer that the feature belongs to'),
band: z.string().describe('The band that the feature belongs to'),
zoom: z
.number()
.describe('The maxzoom level at which the point value was extracted'),
units: z.string().describe('The unit of measurement for the point value')
}),
val: z
.union([z.number(), z.array(z.number())])
.describe(
'Point value at the requested location (number for single-band, array for multi-dimensional data)'
)
})
});
// Union of both feature types
const TilequeryFeatureSchema = z.union([
VectorTilequeryFeatureSchema,
RasterarrayTilequeryFeatureSchema
]);
// Main Tilequery Response Schema
export const TilequeryResponseSchema = z.object({
type: z.literal('FeatureCollection'),
features: z.array(TilequeryFeatureSchema)
});
// Type exports inferred from Zod schemas
export type VectorTilequeryFeature = z.infer<
typeof VectorTilequeryFeatureSchema
>;
export type RasterarrayTilequeryFeature = z.infer<
typeof RasterarrayTilequeryFeatureSchema
>;
export type TilequeryFeature = z.infer<typeof TilequeryFeatureSchema>;
export type TilequeryResponse = z.infer<typeof TilequeryResponseSchema>;