index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="mapCom">
  3. <div id="map"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { CanvasLabel } from '@panzhiyue/leaflet-canvaslabel'
  8. import img from '@/assets/mapdarw/images/marker-icon.png'
  9. // import '@/assets/mapdarw/Leaflet.draw'
  10. // import '@/assets/mapdarw/leaflet.draw.css'
  11. // import '@/assets/mapdarw/leaflet.pin.css'
  12. // import '@/assets/mapdarw/leaflet.pin.js'
  13. export default {
  14. data() {
  15. return {
  16. map: null,
  17. img: img,
  18. DefaultIcon1: null,
  19. layerGroup: [],
  20. layers: [],
  21. rightObj: {},
  22. areaLayer: null,
  23. tilsUrl: './static/kMapTiles/{z}/{x}/{y}.jpg',
  24. ciLayer: null
  25. }
  26. },
  27. mounted() {
  28. this.initMap()
  29. },
  30. methods: {
  31. initMap() {
  32. let map = L.map('map', {
  33. center: [40.02404009136253, 116.50641060224784], // 地图中心--北京
  34. zoom: 16 //缩放比列
  35. // drawControl: true
  36. // zoomControl: false, //禁用 + - 按钮
  37. // doubleClickZoom: true, // 禁用双击放大
  38. // attributionControl: false, // 移除右下角leaflet标识
  39. // preferCanvas: true
  40. })
  41. let name = L.tileLayer(
  42. 'http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}'
  43. ).addTo(map)
  44. var editableLayers = new L.FeatureGroup()
  45. map.addLayer(editableLayers)
  46. var MyCustomMarker = L.Icon.extend({
  47. options: {
  48. shadowUrl: null,
  49. iconAnchor: new L.Point(12, 12),
  50. iconSize: new L.Point(24, 36),
  51. iconUrl: this.img
  52. }
  53. })
  54. var options = {
  55. position: 'topright',
  56. draw: {
  57. polyline: {
  58. shapeOptions: {
  59. color: '#f357a1',
  60. weight: 10
  61. }
  62. },
  63. polygon: {
  64. allowIntersection: false, // Restricts shapes to simple polygons
  65. drawError: {
  66. color: '#e1e100', // Color the shape will turn when intersects
  67. message: "<strong>Oh snap!<strong> you can't draw that!" // Message that will show when intersect
  68. },
  69. shapeOptions: {
  70. color: '#bada55'
  71. }
  72. },
  73. // circle: false, // Turns off this drawing tool
  74. rectangle: false,
  75. // rectangle: {
  76. // shapeOptions: {
  77. // clickable: false
  78. // }
  79. // },
  80. marker: {
  81. icon: new MyCustomMarker()
  82. }
  83. },
  84. edit: {
  85. featureGroup: editableLayers, //REQUIRED!!
  86. remove: true
  87. }
  88. }
  89. var drawControl = new L.Control.Draw(options)
  90. map.addControl(drawControl)
  91. map.on(L.Draw.Event.CREATED, function (e) {
  92. let type = e.layerType,
  93. layer = e.layer
  94. console.log('e====>>>', e)
  95. if (type === 'marker') {
  96. layer.bindPopup('A popup!')
  97. }
  98. editableLayers.addLayer(layer)
  99. })
  100. }
  101. }
  102. }
  103. </script>
  104. <style scoped lang="sass">
  105. .mapCom
  106. height: 85vh
  107. .iconLabel
  108. width: 80px !important
  109. .iconSty
  110. &Class
  111. width: 50px
  112. height: 100px
  113. position: relative
  114. top: 40px
  115. #map
  116. width: 100%
  117. height: 100%
  118. .lmap-image
  119. width: 32px
  120. height: 32px
  121. .lmap-span
  122. display: inline-block
  123. margin-left: 5px
  124. padding: 5px
  125. font-weight: bold
  126. line-height: 20px
  127. font-size: 14px
  128. color: #fff
  129. white-space: nowrap
  130. .lmap-text
  131. display: inline-block
  132. margin-left: 5px
  133. padding: 5px
  134. font-weight: bold
  135. line-height: 20px
  136. font-size: 16px
  137. color: #fff
  138. width: 500px
  139. white-space: nowrap
  140. position: absolute
  141. text-align: center
  142. top: 25px
  143. left: -250px
  144. </style>