2.0.3 • Published 2 years ago

map-integration v2.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

基础

说明


组件集成 Leaflet,高德地图 API 将地图操作封装为统一出入口,方便程序快速切换地图模式。

安装


npm 安装

目前只支持 npm 安装方式

npm i map-integration

1. 采用 leaflet 模式

安装 leaflet

npm install --save leaflet esri-leaflet proj4leaflet

配置全局 leaflet 变量

// 全局引入leaflet
import L from 'leaflet'
import 'proj4leaflet'
require('esri-leaflet')
require('leaflet/dist/leaflet.css')
Vue.prototype.$L = L

2. 采用高德地图模式

安装高德地图

npm i @amap/amap-jsapi-loader --save

配置全局高德地图变量

//  全局引入amap
import AMapLoader from '@amap/amap-jsapi-loader'
Vue.prototype.$AMapLoader = AMapLoader

使用教程

快速上手

<!--
 * @Descripttion: 使用示例
 * @Author: xuyanqi
 * @Date: 2022-06-01 17:30:58
-->
<template>
  <div class="index">
    <map-integration type="leaflet" :options="options" @initMap="initMap"></map-integration>
    <div class="btn-group">
      <button @click="clearLayers">清除图层</button>
      <button @click="removeLayer">清除点</button>
    </div>
  </div>
</template>

<script>
import mapIntegration from 'map-integration'
export default {
  components: {
    mapIntegration,
  },
  data() {
    return {
      mapData: null,
      marker: null,
      options: {},
    }
  },
  mounted() {},
  methods: {
    initMap(data) {
      this.mapData = data
      // 打点
      this.marker = data.addMarker({
        extData: '点',
      })
      // 画线
      data.addPolyline({
        path: [
          [117.127328, 36.673561],
          [117.130263, 36.674951],
          [117.131277, 36.673591],
          [117.131443, 36.672989],
          [117.131384, 36.672705],
          [117.131282, 36.67233],
          [117.131325, 36.671608],
          [117.131325, 36.671556],
          [117.130048, 36.671741],
          [117.128691, 36.672274],
          [117.127908, 36.672834],
          [117.127908, 36.672834],
        ],
        extData: '线',
      })
      // 图层点击
      data.clickLayer((e) => {
        console.log(e)
      })
      // 地图点击
      data.clickMap((e) => {
        console.log(e)
      })
    },
    // 清除地图上所有图层
    clearLayers() {
      this.mapData.clearLayers()
    },
    // 删除指定图层
    removeLayer() {
      this.mapData.removeLayer(this.marker)
    },
  },
}
</script>

<style scoped>
.index {
  height: 100%;
}
.btn-group {
  position: absolute;
  top: 20px;
  right: 10px;
  z-index: 999;
  background-color: #ffffff;
  padding: 10px;
  box-shadow: 0 0 4px #b9b9b9;
  border-radius: 5px;
  display: flex;
  flex-direction: column;
}
button {
  margin: 5px;
}
</style>

props

属性名是否必填默认值可选值说明
typeamapleaflet,amap地图类型
options--配置参数

options 参数

该工具目前只实现了以下通用属性,如果需要其他属性可根据官网 map 对象属性自定义填写,只是在切换地图模式时无法同步使用。

属性名是否必填默认值可选值说明
center116.75199, 36.55358地图中心点坐标值
zoom8地图显示的缩放级别
minZoom1地图缩放最小值
maxZoom16地图缩放最大值
...............

events

事件回调值说明
initMapmapData地图初始化完成后触发

mapData Attribute

属性返回类型说明
mapMap 对象map 对象

mapData Methods

方法名返回值传参说明
addMarker(marker: Object)LayerMarker添加点坐标
addPolyline(polyline: Object)LayerPolyline添加线绘制
clickLayer(callback: Function)callback(Polyline|Marker)图层点击
clickMap(callback: Function)callback({lng: 117.22323,lat: 38.23423})地图点击
clearLayers()清除所有图层
removeLayer(layer: any)Layer删除指定图层

Polyline

属性类型说明
pathnumber 二维数组经纬度数据
borderWeightnumber线的粗细
strokeColorstring线的颜色
extDataobject自定义数据

Marker

属性类型说明
lngnumber精度
latnumber纬度
iconstring图标地址,可以是网络地址
sizenumber图标大小
titlestring鼠标划过文字提示
extDataobject自定义数据
2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago