feat(workbench): align v2 GIS and SCADA API
This commit is contained in:
@@ -6,19 +6,20 @@ import {
|
||||
SCADA_ANALYSIS_SOURCE_ID,
|
||||
createEmptyScadaAnalysisCollection
|
||||
} from "./scada-analysis";
|
||||
import { SCADA_SOURCE_ID } from "./scada";
|
||||
|
||||
export const WATER_NETWORK_GLOBAL_VIEW = {
|
||||
bbox3857: [13508801.930066336, 3608163.3499832638, 13555650.638648884, 3633685.137885742]
|
||||
bbox3857: [13508801.930066336, 3608163.3499832638, 13555650.638648884, 3633685.137885742],
|
||||
bbox4326: [121.35162408429075, 30.81049932304578, 121.77248479490075, 31.007207809222017]
|
||||
} as const;
|
||||
|
||||
export const SOURCE_LAYERS = {
|
||||
pipes: "geo_pipes_mat",
|
||||
junctions: "geo_junctions_mat",
|
||||
valves: "geo_valves",
|
||||
reservoirs: "geo_reservoirs",
|
||||
scada: "geo_scada",
|
||||
pumps: "geo_pumps",
|
||||
tanks: "geo_tanks"
|
||||
pipes: "pipes",
|
||||
junctions: "junctions",
|
||||
valves: "valves",
|
||||
reservoirs: "reservoirs",
|
||||
pumps: "pumps",
|
||||
tanks: "tanks"
|
||||
} as const;
|
||||
|
||||
export const WATER_NETWORK_SOURCE_IDS = [
|
||||
@@ -35,7 +36,7 @@ export type WaterNetworkSourceId = (typeof WATER_NETWORK_SOURCE_IDS)[number];
|
||||
|
||||
export type SupplyLayerCatalogItem = {
|
||||
id: WaterNetworkSourceId;
|
||||
sourceLayer: (typeof SOURCE_LAYERS)[WaterNetworkSourceId];
|
||||
sourceLayer?: (typeof SOURCE_LAYERS)[keyof typeof SOURCE_LAYERS];
|
||||
geometry: "line" | "point";
|
||||
available: boolean;
|
||||
label: string;
|
||||
@@ -77,7 +78,7 @@ export const SUPPLY_LAYER_CATALOG = [
|
||||
},
|
||||
{
|
||||
id: "scada",
|
||||
sourceLayer: SOURCE_LAYERS.scada,
|
||||
sourceLayer: undefined,
|
||||
geometry: "point",
|
||||
available: true,
|
||||
label: "SCADA",
|
||||
@@ -87,7 +88,7 @@ export const SUPPLY_LAYER_CATALOG = [
|
||||
id: "pumps",
|
||||
sourceLayer: SOURCE_LAYERS.pumps,
|
||||
geometry: "point",
|
||||
available: false,
|
||||
available: true,
|
||||
label: "水泵",
|
||||
icon: "pump"
|
||||
},
|
||||
@@ -95,7 +96,7 @@ export const SUPPLY_LAYER_CATALOG = [
|
||||
id: "tanks",
|
||||
sourceLayer: SOURCE_LAYERS.tanks,
|
||||
geometry: "point",
|
||||
available: false,
|
||||
available: true,
|
||||
label: "水箱",
|
||||
icon: "tank"
|
||||
}
|
||||
@@ -103,12 +104,14 @@ export const SUPPLY_LAYER_CATALOG = [
|
||||
|
||||
export const AVAILABLE_WATER_NETWORK_SOURCE_IDS = SUPPLY_LAYER_CATALOG.filter(
|
||||
(layer) => layer.available
|
||||
).map((layer) => layer.id) as Extract<
|
||||
WaterNetworkSourceId,
|
||||
"pipes" | "junctions" | "valves" | "reservoirs" | "scada"
|
||||
>[];
|
||||
).map((layer) => layer.id) as WaterNetworkSourceId[];
|
||||
|
||||
export type AvailableWaterNetworkSourceId = (typeof AVAILABLE_WATER_NETWORK_SOURCE_IDS)[number];
|
||||
export type GeoServerWaterNetworkSourceId = Exclude<AvailableWaterNetworkSourceId, "scada">;
|
||||
|
||||
export const GEOSERVER_WATER_NETWORK_SOURCE_IDS = AVAILABLE_WATER_NETWORK_SOURCE_IDS.filter(
|
||||
(sourceId): sourceId is GeoServerWaterNetworkSourceId => sourceId !== "scada"
|
||||
);
|
||||
|
||||
export function isAvailableWaterNetworkSourceId(
|
||||
value: string
|
||||
@@ -118,11 +121,12 @@ export function isAvailableWaterNetworkSourceId(
|
||||
|
||||
export function createWaterNetworkSources() {
|
||||
return Object.fromEntries(
|
||||
SUPPLY_LAYER_CATALOG.filter((layer) => layer.available).map((layer) => [
|
||||
layer.id,
|
||||
createGeoServerVectorSource(layer.sourceLayer)
|
||||
])
|
||||
) as Record<AvailableWaterNetworkSourceId, VectorSourceSpecification>;
|
||||
SUPPLY_LAYER_CATALOG.flatMap((layer) =>
|
||||
layer.available && layer.sourceLayer !== undefined
|
||||
? [[layer.id, createGeoServerVectorSource(layer.sourceLayer)] as const]
|
||||
: []
|
||||
)
|
||||
) as Record<GeoServerWaterNetworkSourceId, VectorSourceSpecification>;
|
||||
}
|
||||
|
||||
function createGeoServerVectorSource(
|
||||
@@ -135,12 +139,18 @@ function createGeoServerVectorSource(
|
||||
`${MAP_URL}/gwc/service/wmts/rest/${GEOSERVER_WORKSPACE}:${sourceLayer}/WebMercatorQuad/{z}/{y}/{x}?format=application/vnd.mapbox-vector-tile`
|
||||
],
|
||||
minzoom: 0,
|
||||
maxzoom: 24
|
||||
maxzoom: 24,
|
||||
bounds: [...WATER_NETWORK_GLOBAL_VIEW.bbox4326]
|
||||
};
|
||||
}
|
||||
|
||||
export function createBaseStyle(mapboxToken?: string): StyleSpecification {
|
||||
const sources: StyleSpecification["sources"] = {
|
||||
[SCADA_SOURCE_ID]: {
|
||||
type: "geojson",
|
||||
promoteId: "device_id",
|
||||
data: { type: "FeatureCollection", features: [] }
|
||||
},
|
||||
[SCADA_ANALYSIS_SOURCE_ID]: {
|
||||
type: "geojson",
|
||||
data: createEmptyScadaAnalysisCollection()
|
||||
|
||||
Reference in New Issue
Block a user