Deprecate the imageSmoothing option for sources
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
---
|
||||
layout: example.html
|
||||
title: Disable Image Smoothing
|
||||
shortdesc: Example of disabling image smoothing
|
||||
title: Interpolation
|
||||
shortdesc: Example of data interpolation
|
||||
docs: >
|
||||
Example of disabling image smoothing when using raster DEM (digital elevation model) data.
|
||||
The <code>imageSmoothing: false</code> setting is used to disable canvas image smoothing during
|
||||
Example of data resampling when using raster DEM (digital elevation model) data.
|
||||
The <code>interpolate: false</code> setting is used to disable interpolation of data values during
|
||||
reprojection and rendering. Elevation data is
|
||||
calculated from the pixel value returned by <b>forEachLayerAtPixel</b>. For comparison a second map
|
||||
with smoothing enabled returns inaccuate elevations which are very noticeable close to 3107 meters
|
||||
with interpolation enabled returns inaccuate elevations which are very noticeable close to 3107 meters
|
||||
due to how elevation is calculated from the pixel value.
|
||||
tags: "disable image smoothing, xyz, maptiler, reprojection"
|
||||
tags: "disable image interpolation, xyz, maptiler, reprojection"
|
||||
cloak:
|
||||
- key: get_your_own_D6rA4zTHduk6KOKTXzGB
|
||||
value: Get your own API key at https://www.maptiler.com/cloud/
|
||||
---
|
||||
<div class="wrapper">
|
||||
<div class="half">
|
||||
<h4>Smoothing Disabled</h4>
|
||||
<h4>Not Interpolated</h4>
|
||||
<div id="map1" class="map"></div>
|
||||
<div>
|
||||
<label>
|
||||
@@ -24,16 +24,9 @@ cloak:
|
||||
<span id="info1">0.0</span> meters
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
Imagery opacity
|
||||
<input id="opacity" type="range" min="0" max="100" value="80" />
|
||||
<span id="output"></span> %
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="half">
|
||||
<h4>Uncorrected Comparison</h4>
|
||||
<h4>Interpolated</h4>
|
||||
<div id="map2" class="map"></div>
|
||||
<div>
|
||||
<label>
|
||||
@@ -8,7 +8,7 @@ const attributions =
|
||||
'<a href="https://www.maptiler.com/copyright/" target="_blank">© MapTiler</a> ' +
|
||||
'<a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>';
|
||||
|
||||
const disabledLayer = new TileLayer({
|
||||
const notInterpolated = new TileLayer({
|
||||
// specify className so forEachLayerAtPixel can distinguish layers
|
||||
className: 'ol-layer-dem',
|
||||
source: new XYZ({
|
||||
@@ -18,21 +18,11 @@ const disabledLayer = new TileLayer({
|
||||
tileSize: 512,
|
||||
maxZoom: 12,
|
||||
crossOrigin: '',
|
||||
imageSmoothing: false,
|
||||
interpolate: false,
|
||||
}),
|
||||
});
|
||||
|
||||
const imagery = new TileLayer({
|
||||
className: 'ol-layer-imagery',
|
||||
source: new XYZ({
|
||||
attributions: attributions,
|
||||
url: 'https://api.maptiler.com/tiles/satellite/{z}/{x}/{y}.jpg?key=' + key,
|
||||
maxZoom: 20,
|
||||
crossOrigin: '',
|
||||
}),
|
||||
});
|
||||
|
||||
const enabledLayer = new TileLayer({
|
||||
const interpolated = new TileLayer({
|
||||
source: new XYZ({
|
||||
attributions: attributions,
|
||||
url:
|
||||
@@ -43,30 +33,6 @@ const enabledLayer = new TileLayer({
|
||||
}),
|
||||
});
|
||||
|
||||
imagery.on('prerender', function (evt) {
|
||||
// use opaque background to conceal DEM while fully opaque imagery renders
|
||||
if (imagery.getOpacity() === 1) {
|
||||
evt.context.fillStyle = 'white';
|
||||
evt.context.fillRect(
|
||||
0,
|
||||
0,
|
||||
evt.context.canvas.width,
|
||||
evt.context.canvas.height
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const control = document.getElementById('opacity');
|
||||
const output = document.getElementById('output');
|
||||
const listener = function () {
|
||||
output.innerText = control.value;
|
||||
imagery.setOpacity(control.value / 100);
|
||||
};
|
||||
control.addEventListener('input', listener);
|
||||
control.addEventListener('change', listener);
|
||||
output.innerText = control.value;
|
||||
imagery.setOpacity(control.value / 100);
|
||||
|
||||
const view = new View({
|
||||
center: [6.893, 45.8295],
|
||||
zoom: 16,
|
||||
@@ -75,13 +41,13 @@ const view = new View({
|
||||
|
||||
const map1 = new Map({
|
||||
target: 'map1',
|
||||
layers: [disabledLayer, imagery],
|
||||
layers: [notInterpolated],
|
||||
view: view,
|
||||
});
|
||||
|
||||
const map2 = new Map({
|
||||
target: 'map2',
|
||||
layers: [enabledLayer],
|
||||
layers: [interpolated],
|
||||
view: view,
|
||||
});
|
||||
|
||||
@@ -101,7 +67,7 @@ const showElevations = function (evt) {
|
||||
},
|
||||
{
|
||||
layerFilter: function (layer) {
|
||||
return layer === disabledLayer;
|
||||
return layer === notInterpolated;
|
||||
},
|
||||
}
|
||||
);
|
||||
@@ -114,7 +80,7 @@ const showElevations = function (evt) {
|
||||
},
|
||||
{
|
||||
layerFilter: function (layer) {
|
||||
return layer === enabledLayer;
|
||||
return layer === interpolated;
|
||||
},
|
||||
}
|
||||
);
|
||||
@@ -8,6 +8,6 @@ tags: "reprojection, projection, proj4js, image, imagestatic"
|
||||
---
|
||||
<div id="map" class="map"></div>
|
||||
<div>
|
||||
<input type="checkbox" id="imageSmoothing" checked />
|
||||
<label for="imageSmoothing">Image smoothing</label>
|
||||
<input type="checkbox" id="interpolate" checked />
|
||||
<label for="interpolate">Interpolate</label>
|
||||
</div>
|
||||
|
||||
@@ -34,7 +34,7 @@ const map = new Map({
|
||||
}),
|
||||
});
|
||||
|
||||
const imageSmoothing = document.getElementById('imageSmoothing');
|
||||
const interpolate = document.getElementById('interpolate');
|
||||
|
||||
function setSource() {
|
||||
const source = new Static({
|
||||
@@ -44,10 +44,10 @@ function setSource() {
|
||||
crossOrigin: '',
|
||||
projection: 'EPSG:27700',
|
||||
imageExtent: imageExtent,
|
||||
imageSmoothing: imageSmoothing.checked,
|
||||
interpolate: interpolate.checked,
|
||||
});
|
||||
imageLayer.setSource(source);
|
||||
}
|
||||
setSource();
|
||||
|
||||
imageSmoothing.addEventListener('change', setSource);
|
||||
interpolate.addEventListener('change', setSource);
|
||||
|
||||
Reference in New Issue
Block a user