Skip to content

Commit

Permalink
Improve handling of instances in the identity map.
Browse files Browse the repository at this point in the history
Enclose all related instances into the identity map too with the main ol
instance. Clear identity map on component deinit.

#244
  • Loading branch information
ghettovoice committed Oct 25, 2019
1 parent a2c14c4 commit 1636fc6
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 240 deletions.
16 changes: 7 additions & 9 deletions src/component/draw-interaction/interaction.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script>
import { noModifierKeys, shiftKeyOnly } from 'ol/events/condition'
import DrawInteraction from 'ol/interaction/Draw'
import { Collection } from 'ol'
import { Draw as DrawInteraction } from 'ol/interaction'
import { Vector as VectorSource } from 'ol/source'
import { merge as mergeObs } from 'rxjs/observable'
import { map as mapObs } from 'rxjs/operators'
import { interaction, stylesContainer } from '../../mixin'
Expand All @@ -9,11 +11,9 @@
defaultEditStyle,
GEOMETRY_TYPE,
initializeFeature,
isCollection,
isVectorSource,
} from '../../ol-ext'
import { observableFromOlEvent } from '../../rx-ext'
import { assert, hasInteraction } from '../../util/assert'
import { hasInteraction, instanceOf } from '../../util/assert'
import { camelCase, mapValues, upperFirst } from '../../util/minilo'
import mergeDescriptors from '../../util/multi-merge-descriptors'
import { makeWatchers } from '../../util/vue-helpers'
Expand Down Expand Up @@ -153,11 +153,9 @@
* @protected
*/
async createInteraction () {
let sourceIdent = this.makeIdent(this.source)
let source = await this.$identityMap.get(sourceIdent, this.$options.INSTANCE_PROMISE_POOL)
assert(isVectorSource(source), `Source "${sourceIdent}" doesn't exists in the identity map.`)
assert(isCollection(source.getFeaturesCollection()),
`Source "${sourceIdent}" doesn't provide features collection.`)
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.`)
return new DrawInteraction({
features: source.getFeaturesCollection(),
Expand Down
16 changes: 8 additions & 8 deletions src/component/modify-interaction/interaction.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script>
import { altKeyOnly, always, primaryAction } from 'ol/events/condition'
import ModifyInteraction from 'ol/interaction/Modify'
import { Collection } from 'ol'
import { Modify as ModifyInteraction } from 'ol/interaction'
import { Vector as VectorSource } from 'ol/source'
import { interaction, stylesContainer } from '../../mixin'
import { createStyle, defaultEditStyle, isCollection, isVectorSource } from '../../ol-ext'
import { createStyle, defaultEditStyle } from '../../ol-ext'
import { observableFromOlEvent } from '../../rx-ext'
import { assert, hasInteraction } from '../../util/assert'
import { hasInteraction, instanceOf } from '../../util/assert'
import { mapValues } from '../../util/minilo'
import mergeDescriptors from '../../util/multi-merge-descriptors'
import { makeWatchers } from '../../util/vue-helpers'
Expand Down Expand Up @@ -85,11 +87,9 @@
* @protected
*/
async createInteraction () {
let sourceIdent = this.makeIdent(this.source)
let source = await this.$identityMap.get(sourceIdent, this.$options.INSTANCE_PROMISE_POOL)
assert(isVectorSource(source), `Source "${sourceIdent}" doesn't exists in the identity map.`)
assert(isCollection(source.getFeaturesCollection()),
`Source "${sourceIdent}" doesn't provide features collection.`)
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.`)
return new ModifyInteraction({
features: source.getFeaturesCollection(),
Expand Down
160 changes: 76 additions & 84 deletions src/component/snap-interaction/interaction.vue
Original file line number Diff line number Diff line change
@@ -1,87 +1,9 @@
<script>
import SnapInteraction from 'ol/interaction/Snap'
import { Snap as SnapInteraction } from 'ol/interaction'
import { Source } from 'ol/source'
import { interaction } from '../../mixin'
import { makeWatchers } from '../../util/vue-helpers'
/**
* @vueProps
*/
const props = {
/**
* Target source identifier from IdentityMap.
* @type {string}
*/
source: {
type: String,
required: true,
},
/**
* Snap to edges
* @type {boolean}
*/
edge: {
type: Boolean,
default: true,
},
/**
* Snap to vertices.
* @type {boolean}
*/
vertex: {
type: Boolean,
default: true,
},
/**
* Pixel tolerance for considering the pointer close enough to a segment or vertex for snapping.
* @type {number}
*/
pixelTolerance: {
type: Number,
default: 10,
},
}
/**
* @vueMethods
*/
const methods = {
/**
* @return {Promise<Snap>}
* @protected
*/
async createInteraction () {
let sourceIdent = this.makeIdent(this.source)
let source = await this.$identityMap.get(sourceIdent, this.$options.INSTANCE_PROMISE_POOL)
return new SnapInteraction({
source: source,
})
},
/**
* @return {void}
* @protected
*/
mount () {
this::interaction.methods.mount()
},
/**
* @return {void}
* @protected
*/
unmount () {
this::interaction.methods.unmount()
},
/**
* @return {void}
* @protected
*/
subscribeAll () {
},
}
const watch = makeWatchers(['source'], () => function () {
this.scheduleRecreate()
})
import { instanceOf } from '../../util/assert'
/**
* @alias module:snap-interaction/interaction
Expand All @@ -91,8 +13,78 @@
export default {
name: 'vl-interaction-snap',
mixins: [interaction],
props,
methods,
watch,
props: {
/**
* Target source identifier from IdentityMap.
* @type {string}
*/
source: {
type: String,
required: true,
},
/**
* Snap to edges
* @type {boolean}
*/
edge: {
type: Boolean,
default: true,
},
/**
* Snap to vertices.
* @type {boolean}
*/
vertex: {
type: Boolean,
default: true,
},
/**
* Pixel tolerance for considering the pointer close enough to a segment or vertex for snapping.
* @type {number}
*/
pixelTolerance: {
type: Number,
default: 10,
},
},
watch: {
...makeWatchers(['source'], () => function () {
this.scheduleRecreate()
}),
},
methods: {
/**
* @return {Promise<Snap>}
* @protected
*/
async createInteraction () {
let source = await this.getInstance(this.source)
instanceOf(source, Source, `Source "${this.source}" doesn't exists in the identity map.`)
return new SnapInteraction({
source,
})
},
/**
* @return {void}
* @protected
*/
mount () {
this::interaction.methods.mount()
},
/**
* @return {void}
* @protected
*/
unmount () {
this::interaction.methods.unmount()
},
/**
* @return {void}
* @protected
*/
subscribeAll () {
},
},
}
</script>
7 changes: 6 additions & 1 deletion src/component/vector-source/source.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@
loadingStrategy () {
return this.strategyFactory()
},
dataFormatIdent () {
if (!this.olObjIdent) return
return this.makeIdent(this.olObjIdent, 'data_format')
},
dataFormat () {
return this.formatFactory()
return this.instanceFactoryCall(this.dataFormatIdent, ::this.formatFactory)
},
},
methods: {
Expand Down
14 changes: 8 additions & 6 deletions src/mixin/features-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { instanceOf } from '../util/assert'
import { forEach, isPlainObject } from '../util/minilo'
import projTransforms from './proj-transforms'
import rxSubs from './rx-subs'
import identMap from './ident-map'
import { observableFromOlEvent } from '../rx-ext'

export default {
mixins: [rxSubs, projTransforms],
mixins: [identMap, rxSubs, projTransforms],
computed: {
featureIds () {
if (!this.rev) return []
Expand All @@ -28,6 +29,11 @@ export default {

return this.getFeatures().map(::this.writeFeatureInDataProj)
},
featuresCollectionIdent () {
if (!this.olObjIdent) return

return this.makeIdent(this.olObjIdent, 'features_collection')
},
},
methods: {
/**
Expand Down Expand Up @@ -116,11 +122,7 @@ export default {
},
},
created () {
/**
* @type {Collection<Feature>>}
* @private
*/
this._featuresCollection = new Collection()
this._featuresCollection = this.instanceFactoryCall(this.featuresCollectionIdent, () => new Collection())
this._featureSubs = {}

this::defineServices()
Expand Down
Loading

0 comments on commit 1636fc6

Please sign in to comment.