vue使用leaflet加载单张图(可用作室内图定位)

news/2024/7/10 2:50:25 标签: vue, 前端

 完整代码

<!-- 测试页面 -->
<template>
  <div id="map"></div>
</template>

<script>
import L from "leaflet";
import icon from "leaflet/dist/images/marker-icon-2x.png";
export default {
  components: {},

  data() {
    return {
      map: null,
      center: [120, 175],
      zoom: 1,
      markerUrl: L.icon({
        iconUrl: icon,
        iconSize: [34, 45],
        iconAnchor: [12, 25],
        popupAnchor: [1, -34],
        shadowSize: [41, 41],
      }),
      bgImg:
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg95.699pic.com%2Fxsj%2F18%2F2y%2Ftt.jpg%21%2Ffw%2F700%2Fwatermark%2Furl%2FL3hzai93YXRlcl9kZXRhaWwyLnBuZw%2Falign%2Fsoutheast&refer=http%3A%2F%2Fimg95.699pic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1668067345&t=3e4c53d2df490bff214f54e14747b5f0",
      bounds: [
        [0, 0],
        [240, 350],
      ],
      imageOverLay: null,
    };
  },

  computed: {},

  watch: {},

  //生命周期 - 创建完成(可以访问当前this实例)
  created() {},
  //生命周期 - 挂载完成(可以访问DOM元素)
  mounted() {
    this.init();
  },

  methods: {
    // 初始化地图
    init() {
      this.map = L.map("map", {
        center: this.center,
        zoom: this.zoom,
        crs: L.CRS.Simple,
        bounds: this.bounds,
        minZoom: 1,
      });
      //加载单张图
      this.imageOverLay = L.imageOverlay(this.bgImg, this.bounds, {
        interactive: true, //允许地图触发事件
      }).addTo(this.map);
      //   画marker
      this.drawMarker();
    },
    drawMarker() {
      //模拟数据
      let arr = [{ point: [50, 219] }, { point: [93, 119] }];
      this.gem = [];
      for (let i = 0; i < arr.length; i++) {
        const marker = L.marker(arr[i].point, { icon: this.markerUrl }).addTo(
          this.map
        );
        this.gem.push(marker);
        //监听marker点击事件
        marker.on("click", () => {});
        // marker绑定气泡框
        marker.bindPopup(
          `<div><a id='aa' style='color:red'>marker${i}</a></div>`
        );
      }
    },
  },
};
</script>
<style lang="scss" scoped>
#map {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 0;
}
</style>


http://www.niftyadmin.cn/n/1514849.html

相关文章

vue使用leaflet加载海量点

下载依赖 npm i leaflet --save npm i leaflet-canvas-marker-xrr2021 --save 完整代码 <!-- 测试页面 --> <template><div id"map"></div> </template><script> import L from "leaflet"; import icon from "…

vue在leaflet地图实现监控功能

下载播放器插件flv或mpegts npm i flv.js --save npm i mpegts.js --save 先创建一个监控视频组件 <!-- leaflet 使用Vue,extend构造组件 --> <template><div><videoid"videoElement"controlsautoplaymutedwidth"300px"height&qu…

js实现word转换为html

前言 最近接到一个需求&#xff0c;实现上传一个word文档&#xff0c;然后将该word转换成html丢给服务端存上。进行技术调研后发现有三种方法可以实现这个功能&#xff1a;ActiveXObject、docx2html、mammoth。 IE的 ActiveXObject var oWordAppnew ActiveXObject("Word…

vue使用sass实现主题换肤功能

本文只介绍深浅两种主题换肤作为参考。 1.创建配置动态样式的scss文件&#xff0c;路径为/src/assets/scss/_theme.scss。 $themes: (light: (//字体font_color1: #000,//背景background_color1: #fff,// 背景渐变background_gradient1:#F8FBFD ,//边框border_color1: #e8ebf0…

[Antd-vue] Warning: You cannot set a form field before rendering a field associated with the value.

1.需求&#xff1a;给form表单反显数据&#xff08;一般用于数据修改功能&#xff09;。 2.使用了表单的方法setFieldsValue()&#xff0c;来设置一组输入控件的值&#xff0c;传入的值为object&#xff08;能少传不能多传&#xff09;。 3.解决办法 this.$nextTick(()>{th…

实验记录resnet20/cifar100

Cifar100 / resnet20&#xff1a; 1、Baseline Namespace:(batch_size128, decay0.0003, epoch200, gammas[0.1, 0.1, 0.5], learning_rate0.1, momentum0.9, optimizerSGD, schedule[80, 120, 160]) Best acc: 68.85% 80 和 120 是拐点 2、batch_size, gammas Namespa…

ant-design-vue的select组件加入value后placeholder不显示

导致placeholder不显示原因&#xff1a; value为nullvalue为空未获取到value 解决办法&#xff1a; value设置为undefined <a-select v-model"formDate.disabled" placeholder"请选择是否停用" style"width:160px"><a-select-option va…

在vue中实现禁止屏幕滚动,禁止屏幕滑动

1.需求&#xff1a;当如图弹框的内容滚动/滑动时&#xff0c;遮罩层后边的内容静止不动。 2.代码 <div v-show"isShow" touchmove.prevent mousewheel.prevent></div>这个div是遮罩组件的根组件&#xff0c;核心就是div上的事件绑定。 touchmove 是…