arcgis for js vue组件挂载之升级

1.解决弹窗中有异步请求,得到数据后显示弹窗
2.解决地图弹窗自动弹窗禁止后,不影响其他简单的地图弹窗自动打开(点击落点就打开内部设置好的templatePopup模板内容)
3.兼容设置多个类型的弹窗

封装的popup.js

export function setPopup(that) {
  const { mapView } = window
  viewOnClickEventLoad(mapView, that, ({ event, graphic, type }) => {
    clearComponent(that)
    // 高亮点击的要素
    mapView.whenLayerView(graphic.layer).then(function (lyrView) {
      window.highlight = lyrView.highlight(graphic)
    })
    mapView.goTo(graphic.geometry)
    openPopup(event.mapPoint, graphic, that, type)
  })
}

function viewOnClickEventLoad(view, that, callbackfun) {
  view.popup.autoOpenEnabled = false // 禁止自动弹窗
  view.on('click', (event) => {
    view.hitTest(event).then(function (response) {
      const { results } = response
      console.log({ results })
      if (results.length) {
        const aboutVideoIds = ['video', 'layer_keyinformation_realtimevideo_gonganshipin']

        const videoFeature = results.find((result) => {
            const id = result.graphic.layer.id
            return aboutVideoIds.some(item => id.includes(item))
        })
        const eventFeature = results.find((result) => {
            const id = result.graphic.layer.id
            return id.includes('_eventPoint')
        })
        const iotFeature = results.find((result) => {
            const id = result.graphic.layer.id
            return id.includes('iot-equipment')
        })

        const commonFeature = results.find((result) => { return result.graphic.layer.id.includes('_circleQueryResultGraphicsLayer') })

        if (videoFeature && videoFeature.graphic) { // 点击的是视频落点
          callbackfun({ event, graphic: videoFeature.graphic, type: 'video' })
        } else if (eventFeature && eventFeature.graphic) { // 点击的是事件落点
          callbackfun({ event, graphic: eventFeature.graphic, type: 'event' })
        } else if (iotFeature && iotFeature.graphic) { // 点击的是物联设备落点
          callbackfun({ event, graphic: iotFeature.graphic, type: 'iot' })
        } else if (commonFeature && commonFeature.graphic) { // 点击的是常规落点
          const { graphic } = commonFeature
          clearComponent(that)
          view.popup.open({
            location: graphic.geometry.centroid,
            features: [graphic]
          })
        }
      } else {
        view.popup.close()
        clearComponent(that)
      }
    })
  })
}

// 卸载组件 及清空高亮
function clearComponent(that) {
  // 卸载视频挂载
  that.$livePlay.unInstall()
  // 卸载事件挂载
 that.$eventDialog.unInstall()
  // 卸载设备挂载
  that.$iotDialog.unInstall()
  // 置空之前的高亮
  window.highlight = removeHighlight(window.highlight)
}

export function removeHighlight(highlight) {
  if (highlight) {
    highlight.remove()
  }
  return null
}

function openPopup(point, graphic, that, type) {
  // 要素中的属性对象 graphic.attributes
  const data = graphic.attributes
  const { LV_2_NAME, NAME } = data
  const mapOption = {
    video: { title: NAME, compoName: '$livePlay' },
    event: { title: LV_2_NAME, compoName: '$eventDialog' },
    iot: { title: '设备详情', compoName: '$iotDialog' }
  }
  // 手动open弹窗
  window.mapView.popup.open({
    title: mapOption[type].title,
    location: point,
    content: '加载中...'
  })
  // 挂在弹窗组件
  that[mapOption[type].compoName].install(data, that)
}

在地图初始化的时候调用popup.js中 setPopup方法

initMap() {
        const basemapConfig = getBasemapConfig('moumou区', 'dark')
        console.log({ basemapConfig })
        const basemap = createBasemap(basemapConfig)
        const view = createMapView('map-box', basemap)
        window.mapView = view
        // mapView加载完成后的代码可以写这里 //
        view.when(
          () => {
            // This function will execute once the promise is resolved
            view.zoom = 14
            // 隐藏左上角放大缩小插件
            view.ui.components = []

           
            this.initTheme()
            this.mapReady = true
            this.$store.commit('SET_MAPREADY', true)
            setPopup(this) //
          },
          error => {
            // This function will execute if the promise is rejected due to an error
            console.error(new Error(error))
          }
        )
        // 隐藏停靠按钮
        view.popup.dockOptions.buttonEnabled = false
        // 隐藏放大缩小
        view.popup.viewModel.includeDefaultActions = false
      },
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ArcGIS for JavaScript Vue 视频教程是一种通过视频方式来教授如何使用ArcGIS for JavaScriptVue框架来创建交互式地图应用的教程。 ArcGIS for JavaScript 是一款由Esri开发的用于构建地图应用的JavaScript API。它提供了丰富的地图、图层、遥感影像和空间分析功能,能够帮助开发者构建出功能强大、可视化效果出众的地理信息系统。 Vue是一款流行的JavaScript前端框架,它的核心思想是响应式数据绑定和组件化开发。Vue的主要特点是易学、灵活和高效,它能够帮助开发者更快速地构建出交互式和可重用的界面组件ArcGIS for JavaScript Vue 视频教程主要介绍如何结合使用ArcGIS for JavaScriptVue来创建地图应用。通过视频教程,开发者可以学习如何进行地图初始化、添加图层、展示地图、进行空间查询、添加交互等操作。 这些视频教程通常包括一系列教学视频,每个视频都会重点介绍某个具体的功能或操作。开发者可以按照自己的学习进度逐步学习和实践,从而逐渐掌握如何使用ArcGIS for JavaScriptVue来构建出自己的地图应用。 通过视频教程,开发者可以更清晰地了解和学习如何使用ArcGIS for JavaScriptVue。视频教程以实际操作为主,让开发者能够更加直观地理解每个步骤和操作的含义和作用。同时,视频教程也提供了练习和示例代码,方便开发者进行实践和理解。 总之,ArcGIS for JavaScript Vue 视频教程是一种通过视频方式来教授如何使用ArcGIS for JavaScriptVue框架来创建交互式地图应用的教程,它能够帮助开发者快速学习和掌握这两个优秀的技术,从而构建出功能强大、可视化效果出众的地理信息系统。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值