Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access map actions on marker click? #187

Open
AntonERG opened this issue Jun 7, 2020 · 1 comment
Open

How to access map actions on marker click? #187

AntonERG opened this issue Jun 7, 2020 · 1 comment

Comments

@AntonERG
Copy link

AntonERG commented Jun 7, 2020

I'm trying to call map action on the event of marker click, there is no errors in console, but action doesn't happen, my code example is:

<template>
    <div id="q-map">
          <MglMap :mapStyle="mapStyle"
             :center="[filtItems[selectedID].longitude, filtItems[selectedID].latitude]"
             :zoom="14"
              ref="map">
                  <MglMarker v-for="(item, idx) in filtItems" :key="idx" :coordinates="[item.longitude, item.latitude]">
                      <div slot="marker" :id="item.name" @click="pinSelected(idx)">
                      </div>
                  </MglMarker>
            </MglMap>
    </div>
</template>

<script>
   export default {
        methods: {
          async pinSelected (idx) {
             var me = this
             me.$refs.map.map.panTo({
                 coordinates: [30, 30]
             })
          }
       }
  }
</script>

@AntonERG
Copy link
Author

AntonERG commented Jun 8, 2020

Found my bug and working solution !!!

So, I have to remove prop center from <template> at all and instead of panTo I tried flyTo, here is my working code:

<template>
    <div id="q-map">
          <MglMap :mapStyle="mapStyle"
             :zoom="14"
              ref="map">
                  <MglMarker v-for="(item, idx) in filtItems" :key="idx" :coordinates="[item.longitude, item.latitude]">
                      <div slot="marker" :id="item.name" @click="pinSelected(idx)">
                      </div>
                  </MglMarker>
            </MglMap>
    </div>
</template>

<script>
   export default {
        methods: {
          pinSelected (idx) {
             var me = this
             me.$refs.map.map.flyTo({
                 center: [30, 30]
             })
          }
       }
  }
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant