| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776 |
- import * as mars3d from "@/static/lib/mars3d/mars3d.js"
- import * as Cesium from "@/static/lib/Cesium/Cesium.js"
- import * as turf from '@turf/turf'
- import getMapJson from "@/utils/mapjson";
- let refId
- let maps, smallMap
- let graphicLayer
- let uav //飞行器
- let position
- let lineToGroundLayer
- let lineGraphic //连接地面的线
- let wayPointList = [] // 航点数组
- let waylinePositions = [] //需要连线的坐标111
- let line //航线
- let groundLineList = []
- let polygon, graphic
- let isEdit = false
- let isIngraphic = false
- let targetPoint = null
- let targetHeight = null
- let isleft = false
- let boundgraphic = null
- let workLayer
- let clockTimer = null
- function getActionParam(type, params) {
- // console.log(type, params,4444)
- let actionType = {
- orientedShoot: {
- type: 'orientedShoot',
- name: '定向拍照',
- actionTriggerType: 'reachPoint',
- svg: 'takePhoto',
- actionUUID: params['wpml:actionUUID'],
- fileType: params['wpml:payloadLensIndex'] == 'visable,ir' ? 3 : params['wpml:payloadLensIndex'] == 'visable' ? 1 : 2
- },
- startRecord: {
- type: 'startRecord',
- name: '开始录像',
- actionTriggerType: 'reachPoint',
- svg: 'startRecord',
- actionUUID: params['wpml:actionUUID'],
- fileType: params['wpml:payloadLensIndex'] == 'visable,ir' ? 3 : params['wpml:payloadLensIndex'] == 'visable' ? 1 : 2
- },
- stopRecord: {
- type: 'stopRecord',
- name: '停止录像',
- actionTriggerType: 'reachPoint',
- svg: 'stopRecord',
- actionUUID: params['wpml:actionUUID']
- },
- hover: {
- type: 'hover',
- name: '悬停',
- actionTriggerType: 'reachPoint',
- svg: 'hover',
- time: type == 'hover' ? params['wpml:hoverTime'] : '',
- actionUUID: params['wpml:actionUUID']
- },
- rotateYaw: {
- type: 'rotateYaw',
- name: '飞行器偏航角',
- actionTriggerType: 'reachPoint',
- svg: 'rotateYaw',
- uavRotate: type == 'rotateYaw' ? params['wpml:aircraftHeading'] : '',
- actionUUID: params['wpml:actionUUID']
- },
- gimbalRotate: {
- type: 'gimbalRotate',
- name: '云台俯仰角',
- actionTriggerType: 'reachPoint',
- svg: 'gimbalRotate',
- gimbalRotate: type == 'gimbalRotate' ? params['wpml:gimbalPitchRotateAngle'] : '',
- actionUUID: params['wpml:actionUUID']
- },
- zoom: {
- type: 'gimbalRotate',
- name: '变焦',
- actionTriggerType: 'zoom',
- svg: 'gimbalRotate',
- actionUUID: params['wpml:actionUUID']
- },
- takePhoto: {
- type: 'gimbalRotate',
- name: '变焦',
- actionTriggerType: 'zoom',
- svg: 'gimbalRotate',
- actionUUID: params['wpml:actionUUID']
- },
- panoShot: {
- type: 'panoShot',
- name: '全景拍照',
- actionTriggerType: 'panoShot',
- svg: 'panoShot',
- actionUUID: params['wpml:actionUUID']
- },
- ai: {
- type: 'ai',
- name: 'ai',
- actionTriggerType: 'ai',
- svg: 'ai',
- actionUUID: params['wpml:actionUUID']
- },
- }
- return actionType[type]
- }
- export function initLineMap() {
- maps = new mars3d.Map("wayline-main-map", getMapJson());
-
- workLayer = new mars3d.layer.GraphicLayer()
- graphicLayer = new mars3d.layer.GraphicLayer()
- lineToGroundLayer = new mars3d.layer.GraphicLayer()
- maps.addLayer(graphicLayer)
- maps.addLayer(lineToGroundLayer)
- maps.addLayer(workLayer)
- // addWmts(token)
- return maps
- }
- export function clearAll() {
- maps ? maps.graphicLayer.clear() : ''
- graphicLayer = null
- }
- export function closeMap() {
- waylineStore.distance = null
- waylineStore.wayPointList = []
- waylineStore.wayPointNum = 0
- waylineStore.workTime = ''
- waylineStore.qinxie_result = null //重置倾斜摄影总数据
- maps ? maps.graphicLayer.clear() : ''
- if (waylineStore.currentEditWayline && waylineStore.currentEditWayline.wayLineId) {
- waylineStore.currentEditWayline.wayLineId = null;
- }
- waylineStore.polygonList = []
- graphicLayer = null
- waylinePositions = []
- groundLineList = []
- uav = null
- lineGraphic = null
- clearInterval(clockTimer)
- if (maps) {
- maps.destroy()
- maps = null
- lineToGroundLayer = null
- }
- if (smallMap) {
- smallMap.destroy()
- smallMap = null
- }
- }
- export function initSmallMap(data) {
- smallMap = new mars3d.Map("view-map", setSmallMapScene());
- if (data) {
- smallMap.setCameraView(data)
- }
- window.smallMap = smallMap
- // addWmts(token)
- }
- export function flyToPoint({ lng, lat, alt }) {
- smallMap.flyToPoint(new mars3d.LngLatPoint(lng, lat, alt), {
- radius: 2000,
- heading: 12,
- alt: 936,
- pitch: -32.8
- });
- }
- export function changeSmallView(data) {
- smallMap.setCameraView(data)
- }
- export function setSmallMapScene() {
- let json = {
- scene: {
- center: {
- lat: 27.62,
- lng: 111.59,
- alt: 1336414,
- heading: 0,
- pitch: -90
- },
- fxaa: true, // 不开启抗锯齿,可视域会闪烁
- globe: {
- depthTestAgainstTerrain: true // 不加无法投射到地形上
- },
- contextOptions: {
- webgl: {
- preserveDrawingBuffer: true // 截图是黑色时,需要将该项设置为true
- }
- },
- requestRenderMode: true,
- cameraController: {
- zoomFactor: 2, // 相机缩放速度的乘数
- }
- },
- control: {
- contextmenu: { hasDefault: false } // 右键菜单
- },
- terrain: {
- url: "//data.mars3d.cn/terrain",
- show: true,
- },
- basemaps: [{
- name: '天地图卫星',
- icon: 'img/basemaps/tdt_img.jpg',
- type: 'tdt',
- layer: 'img_d',
- key: ['938106e971ecf05ce7355a3af2a58099'],
- show: true
- },
- { type: "gaode", layer: "img_z", show: true, zIndex: 12 }
- ],
- }
- return json
- }
- // 设置起飞点
- export function addTakeoffPoint() {
- maps.setSceneOptions({
- center: {
- lat: waylineStore.center.lat,
- lng: waylineStore.center.lng,
- alt: 2000,
- heading: 12,
- pitch: -85
- }
- })
- const graphic = new mars3d.graphic.BillboardEntity({
- position: new mars3d.LngLatPoint(waylineStore.center.lng, waylineStore.center.lat, waylineStore.center.alt),
- style: {
- image: "/assets/wayline/airport.png",
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- width: 60,
- height: 60,
- clampToGround: true,
- visibleDepth: false,
- scaleByDistance: false,
- scale: 0.8,
- zIndex: 200,
- }
- })
- graphicLayer.addGraphic(graphic)
- waylinePositions.push(graphic)
- //记录起飞点
- waylineStore.takeoffPoint = graphic
- let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
- waylineStore.takeoffPoint._position_draw
- ? waylineStore.takeoffPoint._position_draw
- : waylineStore.takeoffPoint._position
- );
- waylineStore.takeoffPointHeight = takeoffPoint._alt
- addUAV(graphic._position, ((uav) => {
- // // 罗盘旋转
- uav.on(mars3d.EventType.updateStyle, e => {
- waylineStore.heading = e.style.heading
- });
- }))
- }
- // 这里是添加面状航线
- export function addPolygonWayline() {
- maps.setSceneOptions({
- center: {
- lat: waylineStore.center.lat,
- lng: waylineStore.center.lng,
- alt: 2000,
- heading: 12,
- pitch: -85
- }
- })
- const graphic = new mars3d.graphic.BillboardEntity({
- position: new mars3d.LngLatPoint(waylineStore.center.lng, waylineStore.center.lat, waylineStore.center.alt),
- style: {
- image: "/assets/wayline/airport.png",
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- width: 60,
- height: 60,
- clampToGround: true,
- visibleDepth: false,
- scaleByDistance: false,
- scale: 0.8,
- zIndex: 200,
- }
- })
- graphicLayer.addGraphic(graphic)
- waylinePositions.push(graphic)
- //记录起飞点
- waylineStore.takeoffPoint = graphic
- let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
- waylineStore.takeoffPoint._position_draw
- ? waylineStore.takeoffPoint._position_draw
- : waylineStore.takeoffPoint._position
- );
- waylineStore.takeoffPointHeight = takeoffPoint._alt
- // addStartHigeht(takeoffPoint)
- //编辑面状航线
- drawPolygon()
- }
- async function drawPolygon() {
- polygon = maps.graphicLayer.startDraw({
- type: "polygon",
- style: {
- color: "#4786ef",
- opacity: 0.5,
- outline: false,
- outlineWidth: 3,
- outlineColor: "#ffffff",
- clampToGround: true,
- visibleDepth: false,
- zIndex: 299,
- label: {
- background: true,
- verticalOrigin: Cesium.VerticalOrigin.TOP,
- backgroundColor: '#000000',
- backgroundOpacity: 0.7,
- backgroundPadding: 10,
- text: "",
- font_size: 14,
- color: "#ffffff",
- clampToGround: true,
- visibleDepth: false,
- }
- },
- })
- maps.graphicLayer.on(mars3d.EventType.drawCreated, function (event) {
- waylineStore.Obliquephoto.pointsArr = event.positions
- event.positions.forEach(i => {
- waylineStore.polygonList.push(mars3d.LngLatPoint.fromCartesian(i))
- })
- if (waylineStore.currentEditWayline.wayLineType == 2) {
- showPolygonWayline()
- } else {
- startEditObliquephotographyline()
- }
- })
- }
- function showPolygonWayline() {
- if (line) {
- line.remove()
- }
- let coordinates = []
- waylineStore.polygonList.forEach(i => {
- let a = `${i._lng},${i._lat},0`
- coordinates.push(a)
- })
- waylineStore.currentEditWayline.kmzJSON.Document.Folder.Placemark.Polygon.outerBoundaryIs.LinearRing.coordinates = coordinates.join(' ')
- let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
- waylineStore.takeoffPoint._position_draw
- ? waylineStore.takeoffPoint._position_draw
- : waylineStore.takeoffPoint._position
- );
- waylineStore.currentEditWayline.kmzJSON.Document['wpml:missionConfig']['wpml:takeOffRefPoint'] =
- takeoffPoint._lat + "," + takeoffPoint._lng + "," + takeoffPoint._alt;
- waylineStore.currentEditWayline.kmzJSON.Document.Folder.Placemark['wpml:ellipsoidHeight'] = 80
- waylineStore.currentEditWayline.kmzJSON.Document.Folder.Placemark['wpml:height'] = 80
- let RESULT_MAP = generate2dwayline(waylineStore.currentEditWayline, "myMap")
- waylineStore.polygonResult = RESULT_MAP
- line = new mars3d.graphic.PolylinePrimitive({
- // asynchronous: false,
- positions: RESULT_MAP.PATH_ON_MAP,
- style: {
- width: 5,
- // color: "#0BD790",
- materialType: mars3d.MaterialType.LineFlow,
- materialOptions: {
- // color: "#0BD790",
- image: '/assets/wayline/line-interval2.png',
- repeat: new Cesium.Cartesian2(20, 1),
- speed: 1
- }
- }
- });
- if (!lineToGroundLayer) {
- lineToGroundLayer = new mars3d.layer.GraphicLayer();
- maps.addLayer(lineToGroundLayer);
- }
- lineToGroundLayer.addGraphic(line);
- }
- export function setPolygonWayline() {
- if (line) {
- line.remove()
- }
- let RESULT_MAP = generate2dwayline(waylineStore.currentEditWayline, "myMap")
- waylineStore.polygonResult = RESULT_MAP
- line = new mars3d.graphic.PolylinePrimitive({
- // asynchronous: false,
- positions: RESULT_MAP.PATH_ON_MAP,
- style: {
- width: 5,
- // color: "#0BD790",
- materialType: mars3d.MaterialType.LineFlow,
- materialOptions: {
- // color: "#0BD790",
- image: '/assets/wayline/line-interval2.png',
- repeat: new Cesium.Cartesian2(20, 1),
- speed: 1
- }
- }
- });
- if (!lineToGroundLayer) {
- lineToGroundLayer = new mars3d.layer.GraphicLayer();
- maps.addLayer(lineToGroundLayer);
- }
- lineToGroundLayer.addGraphic(line);
- }
- function addStartHigeht(takeoffPoint) {
- const graphic = new mars3d.graphic.LabelEntity({
- position: new mars3d.LngLatPoint(takeoffPoint._lng, takeoffPoint._lat, takeoffPoint.alt),
- style: {
- text: "高度" + takeoffPoint.alt,
- font_size: 46, // 字号放大一倍
- scale: 0.5, // scale传0.5
- font_family: "楷体",
- color: "#00ffff",
- outline: true,
- outlineColor: "#000000",
- outlineWidth: 2,
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- visibleDepth: false
- },
- })
- graphicLayer.addGraphic(graphic)
- }
- // 添加飞行器
- function addUAV(position, callback) {
- let copy = waylineStore.center
- let point = new mars3d.LngLatPoint(copy.lng, copy.lat, copy.alt);
- let point2 = new mars3d.LngLatPoint(copy.lng, copy.lat, 0);
- let height = 0
- mars3d.PointUtil.getSurfaceHeight(maps.scene, point).then(result => {
- height = result.height_original.toFixed(2) - result.height.toFixed(2);
- position = position
- let a = point2.toCartesian()
- //规定要初始默认 离地高度为120 则需要换算 120减去初始的离地高 这是差值 waylineStore.center.alt 是机巢初始的经纬度高 则初始经纬度高加上差值
- uav = new mars3d.graphic.ModelEntity({
- name: "警车",
- position: mars3d.PointUtil.addPositionsHeight(a, 120 - height + waylineStore.center.alt
- ),
- style: {
- url: "/assets/wayline/UAV.gltf",
- scale: 0.02,
- minimumPixelSize: 48,
- // minimumPixelSize: 1,
- heading: 0,
- pitch: 0,
- roll: 0,
- zIndex: 999,
- visibleDepth: false,
- },
- })
- graphicLayer.addGraphic(uav)
- waylineStore.UAVOptions = uav.options.position
- uav.flyTo({
- radius: 2000,
- heading: 12,
- alt: 936,
- pitch: -32.8
- });
- callback(uav)
- }
- );
- }
- export function updatePosition(keys) {
- if (refId) {
- window.cancelAnimationFrame(refId);
- }
- refId = window.requestAnimationFrame(() => {
- if (keys && keys.length > 0 && uav) {
- if (keys.indexOf('q') !== -1 || keys.indexOf('Q') !== -1) {
- let heading = uav.options.style.heading - 0.4;
- uav.setStyle({ heading: heading })
- }
- if (keys.indexOf('e') !== -1 || keys.indexOf('E') !== -1) {
- let heading = uav.options.style.heading + 0.4;
- uav.setStyle({ heading: heading })
- }
- if (keys.indexOf('w') !== -1 || keys.indexOf('W') !== -1) {
- let newPosition = mars3d.PointUtil.getPositionByDirectionAndLen(uav._position, uav.options.style.heading - 90, 1);
- uav.setOptions({ position: newPosition })
- position = newPosition;
- }
- if (keys.indexOf('s') !== -1 || keys.indexOf('S') !== -1) {
- let newPosition = mars3d.PointUtil.getPositionByDirectionAndLen(uav._position, uav.options.style.heading + 90, 1);
- uav.setOptions({ position: newPosition })
- position = newPosition;
- }
- if (keys.indexOf('a') !== -1 || keys.indexOf('A') !== -1) {
- let newPosition = mars3d.PointUtil.getPositionByDirectionAndLen(uav._position, uav.options.style.heading + 180, 1);
- uav.setOptions({ position: newPosition })
- position = newPosition;
- }
- if (keys.indexOf('d') !== -1 || keys.indexOf('D') !== -1) {
- let newPosition = mars3d.PointUtil.getPositionByDirectionAndLen(uav._position, uav.options.style.heading, 1);
- uav.setOptions({ position: newPosition })
- position = newPosition;
- }
- if (keys.indexOf('c') !== -1 || keys.indexOf('C') !== -1) {
- let newPosition = mars3d.PointUtil.addPositionsHeight(uav._position, 1);
- mars3d.PointUtil.getSurfaceHeight(maps.scene, mars3d.LngLatPoint.fromCartesian(newPosition)).then(result => {
- if (result.height_original.toFixed(2) - result.height.toFixed(2) > 150) {
- ElMessage({
- message: '已超出飞行高度',
- type: 'warning',
- plain: true,
- })
- return
- } else {
- uav.setOptions({ position: newPosition })
- position = newPosition;
- }
- })
- }
- if (keys.indexOf('z') !== -1 || keys.indexOf('Z') !== -1) {
- let newPosition = mars3d.PointUtil.addPositionsHeight(uav._position, -1);
- mars3d.PointUtil.getSurfaceHeight(maps.scene, mars3d.LngLatPoint.fromCartesian(newPosition)).then(result => {
- })
- uav.setOptions({ position: newPosition })
- position = newPosition;
- }
- updatePosition(keys);
- updateToGroundLine()
- waylineStore.UAVOptions = uav.options.position
- } else {
- window.cancelAnimationFrame(refId);
- }
- });
- }
- /**
- * @description 更新到地面的连接线
- *
- */
- function updateToGroundLine() {
- if (!lineGraphic) {
- lineToGroundLayer = new mars3d.layer.GraphicLayer();
- maps.addLayer(lineToGroundLayer);
- // let lonlatheight = GISUtils.cartesian3ToLonLatAlt(this.viewer, this.position);
- let p = mars3d.LngLatPoint.fromCartesian(uav != undefined ? uav._position : [])
- let a = [p._lng, p._lat, 0]
- lineGraphic = new mars3d.graphic.PolylinePrimitive({
- asynchronous: false,
- positions: [
- a,
- mars3d.PointUtil.addPositionsHeight(
- uav != undefined ? uav._position : [],
- )
- ],
- style: {
- width: 1,
- color: '#FFFF00',
- zIndex: 1,
- materialType: mars3d.MaterialType.PolylineDash, // 虚线
- materialOptions: {
- color: '#FFFF00',
- dashLength: 6
- }
- }
- });
- lineToGroundLayer.addGraphic(lineGraphic);
- } else {
- let newPosition = mars3d.LngLatPoint.fromCartesian(uav != undefined ? uav._position : []);
- let a = [newPosition._lng, newPosition._lat, 0]
- lineGraphic.setOptions({
- positions: [a, mars3d.PointUtil.addPositionsHeight(
- uav ? uav._position : [],
- )]
- })
- }
- }
- //鼠标双击添加航点
- export function dbClickAddWaypoint(data) {
- if (!lineToGroundLayer) {
- lineToGroundLayer = new mars3d.layer.GraphicLayer();
- maps.addLayer(lineToGroundLayer);
- }
- let point = mars3d.LngLatPoint.fromCartesian(data)
- let position = [point._lng, point._lat, uav._point._alt]
- const wayPoint = new mars3d.graphic.BillboardEntity({
- position: position,
- asynchronous: false,
- style: {
- image: '/assets/wayline/waypoint-active.png',
- // image: "img/wayline/dock.png",
- // image: dockImg,
- scale: 0.6,
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.CENTER,
- pixelOffset: [0, -16],
- highlight: {
- image: '/assets/wayline/waypoint-active.png'
- },
- // 新建航点字体设置
- label: {
- text: waylineStore.wayPointList.length > 0 ? waylineStore.wayPointList.length + 1 : 1,
- font_family: '微软雅黑',
- font_size: 16,
- color: '#FFFFFF',
- visibleDepth: false,
- pixelOffset: [0, -22]
- },
- zIndex: 201
- },
- attr: []
- })
- // 这块是判断航点是否与当前航线重合
- let checkLine = []
- let heightArr = []
- let ischeck = false;
- let isHeightHave = false
- let isPointOnCurPoints = false
- let points = [wayPoint._point._lng, wayPoint._point._lat]
- waylineStore.wayPointList.forEach(i => {
- let point = [i._point._lng, i._point._lat]
- checkLine.push(point)
- heightArr.push(i._point._alt)
- if (Math.abs(point[0] - points[0]) < 0.00001) {
- ischeck = true
- }
- })
- if (ischeck) {
- ElMessage({
- message: '飞机处于航点上,无法新增航点',
- type: 'warning',
- plain: true,
- })
- return
- }
- heightArr.forEach(i => {
- if (i == wayPoint._point._alt) {
- isHeightHave = true
- }
- })
- if (waylineStore.wayPointList.length >= 2) {
- isPointOnCurPoints = turf.booleanPointOnLine(turf.point(points), turf.lineString(checkLine))
- } else if (waylineStore.wayPointList.length == 1) {
- let point1 = turf.point([waylineStore.wayPointList[0]._point._lng, waylineStore.wayPointList[0]._point._lat])
- let point2 = turf.point(points)
- isPointOnCurPoints = turf.booleanEqual(point1, point2)
- }
- if (isPointOnCurPoints && isHeightHave) {
- ElMessage({
- message: '飞机处于航点上,无法新增航点',
- type: 'warning',
- plain: true,
- })
- return
- }
- // wayPointList.push(wayPoint)
- waylineStore.wayPointList.push(wayPoint)
- waylineStore.wayPoint = wayPoint
- waylineStore.wayPointNum = waylineStore.wayPointList.length
- graphicLayer.addGraphic(wayPoint)
- // waylinePositions.push(uav._position)
- updataWayPointStyle()
- lineWaypoint()
- wayPoint.on(mars3d.EventType.mouseOver, function (e) {
- isIngraphic = true
- targetPoint = e.graphic
- targetHeight = e.graphic._point._alt
- })
- wayPoint.on(mars3d.EventType.mouseOut, function (e) {
- isIngraphic = false
- targetPoint = null
- waylineStore.wayPoint = e.graphic
- chooseWayPoint(e.id)
- })
- }
- //添加航点
- export function addWaypoint() {
- if (!lineToGroundLayer) {
- lineToGroundLayer = new mars3d.layer.GraphicLayer();
- maps.addLayer(lineToGroundLayer);
- }
- let point = mars3d.LngLatPoint.fromCartesian(uav._position)
- let position = [point._lng, point._lat, point._alt]
- const wayPoint = new mars3d.graphic.BillboardEntity({
- position: position,
- asynchronous: false,
- style: {
- image: '/assets/wayline/waypoint-active.png',
- // image: "img/wayline/dock.png",
- // image: dockImg,
- scale: 0.6,
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.CENTER,
- visibleDepth: true,
- pixelOffset: [0, -16],
- highlight: {
- image: '/assets/wayline/waypoint-active.png'
- },
- // 新建航点字体设置
- label: {
- text: waylineStore.wayPointList.length > 0 ? waylineStore.wayPointList.length + 1 : 1,
- font_family: '微软雅黑',
- font_size: 20,
- color: '#FFFFFF',
- visibleDepth: false,
- pixelOffset: [0, -22]
- },
- zIndex: 201
- },
- attr: []
- })
- wayPoint.on(mars3d.EventType.click, (e) => {
- waylineStore.wayPoint = e.graphic
- chooseWayPoint(e.id)
- })
- // wayPointList.push(wayPoint)
- // 这块是判断航点是否与当前航线重合
- let checkLine = []
- let heightArr = []
- waylineStore.wayPointList.forEach(i => {
- let point = [i._point._lng, i._point._lat]
- checkLine.push(point)
- heightArr.push(i._point._alt)
- })
- let points = [wayPoint._point._lng, wayPoint._point._lat]
- let isPointOnCurPoints = false;
- let isHeightHave = false
- heightArr.forEach(i => {
- if (i == wayPoint._point._alt) {
- isHeightHave = true
- }
- })
- if (waylineStore.wayPointList.length >= 2) {
- isPointOnCurPoints = turf.booleanPointOnLine(turf.point(points), turf.lineString(checkLine))
- } else if (waylineStore.wayPointList.length == 1) {
- let point1 = turf.point([waylineStore.wayPointList[0]._point._lng, waylineStore.wayPointList[0]._point._lat])
- let point2 = turf.point(points)
- isPointOnCurPoints = turf.booleanEqual(point1, point2)
- }
- if (isPointOnCurPoints && isHeightHave) {
- ElMessage({
- message: '飞机处于航点上,无法新增航点',
- type: 'warning',
- plain: true,
- })
- return
- }
- waylineStore.wayPointList.push(wayPoint)
- waylineStore.wayPoint = wayPoint
- waylineStore.wayPointNum = waylineStore.wayPointList.length
- graphicLayer.addGraphic(wayPoint)
- updataWayPointStyle()
- lineWaypoint()
- wayPoint.on(mars3d.EventType.mouseOver, function (e) {
- isIngraphic = true
- targetPoint = e.graphic
- targetHeight = e.graphic._point._alt
- })
- wayPoint.on(mars3d.EventType.mouseOut, function (e) {
- isIngraphic = false
- targetPoint = null
- waylineStore.wayPoint = e.graphic
- chooseWayPoint(e.id)
- })
- }
- export function deleteWayPoint(id) {
- waylineStore.wayPointNum--
- waylineStore.wayPointList.forEach((i, index) => {
- if (i.id == id) {
- graphicLayer.getGraphicById(id).remove()
- waylineStore.wayPointList.splice(index, 1);
- lineWaypoint()
- updataWayPointStyle()
- }
- })
- // waylineStore.wayPointNum = waylineStore.wayPointList.length 11
- }
- export function chooseWayPoint(id) {
- waylineStore.wayPointList.forEach((i, index) => {
- if (i.id == id) {
- i.setStyle({ image: '/assets/wayline/waypoint-active.png' })
- eventBus.emit('changeIndex', index)
- } else {
- i.setStyle({ image: '/assets/wayline/waypoint.png' })
- }
- })
- }
- // 更新航点的状态
- function updataWayPointStyle() {
- waylineStore.wayPointList.forEach((i, index) => {
- if (index < waylineStore.wayPointList.length - 1) {
- i.setStyle({ image: '/assets/wayline/waypoint.png', label: { text: index + 1 } })
- } else {
- i.setStyle({ image: '/assets/wayline/waypoint-active.png', label: { text: index + 1 } })
- }
- })
- }
- // 把航点给连接起来 1航线!!
- function lineWaypoint() {
- if (line) {
- line.remove()
- }
- if (!lineToGroundLayer) {
- lineToGroundLayer = new mars3d.layer.GraphicLayer();
- maps.addLayer(lineToGroundLayer);
- }
- let positions = []
- let waylineList = [...waylinePositions, ...waylineStore.wayPointList]
- waylineList.forEach(i => {
- let newPosition = mars3d.LngLatPoint.fromCartesian(i.position);
- let a = [newPosition._lng, newPosition._lat, newPosition._alt]
- positions.push(a)
- })
- line = new mars3d.graphic.PolylinePrimitive({
- asynchronous: false,
- positions: positions,
- style: {
- width: 5,
- // color: "#0BD790",
- materialType: mars3d.MaterialType.LineFlow,
- visibleDepth: false,
- materialOptions: {
- // color: "#0BD790",
- image: '/assets/wayline/line-interval2.png',
- repeat: new Cesium.Cartesian2(20, 1),
- speed: 1
- }
- }
- });
- waylineStore.distance = mars3d.MeasureUtil.formatDistance(line.distance)
- // 计算首尾距离 添加总航程
- let start = positions[0]
- let end = positions[positions.length - 1]
- start[2] = 66
- end[2] = 66
- let backLinePosition = [start, end]
- let backLine
- backLine = new mars3d.graphic.PolylinePrimitive({
- asynchronous: false,
- positions: backLinePosition,
- style: {
- width: 5,
- // color: "#0BD790",
- materialType: mars3d.MaterialType.LineFlow,
- materialOptions: {
- // color: "#0BD790",
- image: '/assets/wayline/line-interval2.png',
- repeat: new Cesium.Cartesian2(20, 1),
- speed: 1
- }
- }
- });
- // 因为是直线返回 不计算高度问题 直接把首尾高度设为一致 随意值 只要一致就行
- waylineStore.backDistance = mars3d.MeasureUtil.formatDistance(backLine.distance)
- let time;
- let distance;
- let backDistance;
- if (waylineStore.currentEditWayline.wayLineType == 1) {
- distance = waylineStore.distance;
- backDistance = waylineStore.backDistance;
- if (distance.includes("米")) {
- distance = Number(waylineStore.distance.split("米")[0]);
- } else if (distance.includes("公里")) {
- distance = Number(waylineStore.distance.split("公里")[0]) * 1000;
- }
- if (backDistance.includes("米")) {
- backDistance = Number(waylineStore.backDistance.split("米")[0]);
- } else if (backDistance.includes("公里")) {
- backDistance = Number(waylineStore.backDistance.split("公里")[0]) * 1000;
- }
- time = Math.ceil((distance + backDistance) / waylineStore.speed);
- waylineStore.workTime = time;
- } else if (waylineStore.currentEditWayline.wayLineType == 2) {
- distance = Number(waylineStore.polygonResult.COMMON_INFO.waylineLength);
- waylineStore.speed =
- waylineStore.polygonResult.KMZ_INFO.wayline.Document.Folder[
- "wpml:autoFlightSpeed"
- ];
- time = Math.ceil(distance / waylineStore.speed);
- }
- lineToGroundLayer.addGraphic(line);
- ToGroundLine()
- }
- // 画线
- export function drawLine(positions) {
- // if (line) {
- // line.remove()
- // }
- console.log('lineToGroundLayer', lineToGroundLayer)
- if (!lineToGroundLayer) {
- lineToGroundLayer = new mars3d.layer.GraphicLayer();
- smallMap.addLayer(lineToGroundLayer);
- }
- line = new mars3d.graphic.PolylinePrimitive({
- // asynchronous: false,
- positions: positions,
- style: {
- width: 5,
- // color: "#0BD790",
- materialType: mars3d.MaterialType.LineFlow,
- materialOptions: {
- // color: "#0BD790",
- image: '/assets/wayline/line-interval2.png',
- repeat: new Cesium.Cartesian2(20, 1),
- speed: 1
- }
- }
- });
- lineToGroundLayer.addGraphic(line);
- return line
- }
- // 为每个航点添加连接地面的线
- function ToGroundLine() {
- if (groundLineList.length) {
- groundLineList.forEach(i => {
- i.remove()
- })
- }
- waylineStore.wayPointList.forEach((i, index) => {
- let middel = JSON.parse(JSON.stringify(i._point))
- let p = new mars3d.LngLatPoint(middel._lng, middel._lat, middel._alt)
- let height = 0
- mars3d.PointUtil.getSurfaceHeight(maps.scene, p).then(result => {
- height = (result.height_original.toFixed(2) - result.height.toFixed(2)).toFixed(2)
- let a = [p._lng, p._lat, 0]
- let constpoSition
- if (i.position.z) {
- constpoSition = i.position
- } else {
- constpoSition = i._position_draw
- }
- let groundLine = new mars3d.graphic.PolylinePrimitive({
- asynchronous: false,
- positions: [
- a,
- mars3d.PointUtil.addPositionsHeight(
- constpoSition,
- )
- ],
- style: {
- width: 1,
- color: '#FFFFFF',
- zIndex: 1,
- materialType: mars3d.MaterialType.PolylineDash, // 虚线111
- materialOptions: {
- color: '#FFFFFF',
- dashLength: 6
- },
- label: {
- text: `高度:${height}`,
- font_size: 18,
- color: "#ffffff",
- distanceDisplayCondition: true,
- distanceDisplayCondition_far: 500000,
- distanceDisplayCondition_near: 0,
- clampToGround: true,
- visibleDepth: false,
- }
- },
- });
- lineToGroundLayer.addGraphic(groundLine);
- groundLineList.push(groundLine)
- })
- })
- }
- export function showTheWayline() {
- let wayline = waylineStore.currentEditWayline.kmzJSON.Document
- // 先获取 起飞点的信息
- let takeoff = wayline['wpml:missionConfig']['wpml:takeOffRefPoint'].split(',')
- setTakeOffPoint(takeoff, wayline.Folder.Placemark)
- // 2. 获取航点的信息
- setWaylinePoint(wayline.Folder.Placemark, takeoff)
- }
- function setTakeOffPoint(takeoff, mark) {
- const graphic = new mars3d.graphic.BillboardEntity({
- position: new mars3d.LngLatPoint(takeoff[1], takeoff[0], takeoff[2]),
- style: {
- image: "/assets/wayline/airport.png",
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- clampToGround: true,
- visibleDepth: true,
- scaleByDistance: false,
- zIndex: 200,
- highlight: {
- image: "/assets/wayline/airport.png",
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.CENTER
- },
- }
- })
- graphicLayer.addGraphic(graphic)
- // waylinePositions.push(graphic)
- waylinePositions.push(graphic)
- // 需要的话再说1 反显的时候让飞行器和最后一个航点处于同一个位置
- // let lnglat= mark[mark.length-1].Point.coordinates.split(',')
- // let navPositin = [Number(lnglat[0]), Number(lnglat[1]), mark[mark.length-1]['wpml:executeHeight']]
- //记录起飞点
- waylineStore.takeoffPoint = graphic
- waylineStore.takeoffPointHeight = waylineStore.takeoffPoint._point._alt
- addUAV(graphic._position, ((uav) => {
- // // 罗盘旋转
- uav.on(mars3d.EventType.updateStyle, e => {
- waylineStore.heading = e.style.heading
- });
- }))
- graphic.flyTo({
- radius: 2000,
- heading: 12,
- alt: 936,
- pitch: -72.8
- });
- }
- // 设置 航点
- function setWaylinePoint(arr, takeoff) {
- if (!isArray(arr)) {
- let ponitList = []
- ponitList.push(arr)
- arr = ponitList
- }
- lineToGroundLayer = new mars3d.layer.GraphicLayer();
- maps.addLayer(lineToGroundLayer);
- waylineStore.wayPointList = []
- arr.forEach(i => {
- let alt
- let lnglat = i.Point.coordinates.split(',')
- if (i['wpml:ellipsoidHeight']) {
- alt = i['wpml:ellipsoidHeight'] + Number(takeoff[2])
- } else {
- alt = i['wpml:executeHeight'] + + Number(takeoff[2])
- }
- let position = [Number(lnglat[0]), Number(lnglat[1]), alt]
- let index = i['wpml:index'] + 1
- let wayPoint = new mars3d.graphic.BillboardEntity({
- position: new mars3d.LngLatPoint(position[0], position[1], position[2]),
- style: {
- image: '/assets/wayline/waypoint.png',
- // image: "img/wayline/dock.png",
- // image: dockImg,
- scale: 0.6,
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.CENTER,
- clampToGround: false,
- visibleDepth: true,
- scaleByDistance: false,
- pixelOffset: [0, -16],
- highlight: {
- image: '/assets/wayline/waypoint-active.png'
- },
- // 新建航点字体设置
- label: {
- // text: '航点' + (this_.waylinePointLayer.length === 0 ? '1' : this_.waylinePointLayer.length + 1) + '高度:' + (Math.floor(position.altitude)),
- // text: '航点' + (this_.waylinePointLayer.length === 0 ? '1' : this_.waylinePointLayer.length + 1),
- text: index,
- font_family: '微软雅黑',
- font_size: 16,
- color: '#FFFFFF',
- visibleDepth: false,
- pixelOffset: [0, -22]
- },
- zIndex: 201
- },
- })
- wayPoint.on(mars3d.EventType.click, (e) => {
- waylineStore.wayPoint = e.graphic
- chooseWayPoint(e.id)
- })
- wayPoint.options.attr.actionList = []
- if (i['wpml:actionGroup']) {
- if (i['wpml:actionGroup']['wpml:action'] && !i['wpml:actionGroup']['wpml:action'].length) {
- wayPoint.options.attr.actionList.push(getActionParam(i['wpml:actionGroup']['wpml:action']['wpml:actionActuatorFunc'], i['wpml:actionGroup']['wpml:action']['wpml:actionActuatorFuncParam']))
- } else if (i['wpml:actionGroup']['wpml:action'].length) { //多个动作
- i['wpml:actionGroup']['wpml:action'].forEach(j => {
- wayPoint.options.attr.actionList.push(getActionParam(j['wpml:actionActuatorFunc'], j['wpml:actionActuatorFuncParam']))
- })
- }
- }
- waylineStore.wayPointList.push(wayPoint)
- waylineStore.wayPoint = wayPoint
- waylineStore.wayPointNum = waylineStore.wayPointList.length
- graphicLayer.addGraphic(wayPoint)
- updataWayPointStyle()
- wayPoint.on(mars3d.EventType.mouseOver, function (e) {
- isIngraphic = true
- targetPoint = e.graphic
- targetHeight = e.graphic._point._alt
- })
- wayPoint.on(mars3d.EventType.mouseOut, function (e) {
- isIngraphic = false
- targetPoint = null
- waylineStore.wayPoint = e.graphic
- chooseWayPoint(e.id)
- })
- })
- lineWaypoint()
- }
- //反显面状航线
- export function reverseShowPolygonWayline() {
- let wayline = waylineStore.currentEditWayline.kmzJSON.Document
- // 先获取 起飞点的信息
- let takeoff = wayline['wpml:missionConfig']['wpml:takeOffRefPoint'].split(',')
- setTakeOffPointPolygon(takeoff)
- if (waylineStore.currentEditWayline.wayLineType == 2) {
- showRectangle(wayline)
- } else {
- showObliquePolygon(wayline)
- }
- }
- //反显倾斜摄影
- function showObliquePolygon(wayline) {
- let point = wayline.Folder.Placemark.Polygon.outerBoundaryIs.LinearRing.coordinates
- let positions = []
- let xyzArr = []
- point.split(' ').forEach(i => {
- let xyz = Cesium.Cartesian3.fromDegrees(i.split(',')[0], i.split(',')[1], i.split(',')[2])
- positions.push([i.split(',')[0], i.split(',')[1], i.split(',')[2]])
- xyzArr.push(xyz)
- })
- const graphic = new mars3d.graphic.PolygonEntity({
- positions: positions,
- style: {
- color: "#3388ff",
- opacity: 0.5,
- outline: false,
- clampToGround: true,
- visibleDepth: true,
- },
- })
- // let xyzString = wayline.Folder.Placemark['wpml:xyz']
- // let xyzArr = []
- // xyzString.split(' ').forEach(i => {
- // let Cartesian = new Cesium.Cartesian3(Number(i.split(',')[0]) , Number(i.split(',')[1]), Number(i.split(',')[2]));
- // xyzArr.push(Cartesian)
- // })
- waylineStore.Obliquephoto.pointsArr = xyzArr
- waylineStore.Obliquephoto.height = wayline.Folder.Placemark['wpml:height']
- waylineStore.Obliquephoto.lateralOverlapRate = wayline.Folder.Placemark['wpml:overlap']['wpml:orthoCameraOverlapW']
- waylineStore.Obliquephoto.TiltLateralOverlapRate = wayline.Folder.Placemark['wpml:overlap']['wpml:inclinedCameraOverlapW']
- waylineStore.Obliquephoto.mainCourseAngle = wayline.Folder.Placemark['wpml:direction']
- maps.graphicLayer.addGraphic(graphic)
- startEditObliquephotographyline()
- }
- function setTakeOffPointPolygon(takeoff) {
- const graphic = new mars3d.graphic.BillboardEntity({
- position: new mars3d.LngLatPoint(takeoff[1], takeoff[0], takeoff[2]),
- style: {
- image: "/assets/wayline/takeoff-active.png",
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- clampToGround: true,
- visibleDepth: true,
- scaleByDistance: false,
- zIndex: 200,
- highlight: {
- image: "/assets/wayline/takeoff-active.png",
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.CENTER
- },
- }
- })
- graphicLayer.addGraphic(graphic)
- // waylinePositions.push(graphic)
- waylineStore.takeoffPoint = graphic
- waylinePositions.push(graphic)
- let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
- waylineStore.takeoffPoint._position_draw
- ? waylineStore.takeoffPoint._position_draw
- : waylineStore.takeoffPoint._position
- );
- waylineStore.Obliquephoto.startPoint = {
- lng: takeoffPoint._lng,
- lat: takeoffPoint._lat,
- height: takeoffPoint._alt
- }
- graphic.flyTo({
- radius: 2000,
- heading: 12,
- alt: 936,
- pitch: -32.8
- });
- }
- function showRectangle(wayline) {
- let point = wayline.Folder.Placemark.Polygon.outerBoundaryIs.LinearRing.coordinates
- let positions = []
- point.split(' ').forEach(i => {
- positions.push([i.split(',')[0], i.split(',')[1], i.split(',')[2]])
- })
- const graphic = new mars3d.graphic.PolygonEntity({
- positions: positions,
- style: {
- color: "#3388ff",
- opacity: 0.5,
- outline: true,
- clampToGround: true,
- visibleDepth: true,
- },
- })
- maps.graphicLayer.addGraphic(graphic)
- bindLayerContextMenu()
- let RESULT_MAP = generate2dwayline(waylineStore.currentEditWayline, "myMap")
- waylineStore.distance = Number(RESULT_MAP.COMMON_INFO.waylineLength)
- waylineStore.speed = RESULT_MAP.KMZ_INFO.wayline.Document.Folder["wpml:autoFlightSpeed"]
- waylineStore.workTime = Math.ceil(waylineStore.distance / waylineStore.speed)
- line = new mars3d.graphic.PolylinePrimitive({
- // asynchronous: false,
- positions: RESULT_MAP.PATH_ON_MAP,
- style: {
- width: 5,
- // color: "#0BD790",
- materialType: mars3d.MaterialType.LineFlow,
- materialOptions: {
- // color: "#0BD7901",
- image: '/img/wayline/line-interval2.png',
- repeat: new Cesium.Cartesian2(20, 1),
- speed: 1
- }
- }
- });
- if (!lineToGroundLayer) {
- lineToGroundLayer = new mars3d.layer.GraphicLayer();
- maps.addLayer(lineToGroundLayer);
- }
- lineToGroundLayer.addGraphic(line);
- }
- export function clearWayline() {
- waylineStore.wayPointList = []
- waylineStore.wayPointNum = 0
- graphicLayer ? graphicLayer.remove() : ''
- lineToGroundLayer ? lineToGroundLayer.remove() : ''
- graphicLayer = null
- waylinePositions = []
- groundLineList = []
- uav = null
- lineToGroundLayer = null
- lineGraphic.remove()
- }
- // 绑定矢量对象编辑
- export function bindLayerContextMenu() {
- maps.graphicLayer.bindContextMenu([{
- text: "开始编辑对象",
- icon: "fa fa-edit",
- show: function (e) {
- const graphic = e.graphic
- if (!graphic || !graphic.hasEdit) {
- return false
- }
- return !graphic.isEditing
- },
- callback: (e) => {
- const graphic = e.graphic
- if (!graphic) {
- return false
- }
- if (graphic) {
- maps.graphicLayer.startEditing(graphic)
- }
- }
- },
- {
- text: "停止编辑对象",
- icon: "fa fa-edit",
- show: function (e) {
- const graphic = e.graphic
- if (!graphic || !graphic.hasEdit) {
- return false
- }
- return graphic.isEditing
- },
- callback: (e) => {
- //编辑结束后重新保存一下
- const graphic = e.graphic
- if (!graphic) {
- return false
- }
- if (graphic) {
- graphic.stopEditing()
- }
- graphic._positions_show.forEach(i => {
- waylineStore.polygonList.push(mars3d.LngLatPoint.fromCartesian(i))
- })
- waylineStore.Obliquephoto.pointsArr = graphic._positions_show
- if (waylineStore.currentEditWayline.wayLineType == 2) {
- showPolygonWayline()
- } else if (waylineStore.currentEditWayline.wayLineType == 3) {
- startEditObliquephotographyline()
- }
- }
- },
- {
- text: "删除对象",
- icon: "fa fa-trash-o",
- show: (event) => {
- graphic = event.graphic
- },
- callback: (e) => {
- graphic = e.graphic
- if (!graphic) {
- return
- }
- const parent = graphic.parent // 右击是编辑点时1
- graphicLayer.removeGraphic(graphic)
- }
- },
- ])
- }
- export function bindwayPointMenu() {
- graphicLayer.bindContextMenu([{
- text: "开始编辑对象",
- icon: "fa fa-edit",
- show: function (e) {
- const graphic = e.graphic
- if (!graphic || !graphic.hasEdit) {
- return false
- }
- return !graphic.isEditing
- },
- callback: (e) => {
- const graphic = e.graphic
- if (!graphic) {
- return false
- }
- if (graphic) {
- graphicLayer.startEditing(graphic)
- }
- }
- },
- ])
- }
- export function goWhere(data) {
- maps.flyToPoint(new mars3d.LngLatPoint(data.lng, data.lat, data.alt), {
- radius: 2000,
- heading: 12,
- alt: 936,
- pitch: -32.8
- });
- }
- export function changePointHeight(height) {
- waylineStore.wayPointList.forEach(i => {
- let point = i._point
- let newPosition = [point._lng, point._lat, point._alt + height]
- i.setOptions({
- position: newPosition
- })
- lineWaypoint()
- })
- }
- export function goLocalPosition(data, type) {
- let radius
- // type == 1 ? 80000 : type == 2 ? 40000 : type == 3 ? 20000 : 8000, // 距离目标点的距离
- switch (type) {
- case 1:
- radius = 80000;
- break;
- case 2:
- radius = 40000;
- break;
- case 3:
- radius = 20000;
- break;
- case 5:
- radius = 1036414;
- break;
- case 6:
- radius = 2000;
- break;
- default:
- radius = 8000;
- }
- const position = new mars3d.LngLatPoint(data.lng, data.lat, 10)
- maps.flyToPoint(position, {
- radius: radius,
- duration: 4,
- complete: function (e) {
- // 飞行完成回调方法
- // graphic.openPopup()
- }
- })
- }
- export function getWaylineParams(kml) {
- console.log(kml, 8828)
- }
- //倾斜摄影
- export function Obliquephotography() {
- maps.setSceneOptions({
- center: {
- lat: waylineStore.center.lat,
- lng: waylineStore.center.lng,
- alt: 2000,
- heading: 12,
- pitch: -85
- }
- })
- const graphic = new mars3d.graphic.BillboardEntity({
- position: new mars3d.LngLatPoint(waylineStore.center.lng, waylineStore.center.lat, waylineStore.center.alt),
- style: {
- image: "/assets/wayline/airport.png",
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- width: 60,
- height: 60,
- clampToGround: true,
- visibleDepth: false,
- scaleByDistance: false,
- scale: 0.8,
- zIndex: 200,
- }
- })
- graphicLayer.addGraphic(graphic)
- waylinePositions.push(graphic)
- //记录起飞点
- waylineStore.takeoffPoint = graphic
- let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
- waylineStore.takeoffPoint._position_draw
- ? waylineStore.takeoffPoint._position_draw
- : waylineStore.takeoffPoint._position
- );
- waylineStore.takeoffPointHeight = takeoffPoint._alt
- waylineStore.Obliquephoto.startPoint = {
- lng: takeoffPoint._lng,
- lat: takeoffPoint._lat,
- height: takeoffPoint._alt
- }
- drawPolygon()
- }
- //开始编辑倾斜摄影
- export function startEditObliquephotographyline() {
- eventBus.emit('getObliquephotography', waylineStore.Obliquephoto)
- }
- //显示倾斜摄影的航线
- export function showObliquephotographyline(data) {
- console.log(data, 5555555)
- data.target.pointArr.forEach(i => {
- let a = new Cesium.Cartesian3(i.x, i.y, i.z);
- i = mars3d.LngLatPoint.fromCartesian(a)
- })
- if (line) {
- line.remove()
- }
- line = new mars3d.graphic.PolylinePrimitive({
- // asynchronous: false,
- positions: data.target.pointArr,
- style: {
- width: 5,
- // color: "#0BD790",
- materialType: mars3d.MaterialType.LineFlow,
- materialOptions: {
- // color: "#0BD790",
- image: '/assets/wayline/line-interval2.png',
- repeat: new Cesium.Cartesian2(20, 1),
- speed: 1
- }
- }
- });
- lineToGroundLayer.addGraphic(line);
- if (boundgraphic) {
- boundgraphic.remove()
- }
- //倾斜摄影的范围
- boundgraphic = new mars3d.graphic.PolygonEntity({
- positions: data.target.boundArr,
- style: {
- color: "#4786ef",
- opacity: 0.2,
- outline: false,
- clampToGround: true,
- visibleDepth: true,
- zIndex: 221
- },
- })
- graphicLayer.addGraphic(boundgraphic)
- countLineInfo()
- }
- function countLineInfo() {
- let distance = 0
- waylineStore.qinxie_result.ALL_pointArr.forEach(i => {
- let line = new mars3d.graphic.PolylinePrimitive({
- asynchronous: false,
- positions: i.pointArr,
- style: {
- width: 5,
- // color: "#0BD790",
- materialType: mars3d.MaterialType.LineFlow,
- visibleDepth: false,
- materialOptions: {
- // color: "#0BD790",
- image: '/assets/wayline/line-interval2.png',
- repeat: new Cesium.Cartesian2(20, 1),
- speed: 1
- }
- }
- });
- distance += Number(mars3d.MeasureUtil.formatDistance(line.distance, { unit: 'km' }).split("公里")[0])
- })
- waylineStore.distance = distance.toFixed(2) + '公里'
- waylineStore.workTime = distance * 1000 / waylineStore.speed
- waylineStore.picNum = Math.floor(waylineStore.workTime / 2)
- }
- export function addWorkLayer(data) {
- workLayer.clear()
- const ENITTY_CLASS = {
- point: "PointEntity",
- polygon: "PolygonEntity",
- polyline: "PolylineEntity",
- circle: "CircleEntity",
- };
- let params = JSON.parse(data.layerData)
- params.forEach(i => {
- let layer = new mars3d.graphic[ENITTY_CLASS[i.json.type]](i.json);
- workLayer.addGraphic(layer)
- // maps.addLayer(layer)
- })
- }
- export function clearWorkLayer() {
- workLayer.clear()
- }
|