0.0.81 • Published 10 days ago

zh-mapbox v0.0.81

Weekly downloads
-
License
ISC
Repository
-
Last release
10 days ago

zh-mapbox

介绍

封装了一些mapbox的常用方法

使用

import { RegisterMapBoxMethod } from 'zh-mapbox'

let mapboxgl = require('mapbox-gl')
require('mapbox-gl/dist/mapbox-gl.css')
//注册常用方法
RegisterMapBoxMethod(mapboxgl)
import { RegisterMapBoxModel } from 'zh-mapbox'

import * as THREE from 'three'
import GLTFLoader from 'three/examples/js/loaders/GLTFLoader'
//注册模型相关方法(前提先注册常用方法)
RegisterMapBoxModel(THREE,GLTFLoader)

方法概览

注册常用方法后 map.on('layerdata') 可监听图层的添加与删除

Map

方法名参数描述
RegisterMapBoxMethod(mapboxgl,defaultSource?:string[])mapboxgldefaultSource:默认不进行删除或查找的源注册方法
removeAllLayerAndSource(defaultSource?:string[])defaultSource:默认不进行删除的源删除所有图层和源
getAllLayerAndSource(defaultSource?:string[])-(0.0.24)defaultSource:默认不获取的源获取所有图层和源
findCustomLayer(type?:string[]|string,defaultSource?:string[])type:查找类型defaultSource:默认不查找的源查找自定义的图层
MapTooltip(layerName:string|string[],options:Popup.options)layerName:图层名称options:继承mapbox Popup的参数(实例)地图提示框
MapPopup(layerName:string|string[],options:Popup.options)layerName:图层名称options:继承mapbox Popup的参数(实例)地图弹出框
MapLine-(实例)地图绘制线
MapCustom-(实例)地图其他绘制(默认symbol)
MapCircle-(实例)地图绘制圆
MapEvent-(0.0.24)layerName?:图层名称(实例) 自定义事件
MapMarker(options)-(0.0.24)options:marker参数(实例)绘制marker
MapMoreCustom-(0.0.24)-(实例)多图层方法
fitBoundsGeoJson(geojson:any,options:Camera.options)geojsonoptions:相机相关参数聚焦到geojson
fitBoundsPosition(position:array<array>,options:Camera.options)position:四至位置options:相机相关参数聚焦到四至位置
getInvertMask(geojson:any,options:{id:string,layerConfig:any}):layeroptions.id:遮罩idoptions.layerConfig:图层layer样式配置获取geojson反向区域
loadImages(urls:{key:string|{url:string,...args}}):Promise<{key:value}>urls:图片对象集合key:图片名称 ->图片地址加载多张图片
loadAddImages(url:{key:string|{url:string,...args}})urls:图片对象集合key:图片名称 ->图片地址加载多张图片同时加载到地图上
removeLayerSource(options:{name:string|array,layers?:array,sources?:array}) -(0.0.24)name: 图层和源id(图层和源相同)layers?图层idsources?源id移除图层和源
removeLayerEvent(event:object,clear)-(0.0.24)event: 移除的事件对象clear:清除对象 true -(0.0.73)移除图层定义的事件
findCustomIcon-(0.0.24)-查找自定义的图标
setStyle(style,option,callback?)-(0.0.24)styleoptions{save是否保存图片、源、图层source?:'composite'不保存的源和图层}callback?保存操作后回调设置地图样式(同地图原来设置)
removeEvents(events?:string[])-(0.0.24)events:'click', 'mousemove', 'mouseout'删除事件
removePopup(type:popup|tooltip)-(0.0.24)type:弹窗类型移除弹窗
getCustomLayer()-(0.0.54)-获取type:custom的图层
getLayerIndex(id) -(0.0.66)图层id根据图层id获取层级
getLayerId(index,after)-(0.0.66)index:图层层级after:之后的层级数根据层级获取图层id
getMinLayerId()-(0.0.66)-获取最小层级id
getMaxLayerId()-(0.0.66)-获取最大层级id
getAllLayerId()-(0.0.71)-获取所有图层id
getAllLayer()-(0.0.71)-获取所有图层
getLineLayer()-(0.0.71)-获取线图层
AnimateLine(name,options)-(0.0.73)name:图层idoptions?:{dash?:变化的数组step?:段数}线动画

Map.Style

方法名参数描述
loadSprite(url)-(0.0.24)url:精灵图地址加载精灵图( findCustomIcon 可以查询到)
方法名参数描述
RegisterMapBoxModel(THREE,GLTFLoader)THREE:threejsGLTFLoader:模型加载器注册模型
initGLTF(id:string,options:{},callback:function)id:模型名称options:{lngLat:经纬度height:高度scale:缩放url:地址(绝对地址/网络地址)rotate:旋转 x,y,zAmbientLight:环境光 {show:boolean,...args:three.ambient}DirectionalLight :平行光 three.directionalPointLight:点光源 three.PointLightclick:是否开启点击事件properties:属性}callback:点击回调 返回{lngLat,properties}加载模型

方法

MapTooltip

方法名参数描述
show(callback:function,type?:string)callback:返回tooltip显示的信息,(properties)=>{}type:显示类型 默认跟随点位 ‘move’:跟随鼠标显示提示框
destroy()-销毁
MapPopup
options:{
	...,
	destroyComponent=false,//关闭时是否销毁组件
	customClick=false,//是否自定义点击事件
	popupClose=false,//关闭时是否调用组件内popupClose()方法,vue组件
	closeOther=true,//弹窗打开时关闭其他弹窗
	noCloseLayerName:string[],//不关闭的弹窗名称
	closeClick//点击关闭按钮执行的方法
}
方法名参数描述
show(callbackComp:function,callback?:function)callbackComp:弹出框内显示的组件callback:弹出框打开后回调显示弹出框
close()-关闭弹出框
closeBack(callback:function)callback:弹出框关闭的回调弹出框关闭回调
destroy()-销毁
showPosition(lnglat:LngLatLike,component:vueComponent,options,callback)lnglat:经纬度位置component:vue组件options:{offset:[]}偏移callback 回调直接显示弹出框
MapLine
方法名参数描述
draw(geojson:GeoJson,name:string,options):array(图层名称数组)geojsonname:图层idoptions:{beforeId:在那个图层之下layerConfig:图层配置lineConfig?:额外高亮线配置sourceConfig?:源配置(0.0.23)}绘制线
destroy()-销毁
visible()-(0.0.71)show:boolean显示隐藏
MapCustom
方法名参数描述
draw (geojson:GeoJson,name:string,options):array(图层名称数组)geojson name:图层id options:{ beforeId:在那个图层之下 layerConfig:图层配置 type:图层类型 ’symbol‘sliceNum?:数据分割加载数sourceConfig?:源配置(0.0.23) }绘制图层
destroy()-销毁
visible()-(0.0.71)show:boolean显示隐藏
MapCircle
方法名参数描述
draw (geojson:GeoJson, name:string,options): array(图层名称数组)geojson name:图层id options:{ beforeId:在那个图层之下 layerConfig:图层配置 radius:范围(km)steps:圆边数(64)endRadius?:结束范围(km)lingConfig?:边框线配置sourceConfig?:源配置(0.0.23) }绘制圆/圆环
destroy()-销毁
visible()-(0.0.71)show:boolean显示隐藏
MapEvent
方法名参数描述
add(event:{key:function})event:{'key':事件名称function:事件函数}添加事件
destroy(array?)array?:移除的事件名称不传移除全部移除事件
MapMoreCustom
layerConfig:{
	id,
	type,
	beforeId,
	...
}
方法名参数描述
drawgeojson:GeoJson,options:):arraygeojsonoptions:{sourceConfig:{id,type?,...}layerConfig:[]|{}}添加多图层
destroy()-销毁
visible()-(0.0.71)show:boolean显示隐藏
MapMarker
方法名参数描述
draw(geojson:GeoJson,htmlCallback:function)geojsonhtmlCallback({lngLat,properties})绘制marker
addEvent(events:{key:function})events:{dragstart?:function,drag?:function,dragend?function}添加事件
destroy()-销毁
visible()-(0.0.71)show:boolean显示隐藏

AnimateLine

方法名参数描述
animate()-开始动画
destroy()-销毁动画

使用

import TestPopup from '@/views/TestPopup'
 map.addSource('point', {
      'type': 'geojson',
      'data': {
        'type': 'FeatureCollection',
        'features': [
          {
            'type': 'Feature',
            'properties': {
              name: '123'
            },
            'geometry': {
              'type': 'Point',
              'coordinates': [115, 30]
            }
          }
        ]
      }
    })
    map.addLayer({
      'id': 'point',
      'type': 'circle',
      'source': 'point',
      'paint': {
        'circle-radius': 10,
        'circle-color': '#007cbf'
      }
    })
    const tooltip = map.MapTooltip('point')
    tooltip.show((properties) => {
      return properties.name
    })
	const popup=map.MapPopup('point')
    popup.show(({properties,lngLat})=>{
        //转换vue组件 得到$el以及vue实例
        ...
        return {component:$el,instance:instance}
    },({lnglat,properties})=>{})
beforeDestroy(){
    //销毁
	tooltip.destroy()
	popup.destroy()
}
0.0.81

10 days ago

0.0.80

14 days ago

0.0.77

14 days ago

0.0.78

14 days ago

0.0.79

14 days ago

0.0.73

20 days ago

0.0.74

20 days ago

0.0.75

20 days ago

0.0.76

20 days ago

0.0.71

1 month ago

0.0.72

1 month ago

0.0.70

1 month ago

0.0.64

1 month ago

0.0.65

1 month ago

0.0.66

1 month ago

0.0.67

1 month ago

0.0.68

1 month ago

0.0.69

1 month ago

0.0.63

1 month ago

0.0.62

1 month ago

0.0.60

1 month ago

0.0.61

1 month ago

0.0.59

1 month ago

0.0.54

1 month ago

0.0.55

1 month ago

0.0.56

1 month ago

0.0.57

1 month ago

0.0.58

1 month ago

0.0.53

2 months ago

0.0.51

2 months ago

0.0.52

2 months ago

0.0.50

2 months ago

0.0.48

2 months ago

0.0.49

2 months ago

0.0.47

2 months ago

0.0.45

2 months ago

0.0.46

2 months ago

0.0.44

2 months ago

0.0.43

3 months ago

0.0.42

6 months ago

0.0.41

6 months ago

0.0.40

6 months ago

0.0.39

6 months ago

0.0.38

6 months ago

0.0.37

6 months ago

0.0.36

6 months ago

0.0.35

6 months ago

0.0.34

6 months ago

0.0.33

6 months ago

0.0.32

6 months ago

0.0.31

6 months ago

0.0.30

6 months ago

0.0.29

6 months ago

0.0.28

6 months ago

0.0.27

6 months ago

0.0.26

6 months ago

0.0.25

6 months ago

0.0.24

6 months ago

0.0.23

6 months ago

0.0.22

6 months ago

0.0.21

7 months ago

0.0.20

7 months ago

0.0.19

7 months ago

0.0.18

7 months ago

0.0.17

7 months ago

0.0.16

7 months ago

0.0.15

7 months ago

0.0.14

7 months ago

0.0.13

7 months ago

0.0.12

7 months ago

0.0.11

7 months ago

0.0.10

7 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago