From 79e264e59d2aa6a82a0b09991dd2f4e89446d12c Mon Sep 17 00:00:00 2001 From: Vladimir Vershinin Date: Wed, 3 Jun 2020 17:00:59 +0300 Subject: [PATCH] Fix regression with draw/modify interactions https://github.com/ghettovoice/vuelayers/issues/234#issuecomment-638144839 --- .idea/jsLibraryMappings.xml | 4 ++-- .../draw-interaction/interaction.vue | 17 ++++++++++---- .../modify-interaction/interaction.vue | 23 +++++++++++++++---- test/app.vue | 4 ++-- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml index fd029570..6fb31752 100644 --- a/.idea/jsLibraryMappings.xml +++ b/.idea/jsLibraryMappings.xml @@ -1,8 +1,8 @@ - - + + \ No newline at end of file diff --git a/src/component/draw-interaction/interaction.vue b/src/component/draw-interaction/interaction.vue index 8069ebd2..ea3e61f9 100644 --- a/src/component/draw-interaction/interaction.vue +++ b/src/component/draw-interaction/interaction.vue @@ -14,7 +14,7 @@ } from '../../ol-ext' import { observableFromOlEvent } from '../../rx-ext' import { hasInteraction, instanceOf } from '../../util/assert' - import { camelCase, mapValues, upperFirst } from '../../util/minilo' + import { camelCase, isFunction, mapValues, upperFirst } from '../../util/minilo' import mergeDescriptors from '../../util/multi-merge-descriptors' import { makeWatchers } from '../../util/vue-helpers' @@ -154,11 +154,20 @@ */ async createInteraction () { let source = await this.getInstance(this.source) - instanceOf(source, VectorSource, `Source "${this.source}" doesn't exists in the identity map.`) - instanceOf(source.getFeaturesCollection(), Collection, `Source "${this.source}" doesn't provide features collection.`) + let features + if (!(source instanceof VectorSource)) { + if (isFunction(source.getFeaturesCollection)) { + features = source.getFeaturesCollection() + } else if (isFunction(source.getFeatures)) { + features = source.getFeatures() + } + instanceOf(features, Collection, `Source "${this.source}" doesn't provide features collection.`) + source = null + } return new DrawInteraction({ - features: source.getFeaturesCollection(), + source, + features, clickTolerance: this.clickTolerance, snapTolerance: this.snapTolerance, type: transformType(this.type), diff --git a/src/component/modify-interaction/interaction.vue b/src/component/modify-interaction/interaction.vue index 5ecda4aa..97692c48 100644 --- a/src/component/modify-interaction/interaction.vue +++ b/src/component/modify-interaction/interaction.vue @@ -7,7 +7,7 @@ import { createStyle, defaultEditStyle } from '../../ol-ext' import { observableFromOlEvent } from '../../rx-ext' import { hasInteraction, instanceOf } from '../../util/assert' - import { mapValues } from '../../util/minilo' + import { mapValues, isFunction } from '../../util/minilo' import mergeDescriptors from '../../util/multi-merge-descriptors' import { makeWatchers } from '../../util/vue-helpers' @@ -88,11 +88,26 @@ */ async createInteraction () { let source = await this.getInstance(this.source) - instanceOf(source, VectorSource, `Source "${this.source}" doesn't exists in the identity map.`) - instanceOf(source.getFeaturesCollection(), Collection, `Source "${this.source}" doesn't provide features collection.`) + let features + if (source instanceof VectorSource) { + features = source.getFeaturesCollection() + if (features) { + instanceOf(features, Collection, `Source "${this.source}" doesn't provide features collection.`) + source = null + } + } else { + if (isFunction(source.getFeaturesCollection)) { + features = source.getFeaturesCollection() + } else if (isFunction(source.getFeatures)) { + features = source.getFeatures() + } + instanceOf(features, Collection, `Source "${this.source}" doesn't provide features collection.`) + source = null + } return new ModifyInteraction({ - features: source.getFeaturesCollection(), + source, + features, deleteCondition: this.deleteCondition, insertVertexCondition: this.insertVertexCondition, pixelTolerance: this.pixelTolerance, diff --git a/test/app.vue b/test/app.vue index fac4a3aa..de2890ba 100644 --- a/test/app.vue +++ b/test/app.vue @@ -12,11 +12,11 @@ - + - +