Skip to content

Commit

Permalink
Control idents also for getInstance method, clear idents in unsetInst…
Browse files Browse the repository at this point in the history
…ance

#244
  • Loading branch information
ghettovoice committed Oct 30, 2019
1 parent 6bacf4d commit 457b078
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
32 changes: 28 additions & 4 deletions src/mixin/ident-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,18 @@ export default {
*/
instanceFactoryCall (ident, factory) {
if (ident && this.$identityMap.has(ident, INSTANCES_POOL)) {
this.idents[ident] = true
return this.$identityMap.get(ident, INSTANCES_POOL)
}

const val = factory()
const inst = factory()

if (ident) {
this.idents[ident] = true
this.$identityMap.set(ident, val, INSTANCES_POOL)
this.$identityMap.set(ident, inst, INSTANCES_POOL)
}

return val
return inst
},
/**
* @param {string|undefined} ident
Expand All @@ -87,14 +88,37 @@ export default {
getInstance (ident) {
if (!ident) return

if (!this.hasInstance(ident)) return

this.idents[ident] = true

return this.$identityMap.get(ident, INSTANCES_POOL)
},
/**
* @param {string|undefined} ident
* @returns {*}
*/
hasInstance (ident) {
if (!ident) return false

return this.$identityMap.has(ident, INSTANCES_POOL)
},
/**
* @param {string|undefined} ident
*/
unsetInstance (ident) {
if (!ident) return

delete this.idents[ident]

this.$identityMap.unset(ident, INSTANCES_POOL)
},
/**
* Unsets all self indets
* @return {void}
*/
unsetInstances () {
keys(this.idents).forEach(ident => this.$identityMap.unset(ident, INSTANCES_POOL))
keys(this.idents).forEach(::this.unsetInstance)
},
},
}
Expand Down
40 changes: 26 additions & 14 deletions test/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,40 @@
<!-- <vl-style-func :factory="createCountriesStyleFunc" />-->
<!--</vl-layer-vector>-->

<vl-layer-vector render-mode="image">
<!--<vl-source-cluster :distance="50">-->
<vl-source-vector :features="points" />
<!--</vl-source-cluster>-->
<!--<vl-style-func :factory="makeClusterStyleFunc" />-->
<vl-style-func :factory="makePointStyleFunc" />
</vl-layer-vector>
<!--<vl-layer-vector render-mode="image">-->
<!--<vl-source-cluster :distance="50">-->
<!-- <vl-source-vector :features="points" />-->
<!--</vl-source-cluster>-->
<!--<vl-style-func :factory="makeClusterStyleFunc" />-->
<!-- <vl-style-func :factory="makePointStyleFunc" />-->
<!--</vl-layer-vector>-->

<vl-layer-vector id="draw-target">
<vl-source-vector ident="draw-target" :features.sync="drawFeatures" />
</vl-layer-vector>

<!--<vl-interaction-select :features.sync="selectedFeatures" />-->
<vl-interaction-draw source="draw-target" type="Polygon" />
<!--<vl-interaction-modify source="draw-target" />-->
<vl-interaction-modify source="draw-target" />
</vl-map>
</div>
</div>
</template>

<script>
import { random, range, cloneDeep } from 'lodash'
import { Feature } from 'ol'
import { Point } from 'ol/geom'
import { range, random } from 'lodash'
import { createStyle, findPointOnSurface } from '../src/ol-ext'
const drawFeature = {
id: 1,
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]],
},
}
export default {
name: 'app',
data () {
Expand All @@ -72,7 +80,9 @@
featureId: undefined,
features: [],
selectedFeatures: [],
drawFeatures: [],
drawFeatures: [
cloneDeep(drawFeature),
],
controls: true,
interactions: true,
points: range(0, 100).map(i => ({
Expand Down Expand Up @@ -113,10 +123,10 @@
if (!style) {
style = createStyle({
imageRadius: 10,
strokeColor: '#fff',
strokeColor: '#ffffff',
fillColor: '#3399cc',
text: size.toString(),
textFillColor: '#fff',
textFillColor: '#ffffff',
})
cache[size] = style
Expand All @@ -142,8 +152,10 @@
}
},
toggleMap () {
this.drawFeatures = [
cloneDeep(drawFeature),
]
this.mapVisible = !this.mapVisible
this.drawFeatures = []
},
},
}
Expand Down

0 comments on commit 457b078

Please sign in to comment.