123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- import { SParser } from "@persagy-web/big/lib";
- import fengmap from "fengmap";
- import Axios from "axios";
- export class SFengParser extends SParser {
- constructor(domId, mapServerURL, key, appName, factory, mapThemeURL) {
- super(factory);
- this.appName = "";
- this.mapId = "1000423_";
- this.domId = "";
- this.key = "";
- this.serverUrl = "./data/";
- this.mapThemeURL = "./";
- this.spaceType = [
- 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,
- 300004,
- 300005,
- 300006,
- 300007,
- 300008,
- 300009,
- 300010,
- 300011,
- 300012,
- 300013,
- 300014,
- 300015,
- 300016,
- 300017,
- 300018,
- 300019,
- 300020,
- 300021,
- 300022,
- 300023,
- 300024,
- 300025,
- 300026,
- 300027,
- 300028,
- 300029,
- 300030,
- 300031,
- 300032,
- 300033,
- 300034,
- 300035,
- 300036,
- 300037,
- 300038,
- 300039,
- 200023,
- 200022
- ];
- this.columnType = [300002];
- this.wallType = [300000, 300001];
- this.virtualWallType = [200001, 110001, 200010];
- this.poiList = [
- 170006,
- 170008,
- 170007,
- 170003,
- 170001,
- 100001,
- 100004,
- 100005,
- 100007,
- 140002,
- 170002,
- 150010,
- 100003,
- 140004,
- 170005,
- 120001,
- 120008,
- 120009,
- 120010
- ];
- this.gnameToGid = {};
- this.floorList = [];
- this.version = null;
- this.frImg = "";
- this.domId = domId;
- this.key = key;
- this.serverUrl = mapServerURL;
- this.mapThemeURL = mapThemeURL;
- this.appName = appName;
- }
- parseData(groupId, _fn) {
- let obj = {};
- this.fmap.focusGroupID = groupId;
- let searchAnalyser = new fengmap.FMSearchAnalyser(this.fmap);
- let searchReq = new fengmap.FMSearchRequest();
- const minx = this.fmap.minX;
- const maxy = this.fmap.maxY;
- searchReq.groupID = groupId;
- searchReq.type = "Model";
- searchAnalyser.query(searchReq, (result) => {
- let spaces = [], columns = [], walls = [], virtualWall = [], pList = [];
- result.forEach((t) => {
- if (t.target) {
- let type = t.typeID;
- if (t.target._data && t.target._data.vertices) {
- let arr = t.target._data.vertices, outline = [];
- for (let i = 0; i < arr.length - 1; i += 2) {
- outline.push({
- X: arr[i] - minx,
- Y: arr[i + 1] - maxy
- });
- }
- if (this.spaceType.indexOf(type) > -1) {
- spaces.push({
- OutLine: [outline],
- Name: t.target.name,
- Location: {
- Points: [this.getAverageVal([outline])]
- },
- Type: t.typeID,
- Tag: SFengParser.typeIdMap[t.typeID],
- SourceId: t.FID,
- Height: t.target.height
- });
- }
- else if (this.columnType.indexOf(type) > -1) {
- columns.push({ OutLine: [outline] });
- }
- else if (this.wallType.indexOf(type) > -1) {
- const hasHole = t.target._data.holes &&
- t.target._data.holes.length;
- let holes = [];
- if (hasHole) {
- let tempArr = t.target._data.holes;
- for (let j = 0; j < tempArr.length; j++) {
- let holeChild = [];
- for (let i = 0; i < tempArr[j].length - 1; i += 2) {
- holeChild.push({
- X: tempArr[j][i] - minx,
- Y: tempArr[j][i + 1] - maxy
- });
- }
- holes.push(holeChild);
- }
- }
- walls.push({ OutLine: [outline], HasHole: hasHole, Holes: holes });
- }
- else if (this.virtualWallType.indexOf(type) > -1) {
- virtualWall.push({ OutLine: [outline] });
- }
- }
- if (this.poiList.indexOf(type) > -1) {
- pList.push({
- Name: t.target.name,
- Pos: {
- X: t.mapCoord.x - minx,
- Y: t.mapCoord.y - maxy
- },
- Type: t.typeID,
- Tag: SFengParser.typeIdMap[t.typeID],
- Height: t.target.height,
- SourceId: t.ID
- });
- }
- }
- });
- obj = {
- Spaces: spaces,
- Columns: columns,
- Walls: walls,
- VirtualWalls: virtualWall,
- PList: pList
- };
- _fn(obj);
- });
- }
- loadMap(mapId, _fn) {
- this.fmap = new fengmap.FMMap({
- container: document.getElementById(this.domId),
- mapServerURL: this.serverUrl,
- appName: this.appName,
- key: this.key,
- mapThemeURL: this.mapThemeURL,
- defaultThemeName: mapId
- });
- this.fmap.openMapById(mapId, (err) => {
- console.log("错误信息", err);
- });
- this.fmap.on("loadComplete", () => {
- if (this.mapId != mapId) {
- this.mapId = mapId;
- this.gnameToGid = {};
- this.floorList = [];
- this.fmap.listGroups.forEach(t => {
- this.gnameToGid[t.gname] = t.gid;
- this.floorList.push(t);
- });
- }
- _fn(this.gnameToGid, this.floorList);
- });
- }
- loadTheme(url) {
- return new Promise((resolve, reject) => {
- Axios({
- method: "get",
- url: url
- })
- .then((res) => {
- this.mapTheme = res.data;
- let data = res.data.storetheme;
- this.frImg = data[data.length - 1].image;
- resolve(this.frImg);
- })
- .catch((res) => {
- console.log(res);
- });
- });
- }
- loadFloor(groupId, _fn) {
- const minx = this.fmap.minX;
- const maxy = this.fmap.maxY;
- this.fmap.getDatasByAlias(Number(groupId), "extent", (res) => {
- let index = res.gdata.geo.indexOf("(");
- let str = res.gdata.geo.substring(index);
- str = str.replace(/\(/g, "[");
- str = str.replace(/\)/g, "]");
- str = str.replace(/\s/g, ",");
- const arr = JSON.parse(str);
- const aaa = [];
- for (let i = 0; i < arr.length; i++) {
- let a = arr[i];
- const bbb = [];
- for (let j = 0; j < a.length; j++) {
- let b = a[j];
- const ccc = [];
- for (let k = 0; k < b.length - 1; k += 2) {
- ccc.push({
- X: b[k] - minx,
- Y: b[k + 1] - maxy
- });
- }
- bbb.push(ccc);
- }
- aaa.push(bbb);
- }
- _fn({ OutLine: aaa });
- });
- }
- getAverageVal(Outline) {
- 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
- };
- }
- }
- SFengParser.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",
- 300005: "SwitchingStation",
- 300006: "DistributionRoom",
- 300007: "StrongElectricWell",
- 300008: "WeakCurrentWell",
- 300009: "AirConditionerEngineRoom",
- 300010: "RefrigerationRoom",
- 300011: "FreshAirRoom",
- 300012: "CompressorRoom",
- 300013: "HeatSourceMachineRoom",
- 300014: "DomesticWaterPumpHouse",
- 300015: "HighLevelWaterTankRoom",
- 300016: "SewageTreatmentRoom",
- 300017: "FirePumpHouse",
- 300018: "WetAlarmValveChamber",
- 300019: "PreActionAlarmValveChamber",
- 300020: "AirSupplyRoom",
- 300021: "ExhaustFanRoom",
- 300022: "MakeUpAirRoom",
- 300023: "BusinessManagementOffice",
- 300024: "NetworkRoom",
- 300025: "Substation",
- 300026: "GeneratorRoom",
- 300027: "TrusteeshipRoom",
- 300028: "HuiyunMachineRoom",
- 300029: "AlarmValveChamber",
- 300030: "ReclaimedWaterMachineRoom",
- 300031: "FireControlRoom",
- 300032: "OilSeparator",
- 300033: "GasBoilerRoom",
- 300034: "GasMeterRoom",
- 300035: "ElevatorMachineRoom",
- 300036: "StaffRestaurant",
- 300037: "DryGarbageRoom",
- 300038: "WetGarbageRoom",
- 300039: "ExpansionWaterTankRoom",
- 200023: "MensBathroom",
- 200022: "WomensToilet"
- };
|