-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathFeatureInfoWindow.vue
More file actions
129 lines (117 loc) · 4.1 KB
/
FeatureInfoWindow.vue
File metadata and controls
129 lines (117 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
<v-card
class="wgu-feature-infowindow info-card"
v-draggable-win="draggable"
v-if="this.feature !== null"
v-bind:style="{ left: left, top: top, width: width }" >
<v-toolbar :color="color" class="" dark>
<v-toolbar-side-icon><v-icon>{{icon}}</v-icon></v-toolbar-side-icon>
<v-toolbar-title>{{title}}</v-toolbar-title>
<v-spacer></v-spacer>
<v-toolbar-side-icon @click="onWinXClose"><v-icon>close</v-icon></v-toolbar-side-icon>
</v-toolbar>
<v-img v-if="attributes[imageProp]" :src="attributes[imageProp]" :width="imageWidth" :height="imageHeight" />
<v-card-title v-if="attributes[titleProp]" primary-title>
<h3 class="headline mb-0">{{attributes[titleProp]}}</h3>
</v-card-title>
<v-card-text v-if="attributes[descProp]">{{attributes[descProp]}}</v-card-text>
<v-card-actions>
<v-btn v-if="attributes[infoUrlProp]" flat color="blue" :href="attributes[infoUrlProp]" target="_blank">{{infoUrlText}}</v-btn>
</v-card-actions>
</v-card>
</template>
<script>
import { WguEventBus } from '../WguEventBus.js';
import { DraggableWin } from '../directives/DraggableWin.js';
export default {
name: 'wgu-feature-info-window-win',
directives: {
DraggableWin
},
props: {
icon: {type: String, required: false, default: 'info'},
color: {type: String, required: false, default: 'red darken-3'},
draggable: {type: Boolean, required: false, default: true}
},
data () {
return {
// will be filled in when mounted and when feature clicked
layers: null,
feature: null,
attributes: null,
width: null,
left: null,
top: null,
title: 'Feature Info',
titleProp: null,
imageProp: null,
descProp: null,
infoUrlProp: null,
infoUrlText: null,
imageHeight: null,
imageWidth: null
}
},
mounted () {
const config = this.$appConfig.modules['wgu-feature-info-window'] || {};
this.layers = config.layers;
if (this.layers) {
// Using a regular expression to Match layers
this.layers.forEach(layer => { layer.layerId = new RegExp(layer.layerId) });
}
this.left = config.initPos ? this.initPos.left + 'px' : '300px';
this.top = config.initPos ? this.initPos.top + 'px' : '200px';
this.width = config.width ? config.width + 'px' : '350px';
// listen to selection events of connected layer and apply attributes
WguEventBus.$on('map-selectionchange', (layerId, selected, deselected) => {
if (selected.length === 0) {
return;
}
const layer = this.findLayer(layerId);
if (!layer) {
return;
}
// {...layer}; TODO How to use Object Spread
this.layerId = layer.layerId;
this.title = layer.title || layer.titleProp || 'Feature Info';
this.titleProp = layer.titleProp;
this.descProp = layer.descProp;
this.imageProp = layer.imageProp;
this.imageHeight = layer.imageHeight;
this.imageWidth = layer.imageWidth;
this.infoUrlProp = layer.infoUrlProp;
this.infoUrlText = layer.infoUrlText || 'More info...';
this.setFeature(selected[0]);
});
},
methods: {
/**
* Sets the feature and its attributes as properties
* @param {ol.Feature} feature The new feature
*/
setFeature (feature) {
this.feature = feature;
this.attributes = this.feature ? this.feature.getProperties() : null;
},
/**
* Find a layer in our target Layer collection by layer name (layerId).
* @param {layerId} layerId layer name
*/
findLayer (layerId) {
const targetLayerArr = this.layers.filter(layer => layerId.match(layer.layerId));
return targetLayerArr.length > 0 ? targetLayerArr[0] : null;
},
onWinXClose: function () {
// this.feature.deselected; TODO: how to deselect Feature on Map?
this.setFeature(null);
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.wgu-feature-infowindow.info-card {
position: absolute;
background-color: white;
}
</style>