| | |
| | | class BasemapHelper { |
| | | constructor (options) { |
| | | this.map = options.map |
| | | this.L = options.L |
| | | this.L = window.L |
| | | this.basemapList = [] |
| | | this.basemapMap = new Map() |
| | | this.basemapLayerGroup = options.L.layerGroup().addTo(options.map) |
| | | this.basemapLayerGroup = this.L.layerGroup().addTo(options.map) |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param layer 待显示图层引用 |
| | | * @param isHideOthers 是否先关闭其他图层,默认是true |
| | | */ |
| | | showBasemap = (code, isHideOthers = true) => { |
| | | showBasemap = (code, showAnnotation, isHideOthers = true) => { |
| | | const basemap = this.basemapMap.get(code) |
| | | if (isHideOthers) { |
| | | for (let i = 0, len = this.basemapList.length; i < len; ++i) { |
| | | this.map.removeLayer(this.basemapList[i].layer) |
| | | this.map.removeLayer(this.basemapList[i].annotation) |
| | | } |
| | | this.basemapLayerGroup.clearLayers() |
| | | } |
| | | this.map.addLayer(basemap.layer) |
| | | this.map.addLayer(basemap.annotation) |
| | | this.basemapLayerGroup.addLayer(basemap.layer) |
| | | if (showAnnotation) { |
| | | this.basemapLayerGroup.addLayer(basemap.annotation) |
| | | } |
| | | } |
| | | |
| | | /** |