import { point, Position } from "@turf/turf"; interface IPointServer { latitude: number; longitude: number; name: string; pointType: number; uid: string; } class PointModel { lng!: number; lat!: number; copyFromPoint(p: PointModel) { Object.assign(this, p); return this; } name!: string; id!: string; type!: number; isDeleted = false; /** * 是否是当前道路的起始点 */ isRoadBeginPoint = false; /** * 是否是当前道路的结束点 */ isRoadEndPoint = false; /** * 渲染时是否是当前在编辑的道路上的,不是的话会有透明度 */ isOnRoad = false; active = false; text = ""; setText(text: string) { this.text = text; return this; } /** * 获取 turf 对象 */ toTurf() { return point([this.lng, this.lat]); } getLngLatString() { return this.lng + "," + this.lat; } getPosArray() { return [this.lng, this.lat]; } getPosition(): Position { return [this.lng, this.lat]; } toServerJson(): IPointServer { const result: IPointServer = { latitude: this.lat, longitude: this.lng, name: this.name, pointType: this.type, uid: this.id, }; return result; } fromServerJson(json: any) { this.lat = json.latitude; this.lng = json.longitude; this.name = json.name; this.type = json.pointType; this.id = json.uid; return this; } isInBounds(bounds: number[][]) { return this.lng > bounds[0][0] && this.lng < bounds[1][0] && this.lat > bounds[0][1] && this.lat < bounds[1][1]; } } export default PointModel;