arcgis api for js弹出“下一个”“上一个”popupTemplate

功能需求:在道路上有一连串的point,每一个point点击时会弹出一个popup,展示这个点对应的一张照片。基本实现就是给每个point创建时,指定popupTemplate的内容。这样点击每个point自然就会弹出对应的照片。现在增加需求,每个popupTemplate内容上增加“上一张”“下一张”按钮,点击按钮自动关闭现在的popup,同时打开邻近的point的popup.

1.创建基本的Map  View和Layer

2.给Layer添加points

// 创建point
const point = {
    type: 'point',
    x: photoList[i].shape[0],
    y: photoList[i].shape[1]
}
// 创建symbol
const symbol = {
    type: 'simple-marker',
    color: '#B8860B',
    width: 1,
    size: '4px',
    outline: {
        color: '#B8890B',
        width: 1
    }
}
// 创建action
const nextBtnAction = {
    title: '下一张',
    id: 'next_img_btn',
    className: 'esri-icon-right-triangle-arrow'
}
const preBtnAction = {
    title: '上一张',
    id: 'pre_img_btn',
    className: 'esri-icon-left-triangle-arrow'
}
// 创建popupTemplate
const popupTemplate = {
    title: '{Name}', // 这里的模板语法取值自attributes
    content: '{Description}',
    actions: [preBtnAction, nextBtnAction]
}
// 定义属性
const attributes = {
    Name: '<span style="color:#fff">photo</span>',
    Description: '<img src=' + photoList[i].imageUrl + ' alt="link photo" />',
    index: i // 这个属性自定义的,主要用于方便寻找上下临近点
}
// 创建Graphic
const pointGraphic = new Graphic({
    gemotry: point,
    symbol: symbol,
    attributes: attributes,
    popupTemplate: popupTemplate
}
// 加入图层
layer.add(pointGraphic)

/**
注:photoList是从服务器请求到的数据,表示连续的一系列点
*/

3.监听popup中上一张和下一张的点击事件

view.popup.on('trigger-action', event => {
    if(event.action.id === 'next_img_btn'){
        const curIndex = view.popup.selectedFeature.attributes.index
        const nextPoint = view.popup.selecedFeature.layer.graphics.items[curIndex + 1]
        // 高亮下一个point
        view.whenlayerView(layer).then(layerView => {
            view.popup.close() // 关闭当前popup
            if(hightPoint){
                // 如果有高亮的point,先关闭
                hightPoint.remove()
            }
            // 高亮下一个point
            var hightPoint = layerview.highlight(nextPoint)
            // 在下一个point打开popup
            view.popup.open({
                location: {
                    x: nextPoint.geometry.x,
                    y: nextPoint.geometry.y
                },
                updateLocationEnabled: true,
                features: [nextPoint]
            })
        })
    } else if(event.action.id === 'pre_img_btn'){
        //同上 可以封装为一个函数
    }
}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乘风xs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值