操作流程:
- 引入依赖 npm i leaflet
- 在vue页面创建地图容器 <div id='map'></div>
- 加载地图
var mymap = L.map('gis_map').setView([51.505, -0.09], 13);
L.tileLayer('http://t2.tianditu.com/DataServer?T=cta_w&x={x}&y={y}&l={z}&tk=d0aa380508225cf04c37d1e39f7081e8', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox/streets-v11',
tileSize: 512,
zoomOffset: -1
}).addTo(mymap); - h5查看异常:
[Vue warn]: Error in onLoad hook: "Error: Map container not found."
found in
---> at pages/location/index.vue
chunk-vendors.js:98 [system] Error: Map container not found.
at NewClass._initContainer (pages-location-index.js:4074)
at NewClass.initialize (pages-location-index.js:3107)
at new NewClass (pages-location-index.js:304)
at Object.createMap [as map] (pages-location-index.js:4699)
at VueComponent.createGisMap (index.vue:54)
at VueComponent.onLoad (index.vue:66)
at invokeWithErrorHandling (chunk-vendors.js:5117)
at VueComponent.push../node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.esm.js.Vue.__call_hook (chunk-vendors.js:11859)
at r (chunk-vendors.js:98)
at a (chunk-vendors.js:98)
0 个回复