报这个错
static_qqmapWxJssdk_min.QQMapWX is not a constructor
<script>
import QQMapWX from '../../static/qqmap-wx-jssdk.min.js';
// 实例化API核心类
var qqmapsdk = new QQMapWX({
key: '47TBZ' // 这个我填的是正确的,这里就不粘上来了
});
const img = '/static/location.png';
const positions = [{
latitude: 41.791503,
longitude: 123.469462,
name: "景点一"
},
{
latitude: 41.789248,
longitude: 123.47108,
name: "景点二"
},
{
latitude: 41.786731,
longitude: 123.475723,
name: "景点三"
},
{
latitude: 41.792552,
longitude: 123.479451,
name: "景点四"
},
]
export default {
data() {
return {
latitude: 41.789773,
longitude: 123.475019,
southwest: [41.799628, 123.457275],
northeast: [41.797672, 123.453753],
covers: [{
latitude: 23.099994,
longitude: 113.324520,
iconPath: '/static/location.png'
}, {
latitude: 23.099994,
longitude: 113.322520,
iconPath: '/static/location.png'
}, {
latitude: 23.099994,
longitude: 113.326520,
iconPath: '/static/location.png'
}, {
latitude: 23.096994,
longitude: 113.329520,
iconPath: '/static/location.png'
}]
}
},
onLoad() {
this._mapContext = uni.createMapContext("map", this);
// 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
this._mapContext.addGroundOverlay({
id: 11,
src: "/static/dongwuyuan.jpg", //手绘地图素材路径
bounds: {
southwest: {
latitude: 41.786865,
longitude: 123.46956
},
northeast: {
latitude: 41.79237,
longitude: 123.480648
}
},
visiable: true,
zIndex: 1000,
success: () => {
console.log("显示成功", this.southwest, this.northeast)
},
fail: (e) => {
console.log("显示失败", e)
}
})
this._mapContext.on("markerClusterCreate", (e) => {
console.log("markerClusterCreate", e);
});
this.addMarkers();
},
methods: {
getPoint(latitude, longitude) {
//使用jdk的方法解析
qqmapsdk.reverseGeocoder({
location: [latitude, longitude].join(','),
success: function(res) {
console.log('我在哪',res.result);
}
})
},
markTap(e) {
console.log('ccccccc')
console.log(e)
console.log('ccccccc')
positions.forEach((item, index) => {
if (index == e.markerId) {
console.log('item', item)
}
})
// uni.showToast({
// title: `客户名称${e.markerId}`
// })
},
// 在需要获取位置的地方调用该方法
getLocat() {
console.log("我进来了吗")
let that= this
uni.getLocation({
type: 'gcj02', // 返回可以用于uni.openLocation的经纬度
success: res => {
console.log('当前位置信息:', res);
// 处理获取位置信息成功后的逻辑
console.log('当前位置信息1:', res.latitude);
console.log('当前位置信息2:', res.longitude);
that.getPoint(res.latitude,res.longitude)
},
fail: err => {
console.error('获取位置信息失败', err);
// 处理获取位置信息失败后的逻辑
}
});
},
addMarkers() {
console.log("我进来了吗")
const markers = []
positions.forEach((p, i) => {
console.log('我是P', p)
console.log('我是i', i)
markers.push(
Object.assign({}, {
id: i,
iconPath: img,
width: 50,
height: 50,
//joinCluster: true, // 指定了该参数才会参与聚合
label: {
width: 50,
height: 30,
borderWidth: 1,
borderRadius: 10,
bgColor: '#ffffff',
content: `${p.name}`
}
}, p)
)
})
this._mapContext.addMarkers({
markers,
clear: false,
complete(res) {
console.log('addMarkers', res)
}
})
}
}
}
</script>
<style>
.content {
width: 100%;
height: 100%;
}
.add {
width: 100%;
height: 200rpx;
position: absolute;
bottom: 0;
left: 0;
background: #fff;
z-index: 500000;
}
.map {
position: absolute;
width: 100%;
height: 100%;
}
</style>
打开文件最后的输出改一下,把 module.exports 导出方式改成 export