Adjustments to NumpyTiles example
This commit is contained in:
3
examples/numpytile.css
Normal file
3
examples/numpytile.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
input[type="range"] {
|
||||||
|
vertical-align: text-bottom;
|
||||||
|
}
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
---
|
---
|
||||||
layout: example.html
|
layout: example.html
|
||||||
title: Rendering 16-bit NumpyTiles
|
title: Rendering 16-bit NumpyTiles
|
||||||
shortdesc: Renders a multi-byte depth source image directly using webGL.
|
shortdesc: Renders a multi-byte depth source image directly using WebGL.
|
||||||
docs: >
|
docs: >
|
||||||
Use the NumpyTile format to render multibyte raster data.
|
This example uses a <code>ol/source/DataTile</code> source to load multi-byte raster data in the
|
||||||
tags: "numpytiles"
|
<a href="https://github.com/planetlabs/numpytiles-spec/"></a>NumpyTile</a> format.
|
||||||
|
The source is rendered with a <code>ol/layer/WebGLTile</code> layer. Adjusting the sliders above
|
||||||
|
performs a contrast stretch by adjusting the style variables set on the layer.
|
||||||
|
tags: "numpytiles, webgl"
|
||||||
|
resources:
|
||||||
|
- https://unpkg.com/@planet/ol-numpytiles@2.0.2/umd/NumpyLoader.js
|
||||||
---
|
---
|
||||||
<div id="map" class="map"></div>
|
<div id="map" class="map"></div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h5>Adjust colors</h5>
|
<h5>Contrast stretch</h5>
|
||||||
<ul>
|
<ul>
|
||||||
<li><b>Min:</b> <input type="range" min="1000" max="10000" id="color-floor"/></li>
|
<li>Min <input type="range" min="1000" max="10000" id="input-min"/> <span id="output-min"></span></li>
|
||||||
<li><b>Max:</b> <input type="range" min="10000" max="50000" id="color-ceil"/></li>
|
<li>Max <input type="range" min="10000" max="50000" id="input-max"/> <span id="output-max"></span></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript" src="https://unpkg.com/@planet/ol-numpytiles@2.0.2/umd/NumpyLoader.js"></script>
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import TileLayer from '../src/ol/layer/WebGLTile.js';
|
|||||||
import View from '../src/ol/View.js';
|
import View from '../src/ol/View.js';
|
||||||
|
|
||||||
import DataTileSource from '../src/ol/source/DataTile.js';
|
import DataTileSource from '../src/ol/source/DataTile.js';
|
||||||
import OsmSource from '../src/ol/source/OSM.js';
|
|
||||||
import {fromLonLat} from '../src/ol/proj.js';
|
import {fromLonLat} from '../src/ol/proj.js';
|
||||||
|
|
||||||
// 16-bit COG
|
// 16-bit COG
|
||||||
@@ -45,25 +44,26 @@ const interpolateBand = (bandIdx) => [
|
|||||||
['var', 'bMin'],
|
['var', 'bMin'],
|
||||||
0,
|
0,
|
||||||
['var', 'bMax'],
|
['var', 'bMax'],
|
||||||
1.0,
|
1,
|
||||||
];
|
];
|
||||||
|
|
||||||
const createNumpyStyle = (bandMin, bandMax) => ({
|
const initialMin = 3000;
|
||||||
color: [
|
const initialMax = 18000;
|
||||||
'array',
|
|
||||||
interpolateBand(3),
|
|
||||||
interpolateBand(2),
|
|
||||||
interpolateBand(1),
|
|
||||||
['band', 5],
|
|
||||||
],
|
|
||||||
variables: {
|
|
||||||
'bMin': bandMin,
|
|
||||||
'bMax': bandMax,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const numpyLayer = new TileLayer({
|
const numpyLayer = new TileLayer({
|
||||||
style: createNumpyStyle(3000, 18000),
|
style: {
|
||||||
|
color: [
|
||||||
|
'array',
|
||||||
|
interpolateBand(3),
|
||||||
|
interpolateBand(2),
|
||||||
|
interpolateBand(1),
|
||||||
|
['band', 5],
|
||||||
|
],
|
||||||
|
variables: {
|
||||||
|
'bMin': initialMin,
|
||||||
|
'bMax': initialMax,
|
||||||
|
},
|
||||||
|
},
|
||||||
source: new DataTileSource({
|
source: new DataTileSource({
|
||||||
loader: numpyTileLoader,
|
loader: numpyTileLoader,
|
||||||
bandCount: 5,
|
bandCount: 5,
|
||||||
@@ -72,34 +72,35 @@ const numpyLayer = new TileLayer({
|
|||||||
|
|
||||||
const map = new Map({
|
const map = new Map({
|
||||||
target: 'map',
|
target: 'map',
|
||||||
layers: [
|
layers: [numpyLayer],
|
||||||
new TileLayer({
|
|
||||||
source: new OsmSource(),
|
|
||||||
}),
|
|
||||||
numpyLayer,
|
|
||||||
],
|
|
||||||
view: new View({
|
view: new View({
|
||||||
center: fromLonLat([172.933, 1.3567]),
|
center: fromLonLat([172.933, 1.3567]),
|
||||||
zoom: 15,
|
zoom: 15,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const configureInputs = () => {
|
const inputMin = document.getElementById('input-min');
|
||||||
const colorFloor = document.getElementById('color-floor');
|
const inputMax = document.getElementById('input-max');
|
||||||
const colorCeil = document.getElementById('color-ceil');
|
const outputMin = document.getElementById('output-min');
|
||||||
|
const outputMax = document.getElementById('output-max');
|
||||||
|
|
||||||
colorFloor.addEventListener('input', (evt) => {
|
inputMin.addEventListener('input', (evt) => {
|
||||||
numpyLayer.updateStyleVariables({
|
numpyLayer.updateStyleVariables({
|
||||||
'bMin': parseFloat(evt.target.value),
|
'bMin': parseFloat(evt.target.value),
|
||||||
'bMax': parseFloat(colorCeil.value),
|
'bMax': parseFloat(inputMax.value),
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
outputMin.innerText = evt.target.value;
|
||||||
|
});
|
||||||
|
|
||||||
colorCeil.addEventListener('input', (evt) => {
|
inputMax.addEventListener('input', (evt) => {
|
||||||
numpyLayer.updateStyleVariables({
|
numpyLayer.updateStyleVariables({
|
||||||
'bMin': parseFloat(colorFloor.value),
|
'bMin': parseFloat(inputMin.value),
|
||||||
'bMax': parseFloat(evt.target.value),
|
'bMax': parseFloat(evt.target.value),
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
outputMax.innerText = evt.target.value;
|
||||||
configureInputs();
|
});
|
||||||
|
|
||||||
|
inputMin.value = initialMin;
|
||||||
|
inputMax.value = initialMax;
|
||||||
|
outputMin.innerText = initialMin;
|
||||||
|
outputMax.innerText = initialMax;
|
||||||
|
|||||||
Reference in New Issue
Block a user