Replaces remaining vectorimage.tests.js
Transforms the old rendering tests for the VectorImageLayer decluttering to the new rendering test approach.
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 5.6 KiB |
@@ -90,7 +90,7 @@ layer2.setStyle(function(feature) {
|
|||||||
return new Style({
|
return new Style({
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: feature.get('text'),
|
text: feature.get('text'),
|
||||||
font: '12px "Ubuntu Regular", sans-serif'
|
font: '16px "Ubuntu Regular"'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -119,7 +119,7 @@ layer3.setStyle(function(feature) {
|
|||||||
}),
|
}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: feature.get('text'),
|
text: feature.get('text'),
|
||||||
font: '12px "Ubuntu Regular", sans-serif',
|
font: '16px "Ubuntu Regular"',
|
||||||
textBaseline: 'bottom',
|
textBaseline: 'bottom',
|
||||||
offsetY: -5
|
offsetY: -5
|
||||||
})
|
})
|
||||||
@@ -151,7 +151,8 @@ line.setStyle(new Style({
|
|||||||
text: new Text({
|
text: new Text({
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
text: 'east-west',
|
text: 'east-west',
|
||||||
font: '12px "Ubuntu Regular", sans-serif'
|
font: '16px "Ubuntu Regular"',
|
||||||
|
overflow: true
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
source4.addFeature(point);
|
source4.addFeature(point);
|
||||||
|
|||||||
BIN
rendering/cases/layer-vectorimage-decluttering/expected.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
81
rendering/cases/layer-vectorimage-decluttering/main.js
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import Feature from '../../../src/ol/Feature.js';
|
||||||
|
import Map from '../../../src/ol/Map.js';
|
||||||
|
import View from '../../../src/ol/View.js';
|
||||||
|
import VectorSource from '../../../src/ol/source/Vector.js';
|
||||||
|
import Style from '../../../src/ol/style/Style.js';
|
||||||
|
import Stroke from '../../../src/ol/style/Stroke.js';
|
||||||
|
// import Polygon from '../../../src/ol/geom/Polygon.js';
|
||||||
|
// import Circle from '../../../src/ol/geom/Circle.js';
|
||||||
|
// import LineString from '../../../src/ol/geom/LineString.js';
|
||||||
|
import VectorImageLayer from '../../../src/ol/layer/VectorImage.js';
|
||||||
|
import CircleStyle from '../../../src/ol/style/Circle.js';
|
||||||
|
import Point from '../../../src/ol/geom/Point.js';
|
||||||
|
import LineString from '../../../src/ol/geom/LineString.js';
|
||||||
|
import Text from '../../../src/ol/style/Text.js';
|
||||||
|
|
||||||
|
const center = [1825927.7316762917, 6143091.089223046];
|
||||||
|
|
||||||
|
const source = new VectorSource();
|
||||||
|
const vectorLayer1 = new VectorImageLayer({
|
||||||
|
source: source,
|
||||||
|
style: function(feature) {
|
||||||
|
return new Style({
|
||||||
|
image: new CircleStyle({
|
||||||
|
radius: 15,
|
||||||
|
stroke: new Stroke({
|
||||||
|
color: 'blue'
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
text: new Text({
|
||||||
|
text: feature.get('text'),
|
||||||
|
font: '16px "Ubuntu Regular"'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const centerFeature = new Feature({
|
||||||
|
geometry: new Point(center),
|
||||||
|
text: 'center'
|
||||||
|
});
|
||||||
|
source.addFeature(centerFeature);
|
||||||
|
source.addFeature(new Feature({
|
||||||
|
geometry: new Point([center[0] - 540, center[1]]),
|
||||||
|
text: 'west'
|
||||||
|
}));
|
||||||
|
source.addFeature(new Feature({
|
||||||
|
geometry: new Point([center[0] + 540, center[1]]),
|
||||||
|
text: 'east'
|
||||||
|
}));
|
||||||
|
|
||||||
|
const line = new Feature(new LineString([
|
||||||
|
[center[0] - 650, center[1] - 200],
|
||||||
|
[center[0] + 650, center[1] - 200]
|
||||||
|
]));
|
||||||
|
line.setStyle(new Style({
|
||||||
|
stroke: new Stroke({
|
||||||
|
color: '#CCC',
|
||||||
|
width: 12
|
||||||
|
}),
|
||||||
|
text: new Text({
|
||||||
|
placement: 'line',
|
||||||
|
text: 'east-west',
|
||||||
|
font: '16px "Ubuntu Regular"'
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
source.addFeature(line);
|
||||||
|
|
||||||
|
const map = new Map({
|
||||||
|
layers: [
|
||||||
|
vectorLayer1
|
||||||
|
],
|
||||||
|
target: 'map',
|
||||||
|
view: new View({
|
||||||
|
center: center,
|
||||||
|
zoom: 13
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
map.getView().fit(source.getExtent());
|
||||||
|
|
||||||
|
render({tolerance: 0.005});
|
||||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 22 KiB |
@@ -23,7 +23,7 @@ feature1.setStyle(new Style({
|
|||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'Hello world',
|
text: 'Hello world',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
placement: 'line'
|
placement: 'line'
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
@@ -40,7 +40,7 @@ feature2.setStyle(new Style({
|
|||||||
textBaseline: 'bottom',
|
textBaseline: 'bottom',
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
font: 'bold italic 0.8em "Ubuntu Regular", sans-serif'
|
font: 'bold italic 0.8em "Ubuntu Regular"'
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
vectorSource.addFeature(feature2);
|
vectorSource.addFeature(feature2);
|
||||||
@@ -51,11 +51,11 @@ const feature3 = new Feature({geometry: lineString3});
|
|||||||
feature3.setStyle(new Style({
|
feature3.setStyle(new Style({
|
||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
text: 'Set properties'
|
text: 'Set properties'
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
feature3.getStyle().getText().setFont('bold italic 1.2em "Ubuntu Regular", sans-serif');
|
feature3.getStyle().getText().setFont('bold italic 1.2em "Ubuntu Regular"');
|
||||||
feature3.getStyle().getText().setTextAlign('left');
|
feature3.getStyle().getText().setTextAlign('left');
|
||||||
feature3.getStyle().getText().setOffsetX(10);
|
feature3.getStyle().getText().setOffsetX(10);
|
||||||
feature3.getStyle().getText().setOffsetY(-10);
|
feature3.getStyle().getText().setOffsetY(-10);
|
||||||
@@ -73,7 +73,7 @@ feature4.setStyle(new Style({
|
|||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'negative offsetX',
|
text: 'negative offsetX',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
offsetX: -10,
|
offsetX: -10,
|
||||||
textAlign: 'start',
|
textAlign: 'start',
|
||||||
textBaseline: 'top',
|
textBaseline: 'top',
|
||||||
@@ -89,7 +89,7 @@ feature5.setStyle(new Style({
|
|||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'Small text',
|
text: 'Small text',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
offsetY: 5,
|
offsetY: 5,
|
||||||
scale: 0.7,
|
scale: 0.7,
|
||||||
textAlign: 'end',
|
textAlign: 'end',
|
||||||
@@ -105,7 +105,7 @@ feature6.setStyle(new Style({
|
|||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'FILL AND STROKE',
|
text: 'FILL AND STROKE',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
fill: new Fill({color: '#FFC0CB'}),
|
fill: new Fill({color: '#FFC0CB'}),
|
||||||
stroke: new Stroke({
|
stroke: new Stroke({
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ feature1.setStyle(new Style({
|
|||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'Hello world',
|
text: 'Hello world',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
overflow: true
|
overflow: true
|
||||||
})
|
})
|
||||||
@@ -38,7 +38,7 @@ feature2.setStyle(new Style({
|
|||||||
textBaseline: 'bottom',
|
textBaseline: 'bottom',
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
font: 'bold italic 0.8em "Ubuntu Regular", sans-serif',
|
font: 'bold italic 0.8em "Ubuntu Regular"',
|
||||||
overflow: true
|
overflow: true
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
@@ -73,7 +73,7 @@ feature4.setStyle(new Style({
|
|||||||
stroke: new Stroke({color: 'red'}),
|
stroke: new Stroke({color: 'red'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'PLEASE OMIT ME IM UGLY',
|
text: 'PLEASE OMIT ME IM UGLY',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
offsetX: -10,
|
offsetX: -10,
|
||||||
textAlign: 'start',
|
textAlign: 'start',
|
||||||
textBaseline: 'top',
|
textBaseline: 'top',
|
||||||
@@ -90,7 +90,7 @@ feature5.setStyle(new Style({
|
|||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'Small text',
|
text: 'Small text',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
offsetY: 5,
|
offsetY: 5,
|
||||||
scale: 0.7,
|
scale: 0.7,
|
||||||
rotation: 4,
|
rotation: 4,
|
||||||
@@ -109,7 +109,7 @@ feature6.setStyle(new Style({
|
|||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'FILL AND STROKE',
|
text: 'FILL AND STROKE',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
overflow: true,
|
overflow: true,
|
||||||
fill: new Fill({color: '#FFC0CB'}),
|
fill: new Fill({color: '#FFC0CB'}),
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const vectorSource = new VectorSource();
|
|||||||
const pointStyle = new Style({
|
const pointStyle = new Style({
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'Point Label',
|
text: 'Point Label',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
fill: new Fill({
|
fill: new Fill({
|
||||||
color: 'red'
|
color: 'red'
|
||||||
}),
|
}),
|
||||||
@@ -32,7 +32,7 @@ const lineStyle = new Style({
|
|||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'Line Label',
|
text: 'Line Label',
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
fill: new Fill({
|
fill: new Fill({
|
||||||
color: 'red'
|
color: 'red'
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ feature = new Feature({
|
|||||||
feature.setStyle(new Style({
|
feature.setStyle(new Style({
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'hello',
|
text: 'hello',
|
||||||
font: '14px "Ubuntu Regular", sans-serif',
|
font: '14px "Ubuntu Regular"',
|
||||||
scale: 2,
|
scale: 2,
|
||||||
fill: new Fill({
|
fill: new Fill({
|
||||||
color: 'red'
|
color: 'red'
|
||||||
@@ -39,7 +39,7 @@ feature = new Feature({
|
|||||||
feature.setStyle(new Style({
|
feature.setStyle(new Style({
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'upside down',
|
text: 'upside down',
|
||||||
font: '14px "Ubuntu Regular", sans-serif',
|
font: '14px "Ubuntu Regular"',
|
||||||
rotation: Math.PI,
|
rotation: Math.PI,
|
||||||
stroke: new Stroke({
|
stroke: new Stroke({
|
||||||
color: 'red',
|
color: 'red',
|
||||||
@@ -55,7 +55,7 @@ feature = new Feature({
|
|||||||
});
|
});
|
||||||
feature.setStyle(new Style({
|
feature.setStyle(new Style({
|
||||||
text: new Text({
|
text: new Text({
|
||||||
font: '"Ubuntu Regular", sans-serif',
|
font: '"Ubuntu Regular"',
|
||||||
text: 'rotateWithView',
|
text: 'rotateWithView',
|
||||||
rotateWithView: true,
|
rotateWithView: true,
|
||||||
stroke: new Stroke({
|
stroke: new Stroke({
|
||||||
@@ -72,7 +72,7 @@ feature = new Feature({
|
|||||||
feature.setStyle(new Style({
|
feature.setStyle(new Style({
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'hello',
|
text: 'hello',
|
||||||
font: '14px "Ubuntu Regular", sans-serif',
|
font: '14px "Ubuntu Regular"',
|
||||||
padding: [1, 2, 3, 5],
|
padding: [1, 2, 3, 5],
|
||||||
backgroundFill: new Fill({
|
backgroundFill: new Fill({
|
||||||
color: 'rgba(55, 55, 55, 0.25)'
|
color: 'rgba(55, 55, 55, 0.25)'
|
||||||
@@ -92,7 +92,7 @@ feature = new Feature({
|
|||||||
feature.setStyle(new Style({
|
feature.setStyle(new Style({
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'hello',
|
text: 'hello',
|
||||||
font: '14px "Ubuntu Regular", sans-serif',
|
font: '14px "Ubuntu Regular"',
|
||||||
padding: [1, 2, 3, 5],
|
padding: [1, 2, 3, 5],
|
||||||
backgroundFill: new Fill({
|
backgroundFill: new Fill({
|
||||||
color: 'rgba(55, 55, 55, 0.25)'
|
color: 'rgba(55, 55, 55, 0.25)'
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
font-family: "Ubuntu Regular";
|
font-family: "Ubuntu Regular";
|
||||||
src: url("/data/fonts/ubuntu-regular-webfont.eot");
|
src: url("/data/fonts/ubuntu-regular-webfont.eot");
|
||||||
src: url("/data/fonts/ubuntu-regular-webfont.woff") format("woff"),
|
src: url("/data/fonts/ubuntu-regular-webfont.woff") format("woff"),
|
||||||
url("/data/fonts/ubuntu-regular-webfont.otf") format("opentype"),
|
|
||||||
url("/data/fonts/ubuntu-regular-webfont.svg#filename") format("svg");
|
url("/data/fonts/ubuntu-regular-webfont.svg#filename") format("svg");
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
@@ -29,7 +28,6 @@
|
|||||||
font-style: italic;
|
font-style: italic;
|
||||||
src: url("/data/fonts/ubuntu-bold-italic-webfont.eot");
|
src: url("/data/fonts/ubuntu-bold-italic-webfont.eot");
|
||||||
src: url("/data/fonts/ubuntu-bold-italic-webfont.woff") format("woff"),
|
src: url("/data/fonts/ubuntu-bold-italic-webfont.woff") format("woff"),
|
||||||
url("/data/fonts/ubuntu-bold-italic-webfont.otf") format("opentype"),
|
|
||||||
url("/data/fonts/ubuntu-bold-italic-webfont.svg#filename") format("svg");
|
url("/data/fonts/ubuntu-bold-italic-webfont.svg#filename") format("svg");
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 968 B |
|
Before Width: | Height: | Size: 1.2 KiB |
@@ -1,202 +0,0 @@
|
|||||||
import Circle from '../../../../src/ol/geom/Circle.js';
|
|
||||||
import CircleStyle from '../../../../src/ol/style/Circle.js';
|
|
||||||
import Feature from '../../../../src/ol/Feature.js';
|
|
||||||
import Fill from '../../../../src/ol/style/Fill.js';
|
|
||||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
|
||||||
import Map from '../../../../src/ol/Map.js';
|
|
||||||
import Point from '../../../../src/ol/geom/Point.js';
|
|
||||||
import Polygon from '../../../../src/ol/geom/Polygon.js';
|
|
||||||
import Stroke from '../../../../src/ol/style/Stroke.js';
|
|
||||||
import Style from '../../../../src/ol/style/Style.js';
|
|
||||||
import Text from '../../../../src/ol/style/Text.js';
|
|
||||||
import VectorImageLayer from '../../../../src/ol/layer/VectorImage.js';
|
|
||||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
|
||||||
import View from '../../../../src/ol/View.js';
|
|
||||||
|
|
||||||
describe('ol.rendering.layer.VectorImage', function() {
|
|
||||||
|
|
||||||
const center = [1825927.7316762917, 6143091.089223046];
|
|
||||||
|
|
||||||
let map, source;
|
|
||||||
function createMap() {
|
|
||||||
source = new VectorSource();
|
|
||||||
map = new Map({
|
|
||||||
pixelRatio: 1,
|
|
||||||
target: createMapDiv(80, 80),
|
|
||||||
view: new View({
|
|
||||||
center: center,
|
|
||||||
zoom: 13
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
if (map) {
|
|
||||||
disposeMap(map);
|
|
||||||
}
|
|
||||||
map = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
function addCircle(r) {
|
|
||||||
source.addFeature(new Feature(new Circle(center, r)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function addPolygon(r) {
|
|
||||||
source.addFeature(new Feature(new Polygon([
|
|
||||||
[
|
|
||||||
[center[0] - r, center[1] - r],
|
|
||||||
[center[0] + r, center[1] - r],
|
|
||||||
[center[0] + r, center[1] + r],
|
|
||||||
[center[0] - r, center[1] + r],
|
|
||||||
[center[0] - r, center[1] - r]
|
|
||||||
]
|
|
||||||
])));
|
|
||||||
}
|
|
||||||
|
|
||||||
it('unskips features correctly', function(done) {
|
|
||||||
createMap();
|
|
||||||
addCircle(500);
|
|
||||||
addPolygon(300);
|
|
||||||
map.skipFeature(source.getFeatures()[1]);
|
|
||||||
map.addLayer(new VectorImageLayer({
|
|
||||||
source: source,
|
|
||||||
style: new Style({
|
|
||||||
fill: new Fill({
|
|
||||||
color: 'rgba(255,0,0,0.5)'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
width: 2,
|
|
||||||
color: 'black'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
map.renderSync();
|
|
||||||
map.unskipFeature(source.getFeatures()[1]);
|
|
||||||
map.once('postrender', function() {
|
|
||||||
expectResemble(map, 'rendering/ol/layer/expected/vector.png',
|
|
||||||
IMAGE_TOLERANCE, done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('declutters text', function(done) {
|
|
||||||
createMap();
|
|
||||||
const layer = new VectorImageLayer({
|
|
||||||
declutter: true,
|
|
||||||
source: source
|
|
||||||
});
|
|
||||||
map.addLayer(layer);
|
|
||||||
|
|
||||||
const centerFeature = new Feature({
|
|
||||||
geometry: new Point(center),
|
|
||||||
text: 'center'
|
|
||||||
});
|
|
||||||
source.addFeature(centerFeature);
|
|
||||||
source.addFeature(new Feature({
|
|
||||||
geometry: new Point([center[0] - 540, center[1]]),
|
|
||||||
text: 'west'
|
|
||||||
}));
|
|
||||||
source.addFeature(new Feature({
|
|
||||||
geometry: new Point([center[0] + 540, center[1]]),
|
|
||||||
text: 'east'
|
|
||||||
}));
|
|
||||||
|
|
||||||
layer.setStyle(function(feature) {
|
|
||||||
return new Style({
|
|
||||||
text: new Text({
|
|
||||||
text: feature.get('text'),
|
|
||||||
font: '12px sans-serif'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
map.once('postrender', function() {
|
|
||||||
const hitDetected = map.getFeaturesAtPixel([42, 42]);
|
|
||||||
expect(hitDetected).to.have.length(1);
|
|
||||||
expect(hitDetected[0]).to.equal(centerFeature);
|
|
||||||
expectResemble(map, 'rendering/ol/layer/expected/vector-canvas-declutter.png',
|
|
||||||
2.2, done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('declutters images', function(done) {
|
|
||||||
createMap();
|
|
||||||
const layer = new VectorImageLayer({
|
|
||||||
declutter: true,
|
|
||||||
source: source
|
|
||||||
});
|
|
||||||
map.addLayer(layer);
|
|
||||||
|
|
||||||
const centerFeature = new Feature({
|
|
||||||
geometry: new Point(center)
|
|
||||||
});
|
|
||||||
source.addFeature(centerFeature);
|
|
||||||
source.addFeature(new Feature({
|
|
||||||
geometry: new Point([center[0] - 540, center[1]])
|
|
||||||
}));
|
|
||||||
source.addFeature(new Feature({
|
|
||||||
geometry: new Point([center[0] + 540, center[1]])
|
|
||||||
}));
|
|
||||||
|
|
||||||
layer.setStyle(function(feature) {
|
|
||||||
return new Style({
|
|
||||||
image: new CircleStyle({
|
|
||||||
radius: 15,
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: 'blue'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
map.once('postrender', function() {
|
|
||||||
const hitDetected = map.getFeaturesAtPixel([40, 40]);
|
|
||||||
expect(hitDetected).to.have.length(1);
|
|
||||||
expect(hitDetected[0]).to.equal(centerFeature);
|
|
||||||
expectResemble(map, 'rendering/ol/layer/expected/vector-canvas-declutter-image.png',
|
|
||||||
IMAGE_TOLERANCE, done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('declutters text along lines and images', function(done) {
|
|
||||||
createMap();
|
|
||||||
const layer = new VectorImageLayer({
|
|
||||||
declutter: true,
|
|
||||||
source: source
|
|
||||||
});
|
|
||||||
map.addLayer(layer);
|
|
||||||
|
|
||||||
const point = new Feature(new Point(center));
|
|
||||||
point.setStyle(new Style({
|
|
||||||
image: new CircleStyle({
|
|
||||||
radius: 8,
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: 'blue'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
const line = new Feature(new LineString([
|
|
||||||
[center[0] - 650, center[1] - 200],
|
|
||||||
[center[0] + 650, center[1] - 200]
|
|
||||||
]));
|
|
||||||
line.setStyle(new Style({
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#CCC',
|
|
||||||
width: 12
|
|
||||||
}),
|
|
||||||
text: new Text({
|
|
||||||
placement: 'line',
|
|
||||||
text: 'east-west',
|
|
||||||
font: '12px sans-serif'
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
|
|
||||||
source.addFeature(point);
|
|
||||||
source.addFeature(line);
|
|
||||||
|
|
||||||
map.once('postrender', function() {
|
|
||||||
expectResemble(map, 'rendering/ol/layer/expected/vector-canvas-declutter-line.png',
|
|
||||||
IMAGE_TOLERANCE, done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||