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 the internal ol.Map instance? #220

Closed
frankhommers opened this issue Aug 26, 2019 · 4 comments
Closed

How to access the internal ol.Map instance? #220

frankhommers opened this issue Aug 26, 2019 · 4 comments
Assignees

Comments

@frankhommers
Copy link

In #95 you mention the accessing of the ol.Map instance directly. I want to do this, but I am not sure how? Can you point me in the right direction? Or preferrably give an example?

@ghettovoice
Copy link
Owner

Hello @frankhommers!
Basically any vuelayers component fires several life cycle events: created, mounted, destroyed. This events are relevant for underlying openlayers instance that is used in the component.

So for your use case, you should listen for created event on the vl-map component:

<template>
  <vl-map @created="mapCreated">
  ...
  </vl-map>
</template>

<script>
export default {
  ...
  methods: {
    /**
     * @param vm vl-map component instance
     */
    mapCreated (vm) {
       console.log(vm) // vl-map instance
       console.log(vm.$map) // ol.Map instance
    },
  },
}
</script>

Another method is based on the using of the ref attribute and life cycle promise.

<template>
  <vl-map ref="map">
  ...
  </vl-map>
</template>

<script>
export default {
  ...
  mounted () {
    this.$refs.map.$createPromise.then(vm => {
      console.log(vm) // vl-map instance
      console.log(vm.$map) // ol.Map instance
    })
  },
}
</script>

You can use this methods to get openlayers instance from any component.
There are common instance getters:

- vl-view -> vm.$view
- vl-layer-* -> vm.$layer
- vl-source-* > vm.$source
- vl-interaction-* -> vm.$interaction

@ghettovoice ghettovoice self-assigned this Aug 26, 2019
@frankhommers
Copy link
Author

Thanks for the answers! I will check them (or a colleague) tomorrow ;-)

@frankhommers
Copy link
Author

Yes this works! Thanks!

@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 29, 2019
@stale stale bot closed this as completed Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants