leaflet自定义popup弹框,给popup弹框显示内容添加按钮button或者超链接等html标签

首先效果图:

这里在弹框的文字下面添加了一个button按钮和超链接。这种效果在web应用中很常见。所以下面总结一下如何用leaflet实现。

             

首先要用leaflet实现弹框的效果(如下图),这个就不详细介绍了,比较简单,参考leaflet官网:https://leafletjs.com/index.html

或者这里介绍一个可以在线运行示例的很棒的学习工具 https://jsfiddle.net/5apzcqvu/18/

大概的代码如下:

<template>
     <div class="" title="">
                <l-map">
                    <l-tile-layer :url="url"></l-tile-layer>
                        </l-marker>
                            <l-popup :content="name"></l-popup>
                        <l-marker :lat-lng="marker"></l-marker>
                </l-map>
     </div>
</template>

<script>
    import { LMap, LTileLayer, LMarker, LPopup } from 'vue2-leaflet'; 

    export default {

        components: {
            LMap,
            LTileLayer,
            LMarker,
            LPopup
        },

        data () {
            return {
                options:{
                    zoom:10,
                    center: [47.413220, -1.219482],
                    minZoom: -11,
                    attributionControl: false
                },
                url: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
                marker: L.latLng(47.413220, -1.219482),
                name: 'Contact1'

            }
        },  /*end of data()*/

        methods: {

        },





    };/* end of export */



</script>

重点:如何添加超链接和按钮标签?

只需要在popup组件的content属性里面设置即可,注意不是直接在vue的模板template里的leaflet组件里面加 ,即:

<l-popup :content="name<br><button>进入</button>"></l-popup>

而是在script代码里面的属性设置的地方添加。即:

name: 'Contact1<br><button>进入</button>'

个人觉得原因是html的标签要在script中才能被浏览器解析。

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值