Skip to content

Commit

Permalink
Merge pull request #359 from sronveaux/layer-in-map-overlay
Browse files Browse the repository at this point in the history
Forward layer reference to map overlays
  • Loading branch information
fschmenger authored Nov 27, 2023
2 parents 8571561 + a852acf commit 44bb226
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/reusable-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ An Overlay can either be statically positioned or can be used to implement a too
```javascript
{
feature: ol/Feature,
layer: ol/Layer,
hoverAttribute: string
}
```
Expand Down Expand Up @@ -70,7 +71,7 @@ export default {

#### Feature hover tooltip

The following example implements a customized tooltip to render an attribute of a feature, when it is hovered on the map. Again, the default slot of `<wgu-map-overlay>` is filled by a `<v-sheet>`. A data object containing the `feature` and optionally `hoverAttribute` properties is available from the slot-scope. Declare the following vue template and add it to you `WguAppTemplate`:
The following example implements a customized tooltip to render an attribute of a feature, when it is hovered on the map. Again, the default slot of `<wgu-map-overlay>` is filled by a `<v-sheet>`. A data object containing the `feature`, `layer` and optionally `hoverAttribute` properties is available from the slot-scope. Declare the following vue template and add it to you `WguAppTemplate`:

```javascript
<template>
Expand Down
11 changes: 6 additions & 5 deletions src/components/ol/HoverController.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import TileWmsSource from 'ol/source/TileWMS';
import ImageWMSSource from 'ol/source/ImageWMS';
import VectorSource from 'ol/source/Vector';
import VectorTileSource from 'ol/source/VectorTile'
import VectorTileSource from 'ol/source/VectorTile';
import WMSGetFeatureInfo from 'ol/format/WMSGetFeatureInfo';
import { WguEventBus } from '../../WguEventBus'
import { WguEventBus } from '../../WguEventBus';
import axios from 'axios';

export default class HoverController {
DEFAULT_POINTER_REST_INTERVAL = 150;
DEFAULT_HOVER_OVERLAY = 'wgu-hover-tooltip'
DEFAULT_HOVER_OVERLAY = 'wgu-hover-tooltip';

map = null;
timerHandle = null;
Expand Down Expand Up @@ -101,7 +101,7 @@ export default class HoverController {
featureInfos.push(...features.map((feat) => {
return { layer, feature: feat };
}));
me.displayTooltip(featureInfos, coordinate)
me.displayTooltip(featureInfos, coordinate);
})
.catch(function (error) {
if (!axios.isCancel(error)) {
Expand All @@ -114,7 +114,7 @@ export default class HoverController {
featureInfos.push(...features.map((feat) => {
return { layer, feature: feat };
}));
me.displayTooltip(featureInfos, coordinate)
me.displayTooltip(featureInfos, coordinate);
}
});

Expand Down Expand Up @@ -206,6 +206,7 @@ export default class HoverController {
};
WguEventBus.$emit(overlayId + '-update-overlay', true, coordinate, {
feature,
layer,
hoverAttribute: hoverAttr
});
me.activeOverlayId = overlayId;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/specs/components/ol/HoverController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('ol/HoverController.js', () => {
expect(visible).to.equal(true);
expect(position).to.equal(undefined);
expect(data.feature).to.equal(feat);
expect(data.layer).to.equal(layer);
expect(data.hoverAttribute).to.equal('foo');
done();
});
Expand Down

0 comments on commit 44bb226

Please sign in to comment.