import { MockMap } from "./MockMap"; import { IFeatureSource } from "../../sourceDefinition/LolOpenLayersSourceDef"; import { geogCoordinatesToMetres, geometryLimits, shapeCentre, } from "../../utils/Measure"; import { cloneDeep } from "lodash-es"; class MockGeometry { geometry: Record; constructor(geometry: Record) { this.geometry = geometry; } public getExtent = () => geometryLimits(this.geometry); public getType = () => this.geometry.type; public getInteriorPoint = () => ({ getFlatCoordinates: () => shapeCentre(this) ?? [], }); public getFlatMidpoint = () => shapeCentre(this) ?? []; } export class MockFeature { attributes = {} as Record; mockMap: MockMap; layerName: string; constructor( mockMap: MockMap, layerName: string, attributes: Record ) { this.attributes = cloneDeep(attributes); if (this.attributes.shape?.geometry?.coordinates) { this.attributes.shape.geometry.coordinates = geogCoordinatesToMetres( this.attributes.shape.geometry.coordinates ); } this.mockMap = mockMap; this.layerName = layerName; } public get = (propName: string) => this.attributes[propName]; public getId = () => this.attributes.id; public getProperties = () => this.attributes; public getGeometry = () => new MockGeometry(this.attributes.shape.geometry); } export const mockVTFeatureLoad = ( mockMap: MockMap, featureLayers: Record ) => Object.fromEntries( Object.entries(featureLayers).map(([layerName, layerFeatures]) => [ layerName, layerFeatures.map((f) => new MockFeature(mockMap, layerName, f)), ]) ); export const mockVTFeatures = (mockMap: MockMap) => { const featureLayers = { viw_parcel_all: [ { id: 1, toc_code: "PRIM", parcel_intent: "FSIM", status: "CURR", shape: { geometry: { type: "Polygon", coordinates: [ [ [10.9908204333, -45.0690057167], [10.9912843167, -45.0692283167], [10.9914138, -45.0690879333], [10.9909919833, -45.0688538333], [10.9909128667, -45.0689238667], [10.9908204333, -45.0690057167], ], ], }, }, }, { id: 2, toc_code: "SECO", parcel_intent: "EASM", status: "CURR", shape: { geometry: { type: "Polygon", coordinates: [ [ [10.9905204333, -45.0690057167], [10.9909843167, -45.0692283167], [10.9911138, -45.0690879333], [10.9906919833, -45.0688538333], [10.9906128667, -45.0689238667], [10.9905204333, -45.0690057167], ], ], }, }, }, ], underlying_marks: [ { id: 100, node_id: 10100, name: "Node100", shape: { geometry: { type: "Point", coordinates: [10.9905204333, -45.0690057167], }, }, }, { id: 101, node_id: 10101, name: "Node101", shape: { geometry: { type: "Point", coordinates: [10.9909843167, -45.0692283167], }, }, }, ], }; return mockVTFeatureLoad(mockMap, featureLayers); };