Skip to content

Commit c7cdc2d

Browse files
committed
WIP wegue-oss#122 Share Button for permalink
1 parent 89bd794 commit c7cdc2d

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

src/components/AppHeader.vue

+2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ import LayerListToggleButton from './layerlist/ToggleButton'
5858
import HelpWinToggleButton from './helpwin/ToggleButton'
5959
import MeasureToolToggleButton from './measuretool/ToggleButton'
6060
import InfoClickButton from './infoclick/ToggleButton'
61+
import ShareButton from './sharebutton/ShareButton'
6162
import ZoomToMaxExtentButton from './maxextentbutton/ZoomToMaxExtentButton'
6263
import Geocoder from './geocoder/Geocoder'
6364
6465
export default {
6566
name: 'wgu-app-header',
6667
components: {
68+
'wgu-share-btn': ShareButton,
6769
'wgu-geocoder-btn': Geocoder,
6870
'wgu-zoomtomaxextent-btn': ZoomToMaxExtentButton,
6971
'wgu-layerlist-btn': LayerListToggleButton,

src/components/ol/Map.vue

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export default {
104104
105105
if (this.$appConfig.permalink) {
106106
this.permalinkController = this.createPermalinkController();
107+
this.map.set('permalinkcontroller', this.permalinkController, true);
107108
this.permalinkController.apply();
108109
this.permalinkController.setup();
109110
}

src/components/ol/PermalinkController.js

+7
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ export default class PermalinkController {
194194
return this.conf.separator + UrlUtil.toQueryString(this.urlParams);
195195
}
196196

197+
/**
198+
* Get full URL with permalink string for sharing.
199+
*/
200+
getShareUrl () {
201+
return location.href.split(this.conf.separator)[0] + this.getParamStr();
202+
}
203+
197204
/**
198205
* Get array of visible layer id's.
199206
*/
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<template>
2+
<div>
3+
<div>
4+
<v-btn icon :dark="dark" @click="onClick">
5+
<v-icon medium>{{icon}}</v-icon>
6+
{{text}}
7+
</v-btn>
8+
<textarea id="permalinkurl" ref="permalinkurl" style="display: none; position: relative"></textarea>
9+
</div>
10+
<v-alert
11+
class="wgu-alert"
12+
:value="alert"
13+
:dark="dark"
14+
type="info"
15+
transition="fade-transition"
16+
>
17+
{{alertText}}
18+
</v-alert>
19+
</div>
20+
</template>
21+
22+
<script>
23+
24+
import { Mapable } from '../../mixins/Mapable';
25+
26+
export default {
27+
name: 'wgu-share-btn',
28+
mixins: [Mapable],
29+
props: {
30+
icon: {type: String, required: false, default: 'share'},
31+
text: {type: String, required: false, default: ''},
32+
alertText: {type: String, required: false, default: 'Link copied!'},
33+
alertTimeMillis: {type: Number, required: false, default: 750},
34+
dark: {type: Boolean, required: false, default: false}
35+
},
36+
data () {
37+
return {
38+
alert: false
39+
}
40+
},
41+
methods: {
42+
onClick () {
43+
// Get permalink URL and copy to clipboard
44+
const permalinkController = this.map.get('permalinkcontroller');
45+
if (!permalinkController) {
46+
console.error('no permalink controller available!');
47+
return true;
48+
}
49+
try {
50+
// Copy to clipboard: selected text needs to be visible so
51+
// toggle textarea short time
52+
const url = permalinkController.getShareUrl();
53+
const textArea = this.$refs.permalinkurl;
54+
// Show and select textarea
55+
textArea.style.display = 'block';
56+
textArea.value = url;
57+
textArea.select();
58+
59+
// Copy to clipboard
60+
document.execCommand('copy');
61+
// Hide textarea
62+
textArea.value = '';
63+
textArea.style.display = 'none';
64+
65+
// Show short alert
66+
this.alert = true;
67+
window.setTimeout(() => {
68+
this.alert = false;
69+
}, this.alertTimeMillis);
70+
} catch (error) {
71+
console.error(error);
72+
}
73+
}
74+
}
75+
}
76+
77+
</script>
78+
79+
<!-- Add "scoped" attribute to limit CSS to this component only -->
80+
<style>
81+
.v-alert.wgu-alert {
82+
position: fixed;
83+
top: 5em;
84+
right: 4em;
85+
z-index: 1;
86+
}
87+
88+
</style>

static/app-conf.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"extent": false,
2121
"projection": "EPSG:4326",
2222
"paramPrefix": "",
23-
"history": true
23+
"history": false
2424
},
2525

2626
"mapLayers": [
@@ -163,6 +163,10 @@
163163
"wgu-helpwin": {
164164
"target": "toolbar",
165165
"darkLayout": true
166+
},
167+
"wgu-share": {
168+
"target": "toolbar",
169+
"darkLayout": true
166170
}
167171
}
168172
}

0 commit comments

Comments
 (0)