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

Show how to combine a layer with a render function and a standard layer #15762

Merged
merged 1 commit into from Apr 25, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/svg-layer.css
Expand Up @@ -5,3 +5,7 @@
.svg-layer path:hover {
opacity: 0.4;
}

.ol-layer {
pointer-events: none;
}
1 change: 1 addition & 0 deletions examples/svg-layer.html
Expand Up @@ -4,6 +4,7 @@
shortdesc: Example of a map with an interactive svg layer.
docs: >
With a plain `ol/Layer` and a `render` function, we can use an interactive svg as layer. Hover over countries to see the interactivity that is defined purely with a css `:hover` pseudo-class.
Other layers can be added to the same map. The blue circle is a vector feature on a separate layer.
tags: "svg, layer, render, transform"
---
<div id="map" class="map"></div>
18 changes: 18 additions & 0 deletions examples/svg-layer.js
@@ -1,6 +1,10 @@
import Feature from '../src/ol/Feature.js';
import Layer from '../src/ol/layer/Layer.js';
import Map from '../src/ol/Map.js';
import VectorSource from '../src/ol/source/Vector.js';
import View from '../src/ol/View.js';
import {Point} from '../src/ol/geom.js';
import {Vector} from '../src/ol/layer.js';
import {composeCssTransform} from '../src/ol/transform.js';

const map = new Map({
Expand Down Expand Up @@ -30,6 +34,7 @@ svgContainer.style.width = width + 'px';
svgContainer.style.height = height + 'px';
svgContainer.style.transformOrigin = 'top left';
svgContainer.className = 'svg-layer';
svgContainer.style.position = 'absolute';

map.addLayer(
new Layer({
Expand All @@ -52,3 +57,16 @@ map.addLayer(
},
}),
);

map.addLayer(
new Vector({
source: new VectorSource({
features: [new Feature(new Point([0, 0]))],
}),
style: {
'circle-fill-color': 'blue',
'circle-radius': 10,
'circle-stroke-color': 'white',
},
}),
);