minemap api的vue实现
- 使用vue组件风格创建minemap图层
- 减少minemap api调用,专注于业务逻辑
- 使用简单,易上手
- MineMap
- MMSource
- MMLayer
- MMMarker
- MMPopup
https://zhuweileo.github.io/vue-minemap/vuepress/#/
$ npm install --save vue-minemap
首先,引入minemap api
index.html
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" href="//minedata.cn/minemapapi/v2.0.0/minemap.css">
<title>vue-minemap-demo2</title>
</head>
<body>
<div id="app"></div>
<script src="//minedata.cn/minemapapi/v2.0.0/minemap.js"></script>
<!-- built files will be auto injected -->
</body>
</html>
使用地图组件
<tempalte>
<div id="app">
<mine-map
:accessToken= "'e919a6f32ce242f5aec22652d9dc1fdb'"
:solution= "'7185'"
:options= "{
container: 'map',
style: `http://minedata.cn/service/solu/style/id/7185`,
center: [116.1866179, 39.992559],
zoom: 9,
minZoom: 3,
maxZoom: 17,
}"
></mine-map>
</div>
</tempalte>
<script>
import {MineMap} from 'vue-minemap'
export default {
name:'app',
}
</script>
<style>
html,body{
height: 100%;
}
#app{
height: 100%;
}
</style>
添加source和layer
<tempalte>
<mine-map
:accessToken= "'xxxxxxxxxxxxxxxxxxxxxxxxx'"
:solution= "'7185'"
:options= "{
container: 'map',
style: `http://minedata.cn/service/solu/style/id/xxxx`,
center: [116.1866179, 39.992559],
zoom: 9,
minZoom: 3,
maxZoom: 17,
}"
>
<MMSource :id="sourceId" :options="sourceOption">
<MMLayer
:id="layerOption.id"
:type="layerOption.type"
:paint="layerOption.paint"
></MMLayer>
</MMSource>
</mine-map>
</tempalte>
<script>
import {MineMap,MMSource,MMLayer} from 'vue-minemap'
export default {
name:'app',
data(){
return {
sourceId: 'test',
sourceOption:{
type: 'geojson',
data: {type: 'Point', coordinates: [116.1866179, 39.992559],}
},
layerOption:{
id: 'test',
type: 'circle',
paint: {'circle-radius': 10, 'circle-color': '#ccc'}
}
}
}
}
</script>
- Type:
string
- Required:
true
地图token值
<mine-map :accessToken="'xxxxxxxxxxxxxxxxxx'"/>
- Type:
string | number
- Required:
true
- Default:
true
地图solution
<mine-map :solution="'xxxx'"/>
- Type:
object
- Required:
true
地图初始化参数,格式和minemap api兼容通用
<mine-map :options="{
container: 'map',
style: `http://minedata.cn/service/solu/style/id/xxxx`,
center: [116.1866179, 39.992559],
zoom: 9,
minZoom: 3,
maxZoom: 17,
}"/>
- Type:
string
- Required:
true
source的id
<m-m-source :id="'test'"/>
- Type:
object
- Required:
true
source的初始化参数,格式和minemap api兼容通用
<m-m-source :options="{
type:'geojson',
data: {}
}"/>
- Type:
minemap.Map
- Required:
false
minemap.Map 的实例化对象,当该组件不作为MineMap
组件的子组件,而是单独使用时,需要传入
<m-m-source :mapInstance="map"/>
- Type:
string
- Required:
true
layer的id
<m-m-layer :id="'test'"/>
- Type:
string
- Required:
true
图层类型。 circle
,line
,fill
,symbol
,background
,raster
,extrusion
,heatmap
,hillshade
中的一种。
<m-m-layer :type="'circle'"/>
- Type:
string
- Required:
false
- Default:
''
矢量数据时,需要传入
<m-m-layer :sourceLayer="'link'"/>
- Type:
object
- Required:
false
- Default:
null
图层初始换参数中的 layout部分,格式和minemap api 兼容
<m-m-layer :layout="{
visibility: 'visible'
}">
- Type:
object
- Required:
false
- Default:
null
图层初始换参数中的paint部分,格式和minemap api 兼容
<m-m-layer :paint="{
'circle-color': '#000'
}">
- Type:
array
- Required:
false
- Default:
null
图层初始换参数中的filter部分,格式和minemap api 兼容
<m-m-layer :filter="['==','name','leo']">
- Type:
array
- Required:
true
marker的坐标点
<m-m-marker :lnglat="[116.34,39.45]"></m-m-marker>
- Type:
array
- Required:
false
marker位置偏移
offset[0]: 相对于左上角向右偏移多少像素,
offset[1]: 相对于左上角向下偏移多少像素
<m-m-marker :offset="[50,0]"></m-m-marker>
- Type:
array
- Required:
false
popup的坐标点
<m-m-popup :lnglat="[116.34,39.45]"></m-m-popup>
- Type:
array
- Required:
false
popup位置偏移
offset[0]: 相对于锚点向右偏移多少像素,
offset[1]: 相对于锚点向下偏移多少像素
<m-m-popup :offset="[50,0]"></m-m-popup>
- Type:
string
- Required:
false
popup的偏移锚点
可选值'center' , 'top' , 'bottom' , 'left' , 'right' , 'top-left' , 'top-right' , 'bottom-left' , 'bottom-right'
<m-m-popup :anchor="'top'"></m-m-popup>
- Type:
boolean
- Required:
false
- Default
true
popup是否显示关闭按钮
<m-m-popup :closeButton="false"></m-m-popup>
- Type:
boolean
- Required:
false
- Default
true
点击地图是否可以关闭popup
<m-m-popup :closeOnClick="false"></m-m-popup>
- Required:
false
- Parameters:
map实例
当地图加载完时调用
<mine-map @map-load="onLoad" />
- 写单元测试
- marker组件
- popup组件
- 路径规划组件
- poi搜索组件
- 城市搜索组件
欢迎参与代码贡献
# 打包组件代码
npm run build
# 运行demo
npm run demo:dev
# 打包demo
npm run demo:build
# 运行文档
npm run docs:dev
# 打包文档
npm run docs:build
# 运行单元测试
npm run test