Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward layer reference to map overlays #359

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading