caitxj_alone
caitxj_alone
  • 发布:2021-05-15 11:15
  • 更新:2021-05-15 11:15
  • 阅读:3241

uni-app 使用leaflet + 天地图自定义地图使用问题

分类:uni-app

操作流程:

  1. 引入依赖 npm i leaflet
  2. 在vue页面创建地图容器 <div id='map'></div>
  3. 加载地图
    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);
  4. 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)

2021-05-15 11:15 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复