var mapTalks = require('../../../components/maptalks/maptalks.min.js'); //require这个js模块
export default {
data() {
return {
tianYxlayer: new mapTalks.WMSTileLayer("tianYxlayer", {
urlTemplate:"地图地址",
crossOrigin: "Anonymous",
subdomains: [0, 1, 2, 3],
visible: false
}),
map: null
}
},
onLoad() {
this.initMap();
},
methods: {
initMap() {
this.map = new mapTalks.Map('mapDiv', {
center: [113.357791, 22.77644],
zoom: 8,
minZoom: 4,
maxZoom: 15,
attribution: {
content: ""
},
baseLayer: new mapTalks.GroupTileLayer(
"maps",
[this.tianYxlayer, this.tianditu_base],
{}
)
});
..........
}
}
异常信息:
[system]Error: Invalid container when creating map: 'mapDiv' at l.t._initContainer (webpack-internal:///mPkg:5643:76)
水月 (作者)
找到问题了,我把初始化地图方法写在了onLoad方法里,页面元素还没有加载完就执行了地图方法,导致找不到标签,地图初始化方法放在mounted()下就好了
2022-03-13 07:42
荞二哥
回复 水月: 请问打包成功了吗,maptalks文件超过500KB导致打包失败是怎么解决的呢
2023-10-31 19:09