Я пытаюсь добавить пользовательский элемент управления на карту, используя OpenLayers с Vue.js.
У меня есть компонент Explore.vue, который создает мою «карту» (olmap) с использованием OL, и я передаю ее через привязку к дочернему компоненту LeftSideBar2.vue.
Когда я пытаюсь добавить новый элемент управления на карту, Vue показывает следующую ошибку:
[Vue warn]: Error in mounted hook: "TypeError: this.olmap.addControl is not a function"
Кто-то знает, что происходит?
Мои файлы:
Explore.vue:
Шаблон:
<explore-left-side-bar2 v-bind:olmap="olmap"/>
Сценарий:
export default {
name: 'Explore',
data () {
return {
olmap: {}
}
},
methods: {
initComponent: function () {
// eslint-disable-next-line
this.olmap = new Map({
target: 'map',
layers: [
baseLayerGroup
],
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
zoom: 5
})
})
}
},
mounted: function () {
this.initComponent()
},
components: {
ExploreLeftSideBar2
}
}
LeftSidebar2.vue:
Сценарий:
export default {
name: 'LeftSideBar2',
props: ['olmap'],
data () {
return {
}
},
methods: {
initComponent: function () {
var sidebar = new Sidebar({ element: 'ol-sb-sidebar', position: 'left' })
this.olmap.addControl(sidebar)
}
},
mounted: function () {
this.initComponent()
},
components: {
LeftSideBarLayerTree
}
}