gpt4 book ai didi

javascript - 在Vue中初始化 'marker-animate-unobtrusive'失败

转载 作者:行者123 更新时间:2023-12-02 23:49:12 26 4
gpt4 key购买 nike

我正在尝试使用marker-animate-unobtrusive,但我不断收到此错误:

enter image description here

我在 SO 上找到了另一篇文章谈到在谷歌加载后需要该文件,但我不知道该怎么做。在我的组件中我有这个:

import SlidingMarker from 'marker-animate-unobtrusive'

在我的安装方法中,我有这个:

SlidingMarker.initializeGlobally()

非常感谢任何帮助

最佳答案

这是预期的错误,因为 SlidingMarker 扩展了 google.maps.Marker class ,需要首先加载 GoogleMaps JavaScript API 库,一个选项是通过 index.html 文件添加引用:

<script src="https://maps.googleapis.com/maps/api/js?key=--KEY-GOES-HERE--"></script>   

另一种选择是使用异步 JavaScript 加载器,例如scriptjs 。加载 GoogleMaps JavaScript API 和 marker-animate-unobtrusive 模块的示例可能如下所示:

created: function(){
get("https://maps.googleapis.com/maps/api/js?key=", () => {

const SlidingMarker = require('marker-animate-unobtrusive')
SlidingMarker.initializeGlobally()

const map = new google.maps.Map(document.getElementById('map'), this.mapOptions);

const marker = new SlidingMarker({
position: this.mapOptions.center,
map: map,
title: 'Im sliding marker'
});
});

}

Here is a demo供您引用

更新

vue-google-maps library marker-animate-unobtrusive 插件可以这样集成:

<template>
<div>
<GmapMap :center="center" :zoom="zoom" ref="mapRef"></GmapMap>
</div>
</template>

<script>

/* global google */

export default {
data() {
return {
zoom: 12,
center: { lat: 51.5287718, lng: -0.2416804 },
};
},
mounted: function() {
this.$refs.mapRef.$mapPromise.then(() => {
this.initSlidingMarker(this.$refs.mapRef.$mapObject)
})
},
methods: {
initSlidingMarker(map){
const SlidingMarker = require('marker-animate-unobtrusive')
SlidingMarker.initializeGlobally()


const marker = new SlidingMarker({
position: map.getCenter(),
map: map,
title: 'Im sliding marker'
});

google.maps.event.addListener(map, 'click', (event) => {
marker.setDuration(1000);
marker.setEasing('linear');
marker.setPosition(event.latLng);
});
}
}
}
</script>

<style>
.vue-map-container {
height: 640px;
}
</style>

关于javascript - 在Vue中初始化 'marker-animate-unobtrusive'失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55716325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com