| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- import { SItemFactory, SParser } from "@saga-web/big/lib";
- // @ts-ignore
- import fengmap from "fengmap";
- import { Space } from "@saga-web/big/lib/types/floor/Space";
- import { Column } from "@saga-web/big/lib/types/floor/Column";
- import { VirtualWall } from "@saga-web/big/lib/types/floor/VirtualWall";
- import { Wall } from "@saga-web/big/lib/types/floor/Wall";
- /**
- * 蜂鸟数据解析器
- *
- */
- export class SFengParser extends SParser {
- /** typeId对应的类型 */
- static typeIdMap = {
- 100000: "Pavement",
- 200000: "FrontagePavement",
- 900000: "AuxiliarySurface",
- 300000: "SolidWall",
- 300001: "GlassWall",
- 300003: "PartitionWall",
- 300002: "BearingColumn",
- 800000: "ParkingSpace",
- 200004: "StraightLadder",
- 200003: "Escalator",
- 200103: "UplinkOnly",
- 200203: "DownOnly",
- 200005: "Stairs",
- 200002: "Toilet",
- 200001: "EntranceAndExit",
- 200006: "Cashier",
- 200007: "ATM",
- 200017: "AlarmPoint",
- 200018: "DressModification",
- 200019: "JewelryRepair",
- 200020: "Checkroom",
- 200014: "InformationDesk",
- 200009: "PublicPhone",
- 200008: "ServiceCentre",
- 200010: "Exit",
- 200011: "CargoLift",
- 200012: "Lounge",
- 200013: "CarPark",
- 200015: "MotherBabyRoom",
- 200016: "VIP",
- 200021: "WheelchairAccessible",
- 170006: "StraightLadder",
- 170008: "UpEscalator",
- 170007: "DownEscalator",
- 170003: "Escalator",
- 170001: "Stairs",
- 110001: "EntranceAndExit",
- 100001: "Restroom",
- 100004: "MenRestroom",
- 100005: "WomenRestroom",
- 100007: "AccessibleToilet",
- 140002: "ServiceCentre",
- 170002: "CargoLift",
- 150010: "Lounge",
- 100003: "MotherBabyRoom",
- 140004: "VIP",
- 170005: "WheelchairAccessible",
- 120001: "CarPark",
- 120008: "ParkingExit",
- 120009: "ParkingEntrance",
- 120010: "ParkingExitAndEntrance"
- };
- /** 蜂鸟:底图应用名称 */
- appName: string = "";
- /** 当前蜂鸟map的id */
- currentMapId: string = "";
- /** 蜂鸟map绑定dom的id */
- domId: string = "";
- /** 蜂鸟:底图应用秘钥 */
- key: string = "";
- /** 底图服务器地址 */
- serverUrl: string = "./data/";
- /** 蜂鸟图 */
- private readonly fmap: fengmap.FMMap;
- /** 属于空间类型typeid */
- spaceType: number[] = [
- 100000,
- 200000,
- 900000,
- 800000,
- 200004,
- 200003,
- 200103,
- 200203,
- 200005,
- 200002,
- 200006,
- 200007,
- 200017,
- 200018,
- 200019,
- 200020,
- 200014,
- 200009,
- 200008,
- 200011,
- 200012,
- 200013,
- 200015,
- 200016,
- 200021,
- 170006,
- 170008,
- 170007,
- 170003,
- 170001,
- 100001,
- 100004,
- 100005,
- 100007,
- 140002,
- 170002,
- 150010,
- 100003,
- 140004,
- 170005,
- 120001
- ];
- /** 属于柱子类型的typeid */
- columnType: number[] = [300002];
- /** 属于墙类型的typeid */
- wallType: number[] = [300000, 300001];
- /** 属于虚拟墙类型的typeid */
- virtualWallType: number[] = [
- 200001,
- 110001,
- 200010,
- 120008,
- 120009,
- 120010
- ];
- /** 构造体 */
- constructor(
- domId: string,
- mapServerURL: string,
- key: string,
- appName: string,
- factory: SItemFactory
- ) {
- super(factory);
- this.domId = domId;
- this.key = key;
- this.serverUrl = mapServerURL;
- this.appName = appName;
- this.fmap = new fengmap.FMMap({
- container: document.getElementById(this.domId),
- mapServerURL: this.serverUrl,
- appName: this.appName,
- key: this.key
- });
- } // Constructor
- /**
- * 解析数据
- *
- * @param currentMapId 当前模型id
- * @param groupId 当前楼层
- * @param _fn 查询成功回调函数(返回参数为FloorData)
- * */
- parseData(currentMapId: string, groupId: string, _fn: Function): void {
- this.fmap.openMapById(currentMapId, (err: any) => {
- console.log("错误信息", err);
- });
- this.fmap.on("loadComplete", () => {
- let obj = {};
- // 创建搜索分析对象
- let searchAnalyser = new fengmap.FMSearchAnalyser(this.fmap);
- // 创建搜索请求体对象
- let searchReq = new fengmap.FMSearchRequest();
- searchReq.groupID = groupId;
- searchReq.type = "Model";
- searchAnalyser.query(searchReq, (result: any) => {
- let spaces: Space[] = [],
- columns: Column[] = [],
- walls: Wall[] = [],
- virtualWall: VirtualWall[] = [];
- result = result
- .map((t: any) => {
- if (
- t.target &&
- t.target._data &&
- t.target._data.vertices
- ) {
- let arr = t.target._data.vertices,
- type = t.typeID,
- outline = [];
- for (let i = 0; i < arr.length - 1; i += 2) {
- outline.push({
- X: arr[i] - 12982584.99,
- Y: arr[i + 1] - 4911901.56
- });
- }
- if (this.spaceType.indexOf(type) > -1) {
- spaces.push({
- // @ts-ignore
- OutLine: [outline],
- Name: t.target.name,
- Location: {
- // @ts-ignore
- Points: [this.getAverageVal([outline])]
- },
- Type: t.typeID
- });
- } else if (this.columnType.indexOf(type) > -1) {
- // @ts-ignore
- columns.push({ OutLine: [outline] });
- } else if (this.wallType.indexOf(type) > -1) {
- // @ts-ignore
- walls.push({ OutLine: [outline] });
- } else if (
- this.virtualWallType.indexOf(type) > -1
- ) {
- // @ts-ignore
- virtualWall.push({ OutLine: [outline] });
- }
- }
- })
- .filter((item: any) => item);
- obj = {
- Spaces: spaces,
- Columns: columns,
- Walls: walls,
- VirtualWalls: virtualWall
- };
- _fn(obj);
- });
- });
- }
- /**
- * 计算平均值
- *
- * @param Outline 轮廓线束
- * @return object {X:X,Y:Y}x的平均值,y的平均值
- * */
- private getAverageVal(Outline: { X: number; Y: number }[][]): object {
- let X = 0,
- Y = 0,
- len = Outline[0].length;
- Outline[0].map(item => {
- X += item.X;
- Y += item.Y;
- });
- X = Number((X / len).toFixed(2));
- Y = Number((Y / len).toFixed(2));
- return {
- X: X,
- Y: Y
- };
- }
- } // class SEquipParser
|