Use background property for vector layers
This commit is contained in:
@@ -1,24 +1,29 @@
|
||||
import GeoJSON from '../src/ol/format/GeoJSON.js';
|
||||
import Map from '../src/ol/Map.js';
|
||||
import VectorSource from '../src/ol/source/Vector.js';
|
||||
import View from '../src/ol/View.js';
|
||||
import {Fill, Stroke, Style} from '../src/ol/style.js';
|
||||
import {
|
||||
Heatmap as HeatmapLayer,
|
||||
Tile as TileLayer,
|
||||
Vector as VectorLayer,
|
||||
} from '../src/ol/layer.js';
|
||||
import {OSM, Vector as VectorSource} from '../src/ol/source.js';
|
||||
|
||||
const map = new Map({
|
||||
layers: [
|
||||
new TileLayer({
|
||||
source: new OSM(),
|
||||
}),
|
||||
new VectorLayer({
|
||||
background: '#a9d3df',
|
||||
source: new VectorSource({
|
||||
url: 'data/geojson/countries.geojson',
|
||||
format: new GeoJSON(),
|
||||
}),
|
||||
opacity: 0.5,
|
||||
style: new Style({
|
||||
stroke: new Stroke({
|
||||
color: '#ccc',
|
||||
}),
|
||||
fill: new Fill({
|
||||
color: 'white',
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
new HeatmapLayer({
|
||||
source: new VectorSource({
|
||||
@@ -51,6 +56,12 @@ document.getElementById('export-png').addEventListener('click', function () {
|
||||
map.getViewport().querySelectorAll('.ol-layer canvas, canvas.ol-layer'),
|
||||
function (canvas) {
|
||||
if (canvas.width > 0) {
|
||||
const backgroundColor = canvas.parentNode.style.backgroundColor;
|
||||
if (backgroundColor) {
|
||||
mapContext.fillStyle = backgroundColor;
|
||||
mapContext.fillRect(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
|
||||
const opacity =
|
||||
canvas.parentNode.style.opacity || canvas.style.opacity;
|
||||
mapContext.globalAlpha = opacity === '' ? 1 : Number(opacity);
|
||||
|
||||
@@ -135,7 +135,12 @@ class CanvasImageLayerRenderer extends CanvasLayerRenderer {
|
||||
|
||||
const canvasTransform = toTransformString(this.pixelTransform);
|
||||
|
||||
this.useContainer(target, canvasTransform, layerState.opacity);
|
||||
this.useContainer(
|
||||
target,
|
||||
canvasTransform,
|
||||
layerState.opacity,
|
||||
this.getBackground(frameState)
|
||||
);
|
||||
|
||||
const context = this.context;
|
||||
const canvas = context.canvas;
|
||||
|
||||
@@ -233,7 +233,12 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
|
||||
|
||||
const canvasTransform = transformToString(this.pixelTransform);
|
||||
|
||||
this.useContainer(target, canvasTransform, layerState.opacity);
|
||||
this.useContainer(
|
||||
target,
|
||||
canvasTransform,
|
||||
layerState.opacity,
|
||||
this.getBackground(frameState)
|
||||
);
|
||||
const context = this.context;
|
||||
const canvas = context.canvas;
|
||||
|
||||
|
||||
BIN
test/rendering/cases/layer-vector-background/expected.png
Normal file
BIN
test/rendering/cases/layer-vector-background/expected.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
33
test/rendering/cases/layer-vector-background/main.js
Normal file
33
test/rendering/cases/layer-vector-background/main.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import GeoJSON from '../../../../src/ol/format/GeoJSON.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import VectorLayer from '../../../../src/ol/layer/Vector.js';
|
||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import {Fill, Stroke, Style} from '../../../../src/ol/style.js';
|
||||
|
||||
new Map({
|
||||
target: 'map',
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 1,
|
||||
}),
|
||||
layers: [
|
||||
new VectorLayer({
|
||||
background: '#a9d3df',
|
||||
source: new VectorSource({
|
||||
url: '/data/countries.json',
|
||||
format: new GeoJSON(),
|
||||
}),
|
||||
style: new Style({
|
||||
stroke: new Stroke({
|
||||
color: '#ccc',
|
||||
}),
|
||||
fill: new Fill({
|
||||
color: 'white',
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
render();
|
||||
BIN
test/rendering/cases/layer-vectorimage-background/expected.png
Normal file
BIN
test/rendering/cases/layer-vectorimage-background/expected.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
33
test/rendering/cases/layer-vectorimage-background/main.js
Normal file
33
test/rendering/cases/layer-vectorimage-background/main.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import GeoJSON from '../../../../src/ol/format/GeoJSON.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import VectorImageLayer from '../../../../src/ol/layer/VectorImage.js';
|
||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import {Fill, Stroke, Style} from '../../../../src/ol/style.js';
|
||||
|
||||
new Map({
|
||||
target: 'map',
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 1,
|
||||
}),
|
||||
layers: [
|
||||
new VectorImageLayer({
|
||||
background: '#a9d3df',
|
||||
source: new VectorSource({
|
||||
url: '/data/countries.json',
|
||||
format: new GeoJSON(),
|
||||
}),
|
||||
style: new Style({
|
||||
stroke: new Stroke({
|
||||
color: '#ccc',
|
||||
}),
|
||||
fill: new Fill({
|
||||
color: 'white',
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
render();
|
||||
Reference in New Issue
Block a user