-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from fschmenger/layer_legends
Layer legends
- Loading branch information
Showing
14 changed files
with
547 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<!-- Remarks: | ||
As we need none of the responsive functionality of v-img, we use a simple | ||
HTML img to stop the component from flickering when the image is re-requested. | ||
--> | ||
<img v-if="legendURL" :src="legendURL"> | ||
</template> | ||
|
||
<script> | ||
import LayerLegend from '../../util/LayerLegend'; | ||
/** | ||
* Module for one legend element. | ||
*/ | ||
export default { | ||
name: 'wgu-layerlegendimage', | ||
props: { | ||
mapView: { type: Object, required: true }, | ||
layer: { type: Object, required: true } | ||
}, | ||
data () { | ||
return { | ||
resolution: this.mapView.getResolution(), | ||
viewResolutionChanged: undefined | ||
} | ||
}, | ||
/** | ||
* Register for an event to update the legend on resolution change. | ||
*/ | ||
created () { | ||
const viewResolutionChanged = function (event) { | ||
this.resolution = event.target.getResolution(); | ||
}.bind(this); | ||
this.mapView.on('change:resolution', viewResolutionChanged); | ||
this.viewResolutionChanged = viewResolutionChanged; | ||
}, | ||
/** | ||
* Unregister the event fired on resolution change. | ||
*/ | ||
destroyed () { | ||
if (this.viewResolutionChanged) { | ||
this.mapView.un('change:resolution', this.viewResolutionChanged); | ||
} | ||
}, | ||
computed: { | ||
/** | ||
* Returns a URL to the layers legend image. | ||
*/ | ||
legendURL () { | ||
const options = { | ||
language: this.$i18n.locale, | ||
...this.layer.get('legendOptions') | ||
}; | ||
return LayerLegend.getUrl( | ||
this.layer, this.resolution, options, this.layer.get('legendUrl')); | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<template> | ||
<!-- Show layer details --> | ||
<v-list-group | ||
v-if="showDetails" | ||
v-model="open" | ||
class="text--primary" | ||
> | ||
<template v-slot:activator> | ||
<v-list-item-action> | ||
<v-checkbox | ||
color="secondary" | ||
hide-details | ||
:input-value="layer.getVisible()" | ||
@click.capture.stop="onItemClick()" | ||
/> | ||
</v-list-item-action> | ||
<v-list-item-title> | ||
{{ layer.get('name') }} | ||
</v-list-item-title> | ||
</template> | ||
<v-list-item> | ||
<!-- Remarks: | ||
The legend image item is wrapped by an v-if block to avoid unneccesary image | ||
requests when the layer item is not expanded. | ||
--> | ||
<wgu-layerlegendimage v-if="open" | ||
:layer="layer" | ||
:mapView="mapView" | ||
/> | ||
</v-list-item> | ||
</v-list-group> | ||
|
||
<!-- Simple layer entry --> | ||
<v-list-item | ||
v-else | ||
class="wgu-layerlist-item" | ||
> | ||
<v-list-item-action> | ||
<v-checkbox | ||
color="secondary" | ||
hide-details | ||
:input-value="layer.getVisible()" | ||
@click.capture.stop="onItemClick(layer)" | ||
/> | ||
</v-list-item-action> | ||
<v-list-item-content> | ||
<v-list-item-title> | ||
{{ layer.get('name') }} | ||
</v-list-item-title> | ||
</v-list-item-content> | ||
</v-list-item> | ||
</template> | ||
|
||
<script> | ||
import LayerLegendImage from './LayerLegendImage' | ||
export default { | ||
name: 'wgu-layerlistitem', | ||
components: { | ||
'wgu-layerlegendimage': LayerLegendImage | ||
}, | ||
data () { | ||
return { | ||
open: false | ||
} | ||
}, | ||
props: { | ||
layer: { type: Object, required: true }, | ||
mapView: { type: Object, required: true }, | ||
showDetails: { type: Boolean, required: true } | ||
}, | ||
methods: { | ||
/** | ||
* Handler for click on layer item, toggles the layer`s visibility. | ||
*/ | ||
onItemClick () { | ||
this.layer.setVisible(!this.layer.getVisible()); | ||
} | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.