Skip to content

Commit

Permalink
Fix regression with draw/modify interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ghettovoice committed Jun 3, 2020
1 parent 96e36b7 commit 79e264e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions src/component/draw-interaction/interaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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),
Expand Down
23 changes: 19 additions & 4 deletions src/component/modify-interaction/interaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</vl-layer-tile>

<vl-layer-vector>
<vl-source-vector ref="vectorSource" :features.sync="features" :loader-factory="loader"></vl-source-vector>
<vl-source-vector ident="draw" ref="vectorSource" :features.sync="features" :loader-factory="loader"></vl-source-vector>
<vl-style-func :factory="styleFactory" />
</vl-layer-vector>

<vl-interaction-select :features.sync="selectedFeatures" />
<vl-interaction-select ident="modify" :features.sync="selectedFeatures" />
</vl-map>
</div>
</template>
Expand Down

0 comments on commit 79e264e

Please sign in to comment.