Skip to content

Commit

Permalink
Merge pull request #15762 from ahocevar/svg-layer-opacity
Browse files Browse the repository at this point in the history
Show how to combine a layer with a render function and a standard layer
  • Loading branch information
ahocevar committed Apr 25, 2024
2 parents af217ea + d0e26bc commit a8f94c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
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',
},
}),
);

0 comments on commit a8f94c4

Please sign in to comment.