| | |
| | | import coord from "@/components/poplayer/coord"; |
| | | import store from "@/utils/store"; |
| | | import mapData from "../../../static/mapData"; |
| | | import { liushisijiayuanqudizhibianmafuwu, findAddressCandidates, getDiKuanFanWei, ent_selectByName } from "../../api/api"; |
| | | import vueEvents from '@/utils/vueEvent.js' |
| | | let PoiLayerConstructor = Vue.extend(coord); |
| | | window.rpc = { |
| | | const rpc = { |
| | | timeout: 500, |
| | | url: "http://localhost:8999/RPC2", |
| | | method: "get_statue", |
| | | divPoint: null, |
| | | instance: null, |
| | |
| | | position: null, |
| | | marksIndex: null, |
| | | pitchValue: null, |
| | | //消息对接 |
| | | initMessage() { |
| | | var that = this; |
| | | window.addEventListener("message", res => { |
| | | if (res.data.status === "ok") { |
| | | console.log(res.data.params, "当前事件数据"); |
| | | // that.setLocation(); |
| | | unsubscribeTicks: null, |
| | | LineRoaming: null,//线路漫游 |
| | | dataQuery: [],//关键字查询结果 |
| | | pointerFly: null,//定点漫游 |
| | | isShow: false, |
| | | //关键字查询 |
| | | getFuzzyQuery(res) { |
| | | if (!res.baidu_keys) return |
| | | this.setClearAllMsg(); |
| | | if (this.dataQuery.length > 0) { |
| | | |
| | | if (res.message.indexOf('第') > -1 && res.message.indexOf('条') > -1) { |
| | | var data = mapData.msgMach.localPage |
| | | for (var i in data) { |
| | | if (res.message.indexOf(data[i]) > -1) { |
| | | |
| | | this.setClearAllMsg(); |
| | | setTimeout(() => { |
| | | vueEvents.$emit('queryLayer', true) |
| | | this.setLocation(this.dataQuery[i]) |
| | | return |
| | | }, 1000); |
| | | break; |
| | | } |
| | | } |
| | | } else { |
| | | for (var i in this.dataQuery) { |
| | | var name = this.dataQuery[i].name; |
| | | for (var j = 0; j < length; j++) { |
| | | var world = keyWorld[j].word; |
| | | if (name.indexOf(world) > -1) { |
| | | |
| | | this.setClearAllMsg(); |
| | | // setTimeout(() => { |
| | | vueEvents.$emit('queryLayer', true) |
| | | this.setLocation(this.dataQuery[i]) |
| | | break; |
| | | return |
| | | // }, 1000); |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | var keyWorld = res.baidu_keys.results; |
| | | console.log("baidu_keys", res.baidu_keys) |
| | | |
| | | if (keyWorld) { |
| | | var length = keyWorld.length; |
| | | vueEvents.$emit('queryLayer', false) |
| | | this.dataQuery = []; |
| | | for (var i = 0; i < length; i++) { |
| | | var world = keyWorld[i].word; |
| | | console.log("world", world) |
| | | this.setFuzzyQueryData(world, i, length - 1); |
| | | } |
| | | } |
| | | |
| | | }, |
| | | async setFuzzyQueryData(res, index, length) { |
| | | Promise.all([ |
| | | ent_selectByName(res),//企业 |
| | | liushisijiayuanqudizhibianmafuwu(res),//园区 |
| | | findAddressCandidates(res),//地块 |
| | | ]).then(result => { |
| | | var valdata = result[0]; |
| | | var valdata1 = result[1]; |
| | | if (valdata.length > 0) { |
| | | |
| | | } |
| | | if (valdata1.length > 0) { |
| | | |
| | | } |
| | | |
| | | }) |
| | | |
| | | |
| | | // var data = await |
| | | // if (data.candidates.length <= 0) { |
| | | // this.setClearAllMsg(); |
| | | // this.getLandmass(res) |
| | | // } else { |
| | | // this.getFuzzyQueryData(data.candidates, index, length, 1) |
| | | // } |
| | | }, |
| | | |
| | | getFuzzyQueryData(res, index, length, flag) { |
| | | if (!res || res.length <= 0) return |
| | | for (var i in res) { |
| | | if (this.dataQuery.length < 6) { |
| | | this.dataQuery.push(res[i]) |
| | | } |
| | | } |
| | | if (index == length) { |
| | | if (this.dataQuery.length <= 0) { |
| | | vueEvents.$emit('queryLayer', false) |
| | | return |
| | | } |
| | | |
| | | |
| | | store.queryLayer.data = this.dataQuery; |
| | | this.setClearAllMsg(); |
| | | vueEvents.$emit('queryLayer', true) |
| | | setTimeout(() => { |
| | | |
| | | this.setLocation(this.dataQuery[0]) |
| | | }, 1000); |
| | | } |
| | | }, |
| | | // 显示地块范围 |
| | | getLandmass(res) { |
| | | let that = this; |
| | | findAddressCandidates(res).then((locationInfo) => { |
| | | |
| | | |
| | | // if (locationInfo.candidates.length > 0) { |
| | | // // 划线 |
| | | // getDiKuanFanWei( |
| | | // locationInfo.candidates[0].location.x, |
| | | // locationInfo.candidates[0].location.y |
| | | // ).then((response) => { |
| | | // let center = { lon: 0, lat: 0 }; |
| | | // let polygon = that.read(response.geometry); |
| | | // if (polygon.length > 0) { |
| | | // var geometry = []; |
| | | // let points = polygon[0].split(","); |
| | | // for (let i = 0; i < points.length; i++) { |
| | | // let point = points[i].replace(/^\s+|\s+$/g, "").split(" "); |
| | | // center.lon += parseFloat(point[0]) / points.length; |
| | | // center.lat += parseFloat(point[1]) / points.length; |
| | | // geometry.push({ |
| | | // x: parseFloat(point[0]), |
| | | // y: parseFloat(point[1]), |
| | | // z: 0, |
| | | // }); |
| | | // } |
| | | // if (that.lacationLine) { |
| | | // sgworld.Creator.DeleteObject(that.lacationLine); |
| | | // line = null; |
| | | // } |
| | | // that.lacationLine = sgworld.Creator.createPolyline( |
| | | // geometry, |
| | | // "#ff0000", |
| | | // 1, |
| | | // 0, |
| | | // "线" |
| | | // ); |
| | | // } |
| | | // }); |
| | | |
| | | // var objdata = { |
| | | // POITYPE: "dikuaixinxi", |
| | | // name: locationInfo.candidates[0].attributes.QYMC, |
| | | // yijilei: locationInfo.candidates[0].attributes.yijilei, |
| | | // yongdixing: locationInfo.candidates[0].attributes["用地性"], |
| | | // // LXR: locationInfo.candidates[0].name, |
| | | // // DIZHI: locationInfo.candidates[0].address, |
| | | // lat: locationInfo.candidates[0].location.y, |
| | | // lon: locationInfo.candidates[0].location.x, |
| | | // }; |
| | | // // //添加定位弹窗 |
| | | // that.setAddPointLocation(objdata); |
| | | // // 弹框 |
| | | // console.log(objdata); |
| | | // debugger; |
| | | // } else { |
| | | // this.getAllEntity(res) |
| | | // } |
| | | }); |
| | | }, |
| | | async getAllEntity(res) { |
| | | var obj = { |
| | | request: "bdPoi", |
| | | query: res, |
| | | output: "json", |
| | | coord: "cgcs2000", |
| | | page_num: 0, |
| | | page_size: 20, |
| | | } |
| | | const data = await yzAdapter_Navigation(obj) |
| | | debugger |
| | | }, |
| | | read(wkt) { |
| | | var regExes = { |
| | | typeStr: /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/, |
| | | emptyTypeStr: /^\s*(\w+)\s*EMPTY\s*$/, |
| | | spaces: /\s+/, |
| | | parenComma: /\)\s*,\s*\(/, |
| | | doubleParenComma: /\)\s*\)\s*,\s*\(\s*\(/, // can't use {2} here |
| | | trimParens: /^\s*\(?(.*?)\)?\s*$/, |
| | | }; |
| | | /** |
| | | * Object with properties corresponding to the geometry types. Property values |
| | | * are functions that do the actual parsing. |
| | | * @private |
| | | */ |
| | | var parse$1 = { |
| | | /** |
| | | * Return point geometry given a point WKT fragment. |
| | | * |
| | | * @param {String} str A WKT fragment representing the point. |
| | | * @return {Point} A point geometry. |
| | | * @private |
| | | */ |
| | | point: function point(str) { |
| | | if (str === undefined) { |
| | | return []; |
| | | } |
| | | |
| | | var coords = str.trim().split(regExes.spaces); |
| | | return [Number.parseFloat(coords[0]), Number.parseFloat(coords[1])]; |
| | | }, |
| | | |
| | | /** |
| | | * Return a multipoint geometry given a multipoint WKT fragment. |
| | | * |
| | | * @param {String} str A WKT fragment representing the multipoint. |
| | | * @return {Point} A multipoint feature. |
| | | * @private |
| | | */ |
| | | multipoint: function multipoint(str) { |
| | | var this$1 = this; |
| | | |
| | | if (str === undefined) { |
| | | return []; |
| | | } |
| | | |
| | | var point; |
| | | var points = str.trim().split(","); |
| | | var components = []; |
| | | for (var i = 0, len = points.length; i < len; ++i) { |
| | | point = points[i].replace(regExes.trimParens, "$1"); |
| | | components.push(parse$1.point(point)); |
| | | } |
| | | return components; |
| | | }, |
| | | |
| | | /** |
| | | * Return a linestring geometry given a linestring WKT fragment. |
| | | * |
| | | * @param {String} str A WKT fragment representing the linestring. |
| | | * @return {LineString} A linestring geometry. |
| | | * @private |
| | | */ |
| | | linestring: function linestring(str) { |
| | | if (str === undefined) { |
| | | return []; |
| | | } |
| | | |
| | | var points = str.trim().split(","); |
| | | var components = []; |
| | | var coords; |
| | | for (var i = 0, len = points.length; i < len; ++i) { |
| | | coords = points[i].trim().split(regExes.spaces); |
| | | components.push([ |
| | | Number.parseFloat(coords[0]), |
| | | Number.parseFloat(coords[1]), |
| | | ]); |
| | | } |
| | | return components; |
| | | }, |
| | | |
| | | /** |
| | | * Return a linearring geometry given a linearring WKT fragment. |
| | | * |
| | | * @param {String} str A WKT fragment representing the linearring. |
| | | * @return {LinearRing} A linearring geometry. |
| | | * @private |
| | | */ |
| | | linearring: function linearring(str) { |
| | | if (str === undefined) { |
| | | return []; |
| | | } |
| | | |
| | | var points = str.trim().split(","); |
| | | var components = []; |
| | | var coords; |
| | | for (var i = 0, len = points.length; i < len; ++i) { |
| | | coords = points[i].trim().split(regExes.spaces); |
| | | components.push([ |
| | | Number.parseFloat(coords[0]), |
| | | Number.parseFloat(coords[1]), |
| | | ]); |
| | | } |
| | | return components; |
| | | }, |
| | | |
| | | /** |
| | | * Return a multilinestring geometry given a multilinestring WKT fragment. |
| | | * |
| | | * @param {String} str A WKT fragment representing the multilinestring. |
| | | * @return {MultiLineString} A multilinestring geometry. |
| | | * @private |
| | | */ |
| | | multilinestring: function multilinestring(str) { |
| | | var this$1 = this; |
| | | |
| | | if (str === undefined) { |
| | | return []; |
| | | } |
| | | |
| | | var line; |
| | | var lines = str.trim().split(regExes.parenComma); |
| | | var components = []; |
| | | for (var i = 0, len = lines.length; i < len; ++i) { |
| | | line = lines[i].replace(regExes.trimParens, "$1"); |
| | | components.push(parse$1.linestring(line)); |
| | | } |
| | | return components; |
| | | }, |
| | | |
| | | /** |
| | | * Return a polygon geometry given a polygon WKT fragment. |
| | | * |
| | | * @param {String} str A WKT fragment representing the polygon. |
| | | * @return {Polygon} A polygon geometry. |
| | | * @private |
| | | */ |
| | | polygon: function polygon(str) { |
| | | var this$1 = this; |
| | | |
| | | if (str === undefined) { |
| | | return []; |
| | | } |
| | | |
| | | var ring, linestring, linearring; |
| | | var rings = str.trim().split(regExes.parenComma); |
| | | var shell; |
| | | var holes = []; |
| | | //for (var i = 0, len = rings.length; i < len; ++i) { |
| | | ring = rings[0].replace(regExes.trimParens, "$1"); |
| | | linestring = ring; |
| | | //} |
| | | return linestring; |
| | | }, |
| | | |
| | | /** |
| | | * Return a multipolygon geometry given a multipolygon WKT fragment. |
| | | * |
| | | * @param {String} str A WKT fragment representing the multipolygon. |
| | | * @return {MultiPolygon} A multipolygon geometry. |
| | | * @private |
| | | */ |
| | | multipolygon: function multipolygon(str) { |
| | | var this$1 = this; |
| | | |
| | | if (str === undefined) { |
| | | return []; |
| | | } |
| | | |
| | | var polygon; |
| | | var polygons = str.trim().split(regExes.doubleParenComma); |
| | | var components = []; |
| | | for (var i = 0, len = polygons.length; i < len; ++i) { |
| | | polygon = polygons[i].replace(regExes.trimParens, "$1"); |
| | | components.push(parse$1.polygon(polygon)); |
| | | } |
| | | return components; |
| | | }, |
| | | }; |
| | | |
| | | var geometry, type, str; |
| | | wkt = wkt.replace(/[\n\r]/g, " "); |
| | | var matches = regExes.typeStr.exec(wkt); |
| | | if (wkt.search("EMPTY") !== -1) { |
| | | matches = regExes.emptyTypeStr.exec(wkt); |
| | | matches[2] = undefined; |
| | | } |
| | | if (matches) { |
| | | type = matches[1].toLowerCase(); |
| | | str = matches[2]; |
| | | if (parse$1[type]) { |
| | | geometry = parse$1[type].apply(this, [str]); |
| | | } |
| | | } |
| | | |
| | | if (geometry === undefined) { |
| | | throw new Error("Could not parse WKT " + wkt); |
| | | } |
| | | |
| | | return geometry; |
| | | }, |
| | | |
| | | |
| | | //地图复位 |
| | | setMapRest() { |
| | | const data = mapData.mapRest; |
| | | sgworld.Navigate.flyToPointsInterest({ |
| | | destination: { |
| | | "x": data.lng, |
| | | "y": data.lat, "z": data.alt |
| | | "y": data.lat, |
| | | "z": data.alt, |
| | | }, |
| | | orientation: { |
| | | heading: data.heading, |
| | | pitch: data.pitch, |
| | | roll: data.roll, |
| | | }, |
| | | duration: 5, //飞行时间8s |
| | | duration: 8, //飞行时间8s |
| | | }); |
| | | }, |
| | | |
| | | //动画导航 |
| | | setLineRoaming() { |
| | | var valdata = mapData.animaNavigation; |
| | | this.marksIndex = 1; |
| | | this.pitchValue = -20; |
| | | this.setShowPathLine(valdata); |
| | | var geom = []; |
| | | for (var i in valdata) { |
| | | geom.push(valdata[i].lng, valdata[i].lat, valdata[i].height) |
| | | } |
| | | |
| | | var that = this; |
| | | sgworld.Creator.getFlyData(geom, data => { |
| | | data.showPoint = false; |
| | | data.showLine = false; |
| | | data.mode = 1; |
| | | data.pitch = -10; |
| | | data.height = 75; |
| | | data.speed = 25; |
| | | |
| | | that.LineRoaming = sgworld.Creator.createDynamicObject(data, null, (res) => { |
| | | if (res.time >= res.Totaltime) { |
| | | that.setCloseLineRomaing(); |
| | | that.setMapRest() |
| | | |
| | | } |
| | | }) |
| | | }) |
| | | }, |
| | | //点击获取坐标 |
| | | clickToCoordinates() { |
| | |
| | | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); |
| | | }, |
| | | //定位弹窗 |
| | | setLocation() { |
| | | var data = mapData.pointPop; |
| | | setLocation(res) { |
| | | |
| | | var objdata = { |
| | | POITYPE: data.text, |
| | | SSDW: data.text, |
| | | LXR: data.text, |
| | | DIZHI: res, |
| | | lat: data.lat, |
| | | lon: data.lng |
| | | name: res.attributes.YQmingchen, |
| | | address: res.attributes.YQdizhi, |
| | | // LXR: res.name, |
| | | // DIZHI: res.address, |
| | | lat: res.location.y, |
| | | lon: res.location.x |
| | | }; |
| | | |
| | | //添加定位弹窗 |
| | | this.setAddPointLocation(objdata); |
| | | // //添加路径线 |
| | | // this.setShowPathLine(marks); |
| | | // //飞行漫游 |
| | | // window.Viewer.scene.camera.flyTo({ |
| | | // destination: Cesium.Cartesian3.fromDegrees( |
| | | // marks[0].lng, |
| | | // marks[0].lat, |
| | | // marks[0].height |
| | | // ), //定位坐标点,建议使用谷歌地球坐标位置无偏差 |
| | | // duration: 7 //定位的时间间隔 |
| | | // }); |
| | | // this.marksIndex = 1; |
| | | // this.pitchValue = -20; |
| | | // setTimeout(() => { |
| | | // this.setflyExtent(marks); |
| | | // }, 7000); |
| | | |
| | | }, |
| | | |
| | | setAddPointLocation(res) { |
| | | // 清除方法 |
| | | this.setClearPathlayer(); |
| | | store.setlocalLayerShowAction(false); |
| | | store.setlocalLayerListAction({}); |
| | | store.setlocalLayerShowAction(true); |
| | |
| | | ); |
| | | this.position = window.Viewer.entities.add({ |
| | | name: "FLYToMap", |
| | | position: Cesium.Cartesian3.fromDegrees(objdata.lon, objdata.lat), |
| | | position: Cesium.Cartesian3.fromDegrees(res.lon, res.lat, 200), |
| | | point: { |
| | | pixelSize: 1, |
| | | color: Cesium.Color.WHITE.withAlpha(0), |
| | |
| | | offset: { |
| | | heading: Cesium.Math.toRadians(0.0), |
| | | pitch: Cesium.Math.toRadians(-45), |
| | | range: 600 |
| | | } |
| | | range: 700 |
| | | }, |
| | | duration: 3 |
| | | }); |
| | | setTimeout(() => { |
| | | window.Viewer.entities.remove(this.position) |
| | | |
| | | }, 1000); |
| | | setTimeout(() => { |
| | | this.setPointFly(res) |
| | | }, 4000); |
| | | }, |
| | | setflyExtent(res) { |
| | | |
| | | if (this.unsubscribeTicks) { |
| | | window.Viewer.clock.onTick.removeEventListener(this.unsubscribeTicks); |
| | | this.unsubscribeTicks = null; |
| | | } |
| | | // 相机看点的角度,如果大于0那么则是从地底往上看,所以要为负值 |
| | | var pitch = Cesium.Math.toRadians(this.pitchValue); |
| | | // 时间间隔2秒钟 |
| | |
| | | window.Viewer.clock.stopTime |
| | | ) >= 0 |
| | | ) { |
| | | window.Viewer.clock.onTick.removeEventListener(Exection); |
| | | this.unsubscribeTicks = window.Viewer.clock.onTick.removeEventListener(Exection); |
| | | this.changeCameraHeading(res); |
| | | } |
| | | |
| | |
| | | } |
| | | window.Viewer.clock.onTick.addEventListener(Exection); |
| | | }, |
| | | setPointFly() { |
| | | var alll |
| | | = { lng: 116.802948, lat: 36.550064, height: 100, flytime: 15 } |
| | | setPointFly(res) { |
| | | var that = this; |
| | | this.pointerFly = window.sgworld.Analysis.setPointFly({ |
| | | position: Cesium.Cartesian3.fromDegrees(res.lon, res.lat, 200), |
| | | // scale: 0, |
| | | hideImage: true, |
| | | limitTime: true, |
| | | time: 4, |
| | | end: () => { |
| | | that.pointerFly = null |
| | | } |
| | | |
| | | window.sgworld.Analysis.setPointFly({ |
| | | position: Cesium.Cartesian3.fromDegrees(alll.lng, alll.lat, 50), |
| | | hideImage: false |
| | | }) |
| | | |
| | | }, |
| | | changeCameraHeading(res) { |
| | | |
| | | var nextIndex = this.marksIndex + 1; |
| | | if (this.marksIndex == res.length - 1) { |
| | | // 漫游完成 |
| | | this.setPointFly(res); |
| | | if (this.unsubscribeTicks) { |
| | | window.Viewer.clock.onTick.removeEventListener(this.unsubscribeTicks); |
| | | this.unsubscribeTicks = null; |
| | | } |
| | | return |
| | | } |
| | | // 计算两点之间的方向 |
| | |
| | | toDegrees(radians) { |
| | | return (radians * 180) / Math.PI; |
| | | }, |
| | | |
| | | |
| | | setExtentTime(time) { |
| | | var startTime = Cesium.JulianDate.fromDate(new Date()); |
| | | var stopTime = Cesium.JulianDate.addSeconds( |
| | |
| | | far: 50000 |
| | | }); |
| | | }, |
| | | |
| | | setClearPathlayer() { |
| | | //结束事件 |
| | | setClearAllMsg() { |
| | | if (this.divPoint) { |
| | | this.divPoint && this.divPoint.deleteObject(); |
| | | this.divPoint = null; |
| | |
| | | this.instance && this.instance.$destroy(); |
| | | this.instance = null; |
| | | } |
| | | // 轨迹线 |
| | | this.setClosePathLine(); |
| | | // 漫游 |
| | | this.setCloseLineRomaing(); |
| | | //定点漫游 |
| | | this.setClearPointFly() |
| | | vueEvents.$emit('queryLayer', false) |
| | | }, |
| | | setClearPointFly() { |
| | | if (this.pointerFly) { |
| | | this.pointerFly && this.pointerFly.end(); |
| | | this.pointerFly = null; |
| | | } |
| | | }, |
| | | setCloseLineRomaing() { |
| | | if (this.LineRoaming) { |
| | | this.LineRoaming && this.LineRoaming.exit(); |
| | | this.LineRoaming = null |
| | | } |
| | | }, |
| | | setClosePathLine() { |
| | | if (this.pathLayer) { |
| | | this.pathLayer && this.pathLayer.deleteObject(); |
| | | } |
| | | if (this.position) { |
| | | window.Viewer.entities.remove(this.position); |
| | | this.position = null; |
| | | } |
| | | } |
| | | }, |
| | | }; |
| | | export default rpc; |