【mars3d】 graphic.bindPopup(inthtml).openPopup()无需单击小车,即可在地图上自动激活弹窗的效果。

这篇具有很好参考价值的文章主要介绍了【mars3d】 graphic.bindPopup(inthtml).openPopup()无需单击小车,即可在地图上自动激活弹窗的效果。。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

实现效果:new mars3d.graphic.FixedRoute({无需单击小车,即可在地图上实现默认打开弹窗的激活效果。↓↓↓↓↓↓↓↓

【mars3d】 graphic.bindPopup(inthtml).openPopup()无需单击小车,即可在地图上自动激活弹窗的效果。,app,Mars3d,vue,3d,javascript,前端

相关链接说明:

1.popup的示例完全开源,可参考:功能示例(Vue版) | Mars3D三维可视化平台 | 火星科技

2.绑定的矢量数据上的弹框通过代码默认激活打开参考:功能示例(Vue版) | Mars3D三维可视化平台 | 火星科技

3.实现逻辑:在该矢量数据上bindPopup(),bindPopup之后再该小车数据上openPopup()

4.api说明:

BaseGraphic - V3.7.0 - Mars3D API文档

【mars3d】 graphic.bindPopup(inthtml).openPopup()无需单击小车,即可在地图上自动激活弹窗的效果。,app,Mars3d,vue,3d,javascript,前端

BaseGraphic - V3.7.0 - Mars3D API文档

【mars3d】 graphic.bindPopup(inthtml).openPopup()无需单击小车,即可在地图上自动激活弹窗的效果。,app,Mars3d,vue,3d,javascript,前端

相关演示代码:

import * as mars3d from "mars3d"

export let map // mars3d.Map三维地图对象

export const eventTarget = new mars3d.BaseClass() // 事件对象,用于抛出事件到面板中

let graphicLayer

// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)

export const mapOptions = {

  scene: {

    center: { lat: 30.836861, lng: 116.044673, alt: 1395, heading: 14, pitch: -42 }

  },

  control: {

    clockAnimate: true, // 时钟动画控制(左下角)

    timeline: true, // 是否显示时间线控件

    compass: { top: "10px", left: "5px" }

  }

}文章来源地址https://www.toymoban.com/news/detail-801958.html

/**

 * 初始化地图业务,生命周期钩子函数(必须)

 * 框架在地图初始化完成后自动调用该函数

 * @param {mars3d.Map} mapInstance 地图对象

 * @returns {void} 无

 */

export function onMounted(mapInstance) {

  map = mapInstance // 记录map

  map.toolbar.style.bottom = "55px" // 修改toolbar控件的样式

  // 创建矢量数据图层

  graphicLayer = new mars3d.layer.GraphicLayer()

  map.addLayer(graphicLayer)

  // 加载完成在加载小车,否则地形未加载完成,小车会处于地下

  map.on(mars3d.EventType.load, function (event) {

    addGraphicLayer()

  })

}

/**

 * 释放当前地图业务的生命周期函数

 * @returns {void} 无

 */

export function onUnmounted() {

  map = null

}

function addGraphicLayer() {

  const fixedRoute = new mars3d.graphic.FixedRoute({

    name: "贴地表表面漫游",

    speed: 160,

    positions: [

      [116.043233, 30.845286, 392.48],

      [116.046833, 30.846863, 411.33],

      [116.052137, 30.848801, 439.45],

      [116.060838, 30.850918, 442.91],

      [116.069013, 30.852035, 435.14],

      [116.18739, 30.854441, 244.53],

      [116.205214, 30.859332, 300.96]

    ],

    clockLoop: false, // 是否循环播放

    camera: {

      type: "gs",

      pitch: -30,

      radius: 500

    },

    // model: {

    //   show: true,

    //   url: '//data.mars3d.cn/gltf/mars/qiche.gltf',

    //   scale: 0.2,

    //   minimumPixelSize: 50,

    // },

    model: {

      url: "//data.mars3d.cn/gltf/mars/jingche/jingche.gltf",

      heading: 90,

      mergeOrientation: true, // 用于设置模型不是标准的方向时的纠偏处理,在orientation基础的方式值上加上设置是heading值

      minimumPixelSize: 50

    },

    polyline: {

      color: "#ffff00",

      width: 3

    }

  })

  graphicLayer.addGraphic(fixedRoute)

  // 绑定popup

  bindPopup(fixedRoute)

  fixedRoute.on(mars3d.EventType.start, function (event) {

    console.log("漫游开始start")

  })

  fixedRoute.on(mars3d.EventType.end, function (event) {

    console.log("漫游结束end")

  })

  // ui面板信息展示

  fixedRoute.on(mars3d.EventType.change, (event) => {

    // const popup = event.graphic.getPopup()

    // const container = popup?.container // popup对应的DOM

    // console.log("漫游change", event)

    throttled(eventTarget.fire("roamLineChange", event), 500)

  })

  map.on(mars3d.EventType.keydown, function (event) {

    // 空格 切换暂停/继续

    if (event.keyCode === 32) {

      if (fixedRoute.isPause) {

        fixedRoute.proceed()

      } else {

        fixedRoute.pause()

      }

    }

  })

  // 不贴地时,直接开始

  // startFly(fixedRoute)

  // 需要计算贴地点时,异步计算完成贴地后再启动

  showLoading()

  fixedRoute.autoSurfaceHeight().then(function (e) {

    hideLoading()

    startFly(fixedRoute)

  })

}

function startFly(fixedRoute) {

  fixedRoute.start()

  fixedRoute.openPopup() // 显示popup

  addParticleSystem(fixedRoute.property)

}

function bindPopup(fixedRoute) {

  fixedRoute.bindPopup(

    `<div style="width: 200px">

      <div>总 距 离:<span id="lblAllLen"> </span></div>

      <div>总 时 间:<span id="lblAllTime"> </span></div>

      <div>开始时间:<span id="lblStartTime"> </span></div>

      <div>剩余时间:<span id="lblRemainTime"> </span></div>

      <div>剩余距离:<span id="lblRemainLen"> </span></div>

    </div>`,

    { closeOnClick: false }

  )

  // 刷新局部DOM,不影响popup面板的其他控件操作

  fixedRoute.on(mars3d.EventType.postRender, function (event) {

    const container = event.container // popup对应的DOM

    const params = fixedRoute?.info

    if (!params) {

      return

    }

    const lblAllLen = container.querySelector("#lblAllLen")

    if (lblAllLen) {

      lblAllLen.innerHTML = mars3d.MeasureUtil.formatDistance(params.distance_all)

    }

    const lblAllTime = container.querySelector("#lblAllTime")

    if (lblAllTime) {

      lblAllTime.innerHTML = mars3d.Util.formatTime(params.second_all / map.clock.multiplier)

    }

    const lblStartTime = container.querySelector("#lblStartTime")

    if (lblStartTime) {

      lblStartTime.innerHTML = mars3d.Util.formatDate(Cesium.JulianDate.toDate(fixedRoute.startTime), "yyyy-M-d HH:mm:ss")

    }

    const lblRemainTime = container.querySelector("#lblRemainTime")

    if (lblRemainTime) {

      lblRemainTime.innerHTML = mars3d.Util.formatTime((params.second_all - params.second) / map.clock.multiplier)

    }

    const lblRemainLen = container.querySelector("#lblRemainLen")

    if (lblRemainLen) {

      lblRemainLen.innerHTML = mars3d.MeasureUtil.formatDistance(params.distance_all - params.distance) || "完成"

    }

  })

}

//  添加尾气粒子效果

function addParticleSystem(property) {

  const particleSystem = new mars3d.graphic.ParticleSystem({

    position: property,

    style: {

      image: "./img/particle/smoke.png",

      particleSize: 12, // 粒子大小(单位:像素)

      emissionRate: 20.0, // 发射速率 (单位:次/秒)

      pitch: 40, // 俯仰角

      maxHeight: 1000, // 超出该高度后不显示粒子效果

      startColor: Cesium.Color.GREY.withAlpha(0.7), // 开始颜色

      endColor: Cesium.Color.WHITE.withAlpha(0.0), // 结束颜色

      startScale: 1.0, //  开始比例(单位:相对于imageSize大小的倍数)

      endScale: 5.0, // 结束比例(单位:相对于imageSize大小的倍数)

      minimumSpeed: 1.0, // 最小速度(米/秒)

      maximumSpeed: 4.0 // 最大速度(米/秒)

    },

    attr: { remark: "车辆尾气" }

  })

  graphicLayer.addGraphic(particleSystem)

}

// ui层使用

export const formatDistance = mars3d.MeasureUtil.formatDistance

export const formatTime = mars3d.Util.formatTime

// 节流

function throttled(fn, delay) {

  let timer = null

  let starttime = Date.now()

  return function () {

    const curTime = Date.now() // 当前时间

    const remaining = delay - (curTime - starttime)

    // eslint-disable-next-line @typescript-eslint/no-this-alias

    const context = this

    // eslint-disable-next-line prefer-rest-params

    const args = arguments

    clearTimeout(timer)

    if (remaining <= 0) {

      fn.apply(context, args)

      starttime = Date.now()

    } else {

      timer = setTimeout(fn, remaining)

    }

  }

}

备注说明:

【mars3d】 graphic.bindPopup(inthtml).openPopup()无需单击小车,即可在地图上自动激活弹窗的效果。,app,Mars3d,vue,3d,javascript,前端

1.直接通过new mars3d.graphic.ModelEntity({相关矢量上绑定再激活也可以,关键代码:

  graphic.bindPopup(inthtml).openPopup()

实现链接:

功能示例(Vue版) | Mars3D三维可视化平台 | 火星科技

实现代码参考:

function addDemoGraphic1(graphicLayer) {

  const graphic = new mars3d.graphic.ModelEntity({

    name: "警车",

    position: [116.346929, 30.861947, 401.34],

    style: {

      url: "//data.mars3d.cn/gltf/mars/jingche/jingche.gltf",

      scale: 20,

      minimumPixelSize: 50,

      heading: 90,

      distanceDisplayCondition: true,

      distanceDisplayCondition_near: 0,

      distanceDisplayCondition_far: 10000,

      distanceDisplayPoint: {

        // 当视角距离超过一定距离(distanceDisplayCondition_far定义的) 后显示为点对象的样式

        color: "#00ff00",

        pixelSize: 8

      },

      label: {

        text: "我是原始的",

        font_size: 18,

        color: "#ffffff",

        pixelOffsetY: -50,

        distanceDisplayCondition: true,

        distanceDisplayCondition_far: 10000,

        distanceDisplayCondition_near: 0

      }

    },

    attr: { remark: "示例1" }

  })

  graphicLayer.addGraphic(graphic)

  // 演示个性化处理graphic

  initGraphicManager(graphic)

}

// 也可以在单个Graphic上做个性化管理及绑定操作

function initGraphicManager(graphic) {

  const inthtml = `<table style="width: auto;">

            <tr>

              <th scope="col" colspan="2" style="text-align:center;font-size:15px;">我是graphic上绑定的Popup </th>

            </tr>

            <tr>

              <td>提示:</td>

              <td>这只是测试信息,可以任意html</td>

            </tr>

          </table>`

  graphic.bindPopup(inthtml).openPopup()


 

}

到了这里,关于【mars3d】 graphic.bindPopup(inthtml).openPopup()无需单击小车,即可在地图上自动激活弹窗的效果。的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • mars3d绘制区域范围(面+边框)

    1、图例(绿色面区域+白色边框)  2、代码 1)、绘制区域ts文件 解释: 1、new mars3d.layer.GeoJsonLayer      生成矢量图层 2、styleField       \\\"levels\\\" 是在json文件中区分不同级别景区的标志,值为1、2、3等 3、styleFieldOptions       根据styleField获取到的值进行区分,划分不同颜色的

    2024年02月15日
    浏览(38)
  • Mars3D/Cesium + VUE3

    不定期更新 参考官网: http://mars3d.cn/dev/guide/start/import.html#_3-3-vite-%E6%8A%80%E6%9C%AF%E6%A0%88%E6%97%B6-%E7%9A%84%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE%E4%BF%AE%E6%94%B9 :已亲测vite框架,可以运行,具体见下main 1、插件 vite-plugin-mars3d vite中需要

    2024年02月14日
    浏览(38)
  • vue3 mars3d 天地图

                    npm i mars3d                  npm i mars3d-heatmap (热力图,需要的话安装)                 npm i -D copy-webpack-plugin                 增加mars3d目录配置,修改vue.config.js中configureWebpack里的内容如下:  使用: 最后附上天地图mapUrl地址

    2024年02月15日
    浏览(30)
  • Vue2项目使用mars3d

    或参考webpack.config.js写法进行修改

    2024年02月14日
    浏览(35)
  • Mars3D Studio 的使用方法

    mars3d Studio 是 mars3d 研发团队于近期研发上线的一款 场景可视化编辑平台。拥有资源存档、团队协作、定制材质等丰富的功能。可以实现零代码构建一个可视化三维场景。 (1)数据上传:目前支持 tif 影像上传、 3dtitles 、 gltf 小模型上传以及矢量数据( shp、gesojson、kml ) 下

    2023年04月16日
    浏览(88)
  • [mars3d 学习] 最近升级版本造成的问题

    1、mars3d升级3.5以上,使用的时候报错; 需要看下 Mars3D三维可视化平台 | 火星科技 版本更新日志; 使用将Cesium的版本升级到1.103 2、升级Cesium到1.103,之后打包又会报错 - error in ./node_modules/mars3d-Cesium/Build/Cesium/index.js 哦,是因为cesium1.96改变了代码打包方式;在vue2中就会存在

    2024年02月17日
    浏览(46)
  • Mars3d项目启动上的一些坑

    最近新入职了一家公司,公司新开了有个未来城市的项目,需要用到3D城市建模,公司老总选了Mars3d作为前端框架,项目分给我了,又是一个全新的领域,开搞吧! 下面是自己遇到的几个小问题,记录一下: 1 npm install copy-webpack-plugin --save -dev 时报错 解决办法:npm install cop

    2024年02月05日
    浏览(36)
  • vue3+vite项目集成mars3d

    创建一个项目 yarn create vite // vue - ts 安装依赖 yarn add vite-plugin-mars3d -D yarn add mars3d 控制台警告 warning \\\" mars3d@3.5.0\\\" has unmet peer dependency \\\"@turf/turf@^6.5.0\\\". warning \\\" mars3d@3.5.0\\\" has unmet peer dependency \\\"mars3d-cesium@~1.103.1\\\". 安装 yarn add  @turf/turf mars3d-cesium 修改 vite.config.ts 修改srcApp.vue 就可

    2024年02月15日
    浏览(36)
  • Mars3D使用过程遇到的问题记录【持续更新】

    需要标注线面的角度heading 2022年6月23日 heading计算方式: https://turfjs.fenxianglu.cn/ 计算两点之间的角度 直接F12在控制台可以计算 eg: 加载gltf模型,模型是透明的,需要改为不透明 2022年6月23日 用文本编辑器打开.gltf,把里面的\\\"alphaMode\\\":\\\"BLEND\\\"改成\\\"alphaMode\\\":\\\"OPAQUE\\\" 模型旋转之后,标

    2024年02月08日
    浏览(48)
  • vue3使用Mars3D写区块地图

    因为我也是第一次使用,所以我是把插件和源文件都引入了,能使用启动 源文件 下载地址: http://mars3d.cn/download.html 放入位置 在index.html中引入 引入插件 我是封装的组件,代码的使用和意义 我直接放在备注中 大体布局 父组件 添加地图内部数据和地图外部数据的方法 ,我都

    2024年01月20日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包