mapbox-extensions 中文
mapboxgl controls : measure、switch map、switch layers、doodle、back ...
<scriptsrc="https://cdn.jsdelivr.net/npm/mapbox-extensions@1.3.14/dist/mapbox-extensions.js"></script><linkhref="https://cdn.jsdelivr.net/npm/mapbox-extensions@1.3.14/dist/index.css" rel="stylesheet">npm install / yarn add mapbox-extensions
import { SwitchLayerControl } from 'mapbox-extensions'
import 'mapbox-extensions/dist/index.css'
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
map.addControl(newMeasureControl({horizontal : true,//default false btnBgColor : 'red',//default '#ffffff'btnActiveColor:'red',//default '#ddd'geometryClick:true,//defualt false enableModes:['LineString'],//default allonStart:()=>{},onStop:()=>{},measurePointOptions:{},measureLineStringOptions:{},measurePolygonOptions:{}}))- left click : add a point
- right click : remove a point
- left double click : finish measure and start next
map.addControl(newBackToOriginControl({}))map.addControl(newSwitchMapControl({satelliteOption:{name: "satellite",textColor : 'red',backgroundImage : "",},showSatelliteDefault:true,extra:{// default undefined, similar to SwitchLayerControlOptionsnailActiveColor : "red"}}));map.addControl(newSwitchLayerControl({name:"Layer Manager",position:"top-left",selectAndClearAll:true,selectAllLabel:"select all",clearAllLabel:"clear all",showToTop:true,topLayerId:"",layerGroups:{"layer group 1":{mutex:true,collapse:true,uiType:"SwitchBtn",layers:[{name:"layer1",layer: {},fixed:true,zoom:-100,easeToOptions:{},mutex:true,mutexIdentity:"t1",active:true,backgroundImage:"",backgroundImageActive:"",onVisibleChange:(visible:boolean)=>{}}]}}}));map.addControl(newExtendControl({img1 : "",img2 : "",content : div,position : "top-left",mustBe : "pc",onChange:(open:boolean)=>{}}));map.addControl(newDoodleControl({name: '',reName : '',exitText : '',lineColor : '',lineWidth : 1,polygonColor: '',polygonOpacity : 1,onStart: ()=>{measureControl.stop()},onDrawed: polygon=>{()=>{alert(JSON.stringify(polygon))}},onClear:()=>{},onExit:()=>{}}))






