diegoazh / gmap-vue

A wrapper component for consuming Google Maps API built on top of Vue. Fork of the popular vue-google-maps plugin.
https://diegoazh.github.io/gmap-vue/
173 stars 51 forks source link

Need help on: Operate map by other component #285

Closed azusa5526 closed 1 year ago

azusa5526 commented 2 years ago

Please complete all sections that you can but please don't remove any section, otherwise the bot will close your issue because it doesn't meet our issue template (you can remove this comment)

What you try to do

Try to operate map by other component

What is the problem

In the same component, we can use $refs[some-map-ref].$mapObject to control the map like panTo(), setOptions() ... Now I want to control that map by another component like navbar's btn, I can't get the $mapObject by refs because there're not in the same component.

What kind of things have you already treated

I commit $refs[some-map-ref].$mapObject to Vuex in mounted hook and share this mapObject to navbar by ...mapGetters. So I can control that map by navbar btn. It works fine but not Vuex strict mode. If strict mode enabled, lots of maximum call stack size exceeded error shows in console. image

Someone can give me some hint to access maps by different components gracefully?

Live: https://azusa5526.github.io/map-test/ Or clone & run dev: https://github.com/azusa5526/map-test

Steps to reproduce

1.Create a new vue project with vuetify 2.Add gmap-vue library by npm 3.import GmapVue from 'gmap-vue' in main.js 4.add Vue.use GmapVue... in main.js 5.Copy App.vue, HelloWorld.vue, store/index.vue from my repo: https://github.com/azusa5526/map-test
6.Change store/index.vue 'strict: true / false' flag 7.Open dev sever and see errors

Os

Mobile

N/A

Versions

Package manager

Plugin version

davydnorris commented 2 years ago

This is not a GMap problem, this is a design problem. Components should be self contained, so there are two ways I would approach this: