Skip to content

Commit

Permalink
Merge pull request #53 from chrismayer/refactor-infoclick-win
Browse files Browse the repository at this point in the history
Refactor InfoClickWin
  • Loading branch information
chrismayer authored Jan 30, 2019
2 parents ff5749a + 799dceb commit 3086fe4
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 114 deletions.
108 changes: 108 additions & 0 deletions src/components/infoclick/CoordsTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<template>

<table class="coords" v-if="coordRows" :style="tableStyles">
<thead>
<tr>
<th v-for="entry in coordRows"
</th>
</tr>
</thead>
<tbody>
<tr v-for="(value, key) in coordRows">
<td class="key-td">
{{key}}
</td>
<td class="val-td">
{{value}}
</td>
</tr>
</tbody>
</table>

</template>

<script>
// helper function to detect a CSS color
// Taken from Vuetify sources
// https://github.com/vuetifyjs/vuetify/blob/master/packages/vuetify/src/mixins/colorable.ts
function isCssColor (color) {
return !!color && !!color.match(/^(#|(rgb|hsl)a?\()/)
}
import vColors from 'vuetify/es5/util/colors';
import {transform} from 'ol/proj.js';
import {toStringHDMS} from 'ol/coordinate';
export default {
name: 'wgu-coords-table',
props: {
color: {type: String, required: false, default: 'red darken-3'},
coordsData: {type: Object},
showMapPos: {type: Boolean, required: false, default: true},
showWgsPos: {type: Boolean, required: false, default: true},
showHdms: {type: Boolean, required: false, default: true}
},
data: function () {
return {
coordRows: null
}
},
computed: {
tableStyles () {
// calculate border color of tables due to current color property
let borderColor = this.color;
if (!isCssColor(this.color)) {
let [colorName, colorModifier] = this.color.toString().trim().split(' ', 2);
borderColor = vColors[colorName];
if (colorModifier) {
colorModifier = colorModifier.replace('-', '');
borderColor = vColors[colorName][colorModifier];
}
}
return {
'border': '2px solid ' + borderColor
};
}
},
methods: {
},
watch: {
coordsData () {
const me = this;
const coordinate = me.coordsData.coordinate;
const projection = me.coordsData.projection;
const coordinateWgs84 = transform(coordinate, projection, 'EPSG:4326');
let coordRows = {};
if (me.showMapPos) {
// show coordinate in map' SRS
coordRows['MAP PROJ'] =
coordinate[1].toFixed(2) + ' ' + coordinate[0].toFixed(2);
}
if (me.showWgsPos) {
// show coordinate in WGS 84
const coordinateWgs84 = transform(coordinate, projection, 'EPSG:4326');
coordRows['WGS 84'] =
coordinateWgs84[1].toFixed(7) + '° ' + coordinateWgs84[0].toFixed(7) + '°'
}
if (me.showHdms) {
// show coordinate in WGS 84 as formatted deegree / min / secs
const hdms = toStringHDMS(coordinateWgs84);
coordRows['HDMS'] = hdms
}
me.coordRows = coordRows;
}
}
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.wgu-infoclick-win table.coords {
margin-top: 12px;
width: 100%;
}
</style>
165 changes: 56 additions & 109 deletions src/components/infoclick/InfoClickWin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,33 @@
</v-toolbar>
<v-card-title primary-title>

<div v-if="this.gridData === null && this.coordsData === null" class="no-data">
<div v-if="!this.attributeData && !this.coordsData" class="no-data">
Click on the map to get information for the clicked map position.
</div>

<!-- feature property grid -->
<table v-if="this.gridData !== null" :style="tableStyles">
<thead>
<tr>
<th v-for="entry in gridData"
</th>
</tr>
</thead>
<tbody class="attr-tbody">
<tr v-for="(value, key) in gridData">
<td>
{{key}}
</td>
<td>
{{value}}
</td>
</tr>
</tbody>
</table>

<table class="coords" v-if="this.coordsData !== null" :style="tableStyles">
<thead>
<tr>
<th v-for="entry in coordsData"
</th>
</tr>
</thead>
<tbody>
<tr v-for="(value, key) in coordsData">
<td>
{{key}}
</td>
<td>
{{value}}
</td>
</tr>
</tbody>
</table>
<wgu-property-table :properties="attributeData" :color="color" />

<!-- click coodinate info grid -->
<wgu-coords-table :coordsData="coordsData" :color="color" />

</v-card-title>
</v-card>

</template>

<script>
// helper function to detect a CSS color
// Taken from Vuetify sources
// https://github.com/vuetifyjs/vuetify/blob/master/packages/vuetify/src/mixins/colorable.ts
function isCssColor (color) {
return !!color && !!color.match(/^(#|(rgb|hsl)a?\()/)
}
import vColors from 'vuetify/es5/util/colors';
import { WguEventBus } from '../../WguEventBus.js';
import {transform} from 'ol/proj.js';
import {toStringHDMS} from 'ol/coordinate';
import PropertyTable from './PropertyTable';
import CoordsTable from './CoordsTable';
export default {
name: 'wgu-infoclick-win',
components: {
'wgu-property-table': PropertyTable,
'wgu-coords-table': CoordsTable
},
props: {
color: {type: String, required: false, default: 'red darken-3'},
icon: {type: String, required: false, default: 'info'},
Expand All @@ -82,30 +46,10 @@ export default {
show: false,
left: '2px',
top: '270px',
coordsMapProj: '',
coordsWgs84: '',
coordsHdms: '',
gridData: null,
attributeData: null,
coordsData: null
}
},
computed: {
tableStyles () {
// calculate border color of tables due to current color property
let borderColor = this.color;
if (!isCssColor(this.color)) {
let [colorName, colorModifier] = this.color.toString().trim().split(' ', 2);
borderColor = vColors[colorName];
if (colorModifier) {
colorModifier = colorModifier.replace('-', '');
borderColor = vColors[colorName][colorModifier];
}
}
return {
'border': '2px solid ' + borderColor
};
}
},
created () {
var me = this;
// Listen to the ol-map-mounted event and receive the OL map instance
Expand All @@ -118,48 +62,56 @@ export default {
toggleUi () {
this.show = !this.show;
},
registerMapClick () {
registerMapClick (unregister) {
var me = this;
me.map.on('singleclick', (evt) => {
var featureLayer = me.map.forEachFeatureAtPixel(evt.pixel,
function (feature, layer) {
return [feature, layer];
});
if (featureLayer) {
var feat = featureLayer[0];
var props = feat.getProperties();
delete props.geometry;
me.gridData = props;
} else {
me.gridData = null;
}
var coordinates = evt.coordinate;
var mapProjCode = me.map.getView().getProjection().getCode();
var coordinatesWgs84 =
transform(coordinates, mapProjCode, 'EPSG:4326');
var hdms = toStringHDMS(coordinatesWgs84);
me.coordsMapProj = coordinates[1].toFixed(2) + ' ' + coordinates[0].toFixed(2);
me.coordsWgs84 = coordinatesWgs84[1].toFixed(7) + ' ' + coordinatesWgs84[0].toFixed(7);
me.coordsHdms = hdms;
me.coordsData = {
'POS': coordinates[1].toFixed(2) + ' ' + coordinates[0].toFixed(2),
'WGS 84': coordinatesWgs84[1].toFixed(7) + ' ' + coordinatesWgs84[0].toFixed(7),
'HDMS': hdms
}
});
if (unregister === true) {
me.map.un('singleclick', me.onMapClick);
} else {
me.map.on('singleclick', me.onMapClick);
}
},
/**
* Handler for 'singleclick' on the map.
* Collects data and passes it to corresponding objects.
*
* @param {ol/MapBrowserEvent} evt The OL event of 'singleclick' on the map
*/
onMapClick (evt) {
const me = this;
let featureLayer = me.map.forEachFeatureAtPixel(evt.pixel,
(feature, layer) => {
return [feature, layer];
});
// collect feature attributes --> PropertyTable
if (featureLayer) {
const feat = featureLayer[0];
let props = feat.getProperties();
// do not show geometry property
delete props.geometry;
me.attributeData = props;
} else {
me.attributeData = null;
}
// collect click coordinate + projection --> CoordsTable
me.coordsData = {
coordinate: evt.coordinate,
projection: me.map.getView().getProjection().getCode()
};
}
},
watch: {
show () {
const me = this;
if (this.show === true) {
this.registerMapClick();
me.registerMapClick();
} else {
// cleanup old data
me.attributeData = null;
me.coordsData = null;
}
}
}
Expand Down Expand Up @@ -193,11 +145,6 @@ export default {
overflow-y: scroll;
}
.wgu-infoclick-win table.coords {
margin-top: 12px;
width: 100%;
}
.wgu-infoclick-win td {
background-color: #f9f9f9;
}
Expand Down
63 changes: 63 additions & 0 deletions src/components/infoclick/PropertyTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>

<table v-if="this.properties" :style="tableStyles">
<thead>
<tr>
<th v-for="entry in properties"
</th>
</tr>
</thead>
<tbody class="attr-tbody">
<tr v-for="(value, key) in properties">
<td class="key-td">
{{key}}
</td>
<td class="val-td">
{{value}}
</td>
</tr>
</tbody>
</table>

</template>

<script>
// helper function to detect a CSS color
// Taken from Vuetify sources
// https://github.com/vuetifyjs/vuetify/blob/master/packages/vuetify/src/mixins/colorable.ts
function isCssColor (color) {
return !!color && !!color.match(/^(#|(rgb|hsl)a?\()/)
}
import vColors from 'vuetify/es5/util/colors';
export default {
name: 'wgu-property-table',
props: {
color: {type: String, required: false, default: 'red darken-3'},
properties: {type: Object}
},
computed: {
tableStyles () {
// calculate border color of tables due to current color property
let borderColor = this.color;
if (!isCssColor(this.color)) {
let [colorName, colorModifier] = this.color.toString().trim().split(' ', 2);
borderColor = vColors[colorName];
if (colorModifier) {
colorModifier = colorModifier.replace('-', '');
borderColor = vColors[colorName][colorModifier];
}
}
return {
'border': '2px solid ' + borderColor
};
}
}
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
</style>
Loading

0 comments on commit 3086fe4

Please sign in to comment.