inocan-group / vue3-google-map

A set of composable components for easy use of Google Maps in your Vue 3 projects.
https://vue3-google-map.com
MIT License
295 stars 60 forks source link

Traffic Layer #271

Closed hdrodel closed 3 months ago

hdrodel commented 3 months ago

What would be the best practice to display a traffic layer on the map?

hdrodel commented 3 months ago

I got something working but i don't know if that really is how it was supposed to be done

<template>
<GoogleMap
   api-key="<key>"
   :api="google"
   ref="mapRef"
    > 
    <!--adding markers here-->
</GoogleMap>
</template>
<script>
import { Loader } from "@googlemaps/js-api-loader";
export default {
  data() {
    return {
    google: null,
    loader: new Loader({apiKey: <key>, version: "weekly"})
};
  },

  async mounted() {
    this.google = await this.loader.importLibrary("maps");
    this.trafficLayer = new this.google.TrafficLayer();
    await nextTick();
    console.log(this.trafficLayer);
    this.trafficLayer.setMap(this.$refs.mapRef.map);
},

};
</script>

Any better way to do this?