Merge pull request #9362 from KaiVolland/text-rendering
Use local font "Ubuntu Regular" for rendering tests
|
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 sans-serif'
|
font: '16px Ubuntu'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -119,7 +119,7 @@ layer3.setStyle(function(feature) {
|
|||||||
}),
|
}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: feature.get('text'),
|
text: feature.get('text'),
|
||||||
font: '12px sans-serif',
|
font: '16px Ubuntu',
|
||||||
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 sans-serif'
|
font: '16px Ubuntu',
|
||||||
|
overflow: true
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
source4.addFeature(point);
|
source4.addFeature(point);
|
||||||
|
|||||||
|
After Width: | Height: | Size: 5.7 KiB |
@@ -0,0 +1,79 @@
|
|||||||
|
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 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'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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'
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
source.addFeature(line);
|
||||||
|
|
||||||
|
const map = new Map({
|
||||||
|
pixelRatio: 1,
|
||||||
|
layers: [
|
||||||
|
vectorLayer1
|
||||||
|
],
|
||||||
|
target: 'map',
|
||||||
|
view: new View({
|
||||||
|
center: center,
|
||||||
|
zoom: 13
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
map.getView().fit(source.getExtent());
|
||||||
|
|
||||||
|
render({tolerance: 0.02});
|
||||||
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 21 KiB |
@@ -23,6 +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: '10px Ubuntu',
|
||||||
placement: 'line'
|
placement: 'line'
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
@@ -35,11 +36,11 @@ feature2.setStyle(new Style({
|
|||||||
stroke: new Stroke({color: 'blue'}),
|
stroke: new Stroke({color: 'blue'}),
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'Scale 2',
|
text: 'Scale 2',
|
||||||
|
font: 'normal 400 12px/1 Ubuntu',
|
||||||
scale: 2,
|
scale: 2,
|
||||||
textBaseline: 'bottom',
|
textBaseline: 'bottom',
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
placement: 'line',
|
placement: 'line'
|
||||||
font: 'bold italic 0.8em serif'
|
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
vectorSource.addFeature(feature2);
|
vectorSource.addFeature(feature2);
|
||||||
@@ -50,10 +51,10 @@ 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: 'italic bold 0.75em Ubuntu',
|
||||||
text: 'Set properties'
|
text: 'Set properties'
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
feature3.getStyle().getText().setFont('bold italic 1.2em monospace');
|
|
||||||
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);
|
||||||
@@ -71,6 +72,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: 'normal 400 10px/1 Ubuntu',
|
||||||
offsetX: -10,
|
offsetX: -10,
|
||||||
textAlign: 'start',
|
textAlign: 'start',
|
||||||
textBaseline: 'top',
|
textBaseline: 'top',
|
||||||
@@ -86,6 +88,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: '10px Ubuntu',
|
||||||
offsetY: 5,
|
offsetY: 5,
|
||||||
scale: 0.7,
|
scale: 0.7,
|
||||||
textAlign: 'end',
|
textAlign: 'end',
|
||||||
@@ -101,6 +104,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: '10px Ubuntu',
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
fill: new Fill({color: '#FFC0CB'}),
|
fill: new Fill({color: '#FFC0CB'}),
|
||||||
stroke: new Stroke({
|
stroke: new Stroke({
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.7 KiB |
@@ -20,6 +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: '10px Ubuntu',
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
overflow: true
|
overflow: true
|
||||||
})
|
})
|
||||||
@@ -37,7 +38,7 @@ feature2.setStyle(new Style({
|
|||||||
textBaseline: 'bottom',
|
textBaseline: 'bottom',
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
font: 'bold italic 0.8em serif',
|
font: 'italic bold 0.5em Ubuntu',
|
||||||
overflow: true
|
overflow: true
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
@@ -52,7 +53,6 @@ feature3.setStyle(new Style({
|
|||||||
text: 'Set properties'
|
text: 'Set properties'
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
feature3.getStyle().getText().setFont('bold italic 1.2em monospace');
|
|
||||||
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);
|
||||||
@@ -72,6 +72,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: '10px Ubuntu',
|
||||||
offsetX: -10,
|
offsetX: -10,
|
||||||
textAlign: 'start',
|
textAlign: 'start',
|
||||||
textBaseline: 'top',
|
textBaseline: 'top',
|
||||||
@@ -88,6 +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: '10px Ubuntu',
|
||||||
offsetY: 5,
|
offsetY: 5,
|
||||||
scale: 0.7,
|
scale: 0.7,
|
||||||
rotation: 4,
|
rotation: 4,
|
||||||
@@ -106,6 +108,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: '10px Ubuntu',
|
||||||
placement: 'line',
|
placement: 'line',
|
||||||
overflow: true,
|
overflow: true,
|
||||||
fill: new Fill({color: '#FFC0CB'}),
|
fill: new Fill({color: '#FFC0CB'}),
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.4 KiB |
@@ -19,6 +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',
|
||||||
fill: new Fill({
|
fill: new Fill({
|
||||||
color: 'red'
|
color: 'red'
|
||||||
}),
|
}),
|
||||||
@@ -31,6 +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',
|
||||||
fill: new Fill({
|
fill: new Fill({
|
||||||
color: 'red'
|
color: 'red'
|
||||||
}),
|
}),
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 7.7 KiB |
@@ -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 sans-serif',
|
font: '12px Ubuntu',
|
||||||
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 sans-serif',
|
font: '12px Ubuntu',
|
||||||
rotation: Math.PI,
|
rotation: Math.PI,
|
||||||
stroke: new Stroke({
|
stroke: new Stroke({
|
||||||
color: 'red',
|
color: 'red',
|
||||||
@@ -55,6 +55,7 @@ feature = new Feature({
|
|||||||
});
|
});
|
||||||
feature.setStyle(new Style({
|
feature.setStyle(new Style({
|
||||||
text: new Text({
|
text: new Text({
|
||||||
|
font: 'Ubuntu',
|
||||||
text: 'rotateWithView',
|
text: 'rotateWithView',
|
||||||
rotateWithView: true,
|
rotateWithView: true,
|
||||||
stroke: new Stroke({
|
stroke: new Stroke({
|
||||||
@@ -71,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 sans-serif',
|
font: '12px Ubuntu',
|
||||||
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)'
|
||||||
@@ -91,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 sans-serif',
|
font: '12px Ubuntu',
|
||||||
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)'
|
||||||
|
|||||||
|
After Width: | Height: | Size: 440 KiB |
|
After Width: | Height: | Size: 422 KiB |
@@ -16,6 +16,20 @@
|
|||||||
.ol-control {
|
.ol-control {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: "Ubuntu";
|
||||||
|
src: url("/data/fonts/ubuntu-regular-webfont.eot");
|
||||||
|
src: url("/data/fonts/ubuntu-regular-webfont.woff") format("woff"),
|
||||||
|
url("/data/fonts/ubuntu-regular-webfont.svg#filename") format("svg");
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: "Ubuntu";
|
||||||
|
font-weight: bold;
|
||||||
|
font-style: italic;
|
||||||
|
src: url("/data/fonts/ubuntu-bold-italic-webfont.eot");
|
||||||
|
src: url("/data/fonts/ubuntu-bold-italic-webfont.woff") format("woff"),
|
||||||
|
url("/data/fonts/ubuntu-bold-italic-webfont.svg#filename") format("svg");
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -313,6 +313,7 @@ if (require.main === module) {
|
|||||||
const options = yargs.
|
const options = yargs.
|
||||||
option('fix', {
|
option('fix', {
|
||||||
describe: 'Accept all screenshots as accepted',
|
describe: 'Accept all screenshots as accepted',
|
||||||
|
type: 'boolean',
|
||||||
default: false
|
default: false
|
||||||
}).
|
}).
|
||||||
option('host', {
|
option('host', {
|
||||||
|
|||||||
|
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||