1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
<script> import store from '@/store'; export default { name: 'home', data () { return { map: null, L: null, baseLayer: null, msg: '高德地图', map_config: { zoom: 15, center: [30.541093, 114.360734], minZoom: 2, maxZoom: 18 } }; }, mounted () { this.initMap(); }, methods: { initMap () { this.L = L; let map = L.map("map", { center: this.map_config.center, zoom: this.map_config.zoom }); this.map = map; this.addLayer(L, map, store.state.layerItems['gd_n_a'],18, 3); }, addLayer (L, map, layer_name, maxZoom, minZoom) { if (this.baseLayer !== null) { map.removeLayer(this.baseLayer); } this.baseLayer = L.tileLayer.chinaProvider(layer_name, { maxZoom: maxZoom === undefined ? this.map_config.maxZoom : maxZoom, minZoom: minZoom === undefined ? this.map_config.minZoom : minZoom }); map.addLayer(this.baseLayer); }, returnHome () { this.map.setView(this.map_config.center, 15); }, mapSet (map_name, L = this.L, map = this.map) { switch (map_name) { case 'gd': this.addLayer(L, map, store.state.layerItems['gd_n_a'], 18, 3); this.msg = '高德地图 '; break; case 'glg': this.addLayer(L, map, store.state.layerItems['glg_n']); this.msg = '谷歌地图 '; break; case 'geo': this.addLayer(L, map, store.state.layerItems['geo_n_g'], 16); this.msg = ' 智图 '; break; case 'osm': this.addLayer(L, map, store.state.layerItems['osm']); this.msg = 'OSM地图'; break; case 'box': if (this.baseLayer !== null) { map.removeLayer(this.baseLayer); } this.baseLayer = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?' + 'access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', { id: store.state.layerItems['box'], minZoom: 3 }); map.addLayer(this.baseLayer); this.msg = 'Mapbox'; break; default: break; } }, }, } </script>
|