Skip to content

Commit

Permalink
Merge pull request #16 from chrismayer/mapable
Browse files Browse the repository at this point in the history
Introduce 'Mapable' mixin
  • Loading branch information
chrismayer authored Apr 25, 2018
2 parents 582f566 + 2367c0a commit 3e74a56
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 36 deletions.
21 changes: 8 additions & 13 deletions src/components/layerlist/LayerList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
</template>

<script>
// Import the EventBus
import { WguEventBus } from '../../WguEventBus.js'
import { DraggableWin } from '../../directives/DraggableWin.js';
import { Mapable } from '../../mixins/Mapable';
export default {
directives: {
DraggableWin
},
mixins: [Mapable],
props: ['icon'],
data () {
return {
Expand All @@ -44,18 +44,13 @@
top: '70px'
}
},
created () {
var me = this
// Listen to the ol-map-mounted event and receive the OL map instance
WguEventBus.$on('ol-map-mounted', function (olMap) {
// make the OL map accesible in this component
me.map = olMap;
// create the layer items from the OL map
me.createLayerItems();
});
},
methods: {
/**
* This function is executed, after the map is bound (see mixins/Mapable)
*/
onMapBound () {
this.createLayerItems();
},
/**
* Creates the layer items from the OpenLayers map.
*/
Expand Down
22 changes: 9 additions & 13 deletions src/components/measuretool/MeasureWin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
</template>

<script>
// Import the EventBus
import { WguEventBus } from '../../WguEventBus.js'
import { DraggableWin } from '../../directives/DraggableWin.js';
import { DraggableWin } from '../../directives/DraggableWin';
import { Mapable } from '../../mixins/Mapable';
import DrawInteraction from 'ol/interaction/draw'
import LineStringGeom from 'ol/geom/linestring'
import PolygonGeom from 'ol/geom/polygon'
Expand All @@ -56,6 +55,7 @@
directives: {
DraggableWin
},
mixins: [Mapable],
props: ['icon'],
data () {
return {
Expand All @@ -67,16 +67,6 @@
top: '200px'
}
},
created () {
var me = this;
// Listen to the ol-map-mounted event and receive the OL map instance
WguEventBus.$on('ol-map-mounted', (olMap) => {
// make the OL map accesible in this component
me.map = olMap;
me.createMeasureLayer();
});
},
watch: {
show () {
var me = this;
Expand All @@ -92,6 +82,12 @@
}
},
methods: {
/**
* This function is executed, after the map is bound (see mixins/Mapable)
*/
onMapBound () {
this.createMeasureLayer();
},
/**
* Creates a vector layer for the measurement results and adds it to the
* map.
Expand Down
20 changes: 20 additions & 0 deletions src/mixins/Mapable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// import Vue from 'vue';

import { WguEventBus } from '../WguEventBus.js'

/**
* Mixin, which binds the OL map to the target component.
* Executes the onMapBound function of the target component, if available.
*/
export const Mapable = {
created: function () {
WguEventBus.$on('ol-map-mounted', (olMap) => {
// make the OL map accesible in this component
this.map = olMap;

if (this.onMapBound) {
this.onMapBound();
}
});
}
};
5 changes: 0 additions & 5 deletions test/unit/specs/layerlist/LayerList.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import Vue from 'vue'
import LayerList from '@/components/layerlist/LayerList'

describe('layerlist/LayerList.vue', () => {
// Inspect the raw component options
it('has a created hook', () => {
expect(typeof LayerList.created).to.equal('function');
});

// Evaluate the results of functions in
// the raw component options
it('sets the correct default data', () => {
Expand Down
5 changes: 0 additions & 5 deletions test/unit/specs/measuretool/MeasureWin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import Vue from 'vue'
import MeasureWin from '@/components/measuretool/MeasureWin'

describe('measuretool/MeasureWin.vue', () => {
// Inspect the raw component options
it('has a created hook', () => {
expect(typeof MeasureWin.created).to.equal('function');
});

// Evaluate the results of functions in
// the raw component options
it('sets the correct default data', () => {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/specs/mixins/Mapable.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Mapable from '@/mixins/Mapable'

describe('Mapable.js', () => {
it('is defined', () => {
expect(typeof Mapable).to.not.equal(undefined);
});
});

0 comments on commit 3e74a56

Please sign in to comment.