leaflet.draw 这个包 在vue中怎么用呢

0 投票
<template>
  <div style="height: 100%">
    <div id="map" style="margin:0 auto;width: 100%;height: 100%;"></div>
  </div>
</template>
<script>
import L from 'leaflet'
import tiledMapLayer from '@supermap/iclient-leaflet'

export default {
  name: 'HelloWorld',
  data() {
    return {
      map: null
    }
  },
  methods: {
    initMap() {
      console.log(L)
      var map = L.map('map', {
        center: [23.103651, 109.602506],
        crs: L.CRS.EPSG3857,
        zoom: 14
      });
      L.supermap.cloudTileLayer("http://t2.supermapcloud.com/FileService/image").addTo(map);

      var editableLayers = new L.FeatureGroup();
      map.addLayer(editableLayers);
      var options = {
        position: 'topleft',
        draw: {
          polyline: {},
          polygon: {},
          circle: {},
          rectangle: {},
          marker: {},
          remove: {}
        },
        edit: {
          featureGroup: editableLayers,
          remove: true
        }
      };
      var drawControl = new L.Control.Draw(options);  // 这里 开始 报错  leaflet.draw  这个怎么导入
      map.addControl(drawControl);
      handleMapEvent(drawControl._container, map);
      map.on(L.Draw.Event.CREATED, function(e) {
        var type = e.layerType,
          layer = e.layer;
        if (type === 'marker') {
          layer.bindPopup('A popup!');
        }
        editableLayers.addLayer(layer);
      });

      function handleMapEvent(div, map) {
        if (!div || !map) {
          return;
        }
        div.addEventListener('mouseover', function() {
          map.scrollWheelZoom.disable();
          map.doubleClickZoom.disable();
        });
        div.addEventListener('mouseout', function() {
          map.scrollWheelZoom.enable();
          map.doubleClickZoom.enable();
        });
      }
    }
  },
  mounted() {
    this.initMap()
  }
};

</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
7月 19, 2018 分类:  2011次浏览 | 用户: sugon_zdh (2 分)

2 个回答

0 投票
您好,leaflet.draw是个leaflet插件,您需要把它也引进来。
7月 20, 2018 用户: 李熙y 名扬四海 (4,524 分)
这个 有没有 npm  方式 下载 这个插件
能留个联系方式嘛,我在学习VUE+Leaflet
我引用了leaflet.draw还是报错啊,找不到L.Control.Draw
0 投票

你好,我现在也是遇到同样的问题,捂脸,就是L.Control类没有Draw这个函数,也没有L.Draw这个类,不知道兄弟你到时是怎么解决的,可以分享下吗smiley

3月 11 用户: 蜗牛单行道 初出茅庐 (26 分)
...