Skip to content

Commit

Permalink
refacto replace provider WMTS and rasteriser by extendedDataProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Jul 6, 2018
1 parent bbf0a9b commit f440096
Show file tree
Hide file tree
Showing 26 changed files with 467 additions and 419 deletions.
18 changes: 12 additions & 6 deletions examples/globe_vector.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,28 @@

promises.push(globeView.addLayer({
type: 'color',
url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/croquis.kml',
protocol: 'rasterizer',
id: 'Kml',
name: 'kml',
transparent: true,
source: {
protocol: 'file',
url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/croquis.kml',
},
}));

promises.push(globeView.addLayer({
type: 'color',
url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/ULTRA2009.gpx',
protocol: 'rasterizer',
id: 'Gpx',
name: 'Ultra 2009',
transparent: true,
source: {
url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/ULTRA2009.gpx',
protocol: 'file',
},
}));

promises.push(globeView.addLayer({
type: 'color',
url: 'https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/departements/09-ariege/departement-09-ariege.geojson',
protocol: 'rasterizer',
id: 'ariege',
name: 'ariege',
transparent: true,
Expand All @@ -97,6 +99,10 @@
fillOpacity: 0.5,
stroke: 'white',
},
source: {
url: 'https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/departements/09-ariege/departement-09-ariege.geojson',
protocol: 'file',
},
}));

var menuGlobe = new GuiTools('menuDiv', globeView);
Expand Down
8 changes: 4 additions & 4 deletions examples/layers/JSONLayers/IGN_MNT.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"type": "elevation",
"protocol": "wmts",
"id": "IGN_MNT",
"url": "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
"noDataValue" : -99999,
"updateStrategy": {
"type": 1,
"options": {
"groups": [3, 7, 11]
}
},
"format": "image/x-bil;bits=32",
"options": {
"source": {
"protocol": "wmts",
"url": "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
"format": "image/x-bil;bits=32",
"attribution" : {
"name":"IGN",
"url":"http://www.ign.fr/"
Expand Down
8 changes: 4 additions & 4 deletions examples/layers/JSONLayers/IGN_MNT_HIGHRES.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"type": "elevation",
"protocol": "wmts",
"id": "IGN_MNT_HIGHRES",
"url": "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
"noDataValue" : -99999,
"updateStrategy": {
"type": 1,
"options": {
"groups": [11, 14]
}
},
"format": "image/x-bil;bits=32",
"options": {
"source": {
"protocol": "wmts",
"url": "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
"format": "image/x-bil;bits=32",
"attribution" : {
"name":"IGN",
"url":"http://www.ign.fr/"
Expand Down
20 changes: 8 additions & 12 deletions examples/layers/JSONLayers/Ortho.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
{
"type": "color",
"protocol": "wmts",
"id": "Ortho",
"url": "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
"networkOptions": {
"crossOrigin": "anonymous"
},
"updateStrategy": {
"type": 0,
"options": {}
},
"format": "image/jpeg",
"options": {
"id": "Ortho",
"source": {
"protocol": "wmts",
"url": "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
"networkOptions": {
"crossOrigin": "anonymous"
},
"format": "image/jpeg",
"attribution" : {
"name":"IGN",
"url":"http://www.ign.fr/"
Expand Down
8 changes: 4 additions & 4 deletions examples/layers/JSONLayers/WORLD_DTM.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

{
"type": "elevation",
"protocol": "wmts",
"id": "MNT_WORLD_SRTM3",
"url": "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
"noDataValue": -99999,
"updateStrategy": {
"type": 1,
"options": {
"groups": [3, 7, 9]
}
},
"format": "image/x-bil;bits=32",
"options": {
"source": {
"format": "image/x-bil;bits=32",
"protocol": "wmts",
"url": "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
"name": "ELEVATION.ELEVATIONGRIDCOVERAGE.SRTM3",
"tileMatrixSet": "WGS84G",
"tileMatrixSetLimits": {
Expand Down
18 changes: 9 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<script type="text/javascript">
/* global itowns,document,GuiTools, debug, window */

var positionOnGlobe = { longitude: 2.351323, latitude: 48.856712, altitude: 25000000 };
var positionOnGlobe = { longitude: 6, latitude: 45, altitude: 250000 };

// iTowns namespace defined here
var viewerDiv = document.getElementById('viewerDiv');
Expand All @@ -48,15 +48,15 @@

var promises = [];
promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Ortho.json').then(addLayerCb));
promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/OrthosCRS.json').then(addLayerCb));
promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/ScanEX.json').then(addLayerCb));
promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Region.json').then(addLayerCb));
// promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/OrthosCRS.json').then(addLayerCb));
// promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/ScanEX.json').then(addLayerCb));
// promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Region.json').then(addLayerCb));

promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Cada.json').then(addLayerCb));
promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Administrative.json').then(addLayerCb));
promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Transport.json').then(addLayerCb));
promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Railways.json').then(addLayerCb));
promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Denomination.json').then(addLayerCb));
// promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Cada.json').then(addLayerCb));
// promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Administrative.json').then(addLayerCb));
// promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Transport.json').then(addLayerCb));
// promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Railways.json').then(addLayerCb));
// promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/Denomination.json').then(addLayerCb));

promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/WORLD_DTM.json').then(addLayerCb));
promises.push(itowns.Fetcher.json('examples/layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addLayerCb));
Expand Down
24 changes: 24 additions & 0 deletions src/Core/Geographic/Extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,28 @@ Extent.prototype.expandByPoint = function expandByPoint(coordinates) {
}
};

Extent.prototype.extentParentWithPitch = function extentParentWithPitch(levelParent) {
if (_isTiledCRS(this.crs())) {
if (levelParent && levelParent !== this.zoom) {
const diffLevel = this.zoom - levelParent;
const diff = Math.pow(2, diffLevel);
const invDiff = 1 / diff;

const r = (this.row - (this.row % diff)) * invDiff;
const c = (this.col - (this.col % diff)) * invDiff;

const pitch = new THREE.Vector4(
this.col * invDiff - c,
this.row * invDiff - r,
invDiff,
invDiff);

const extent = new Extent(this.crs(), levelParent, r, c);
return { extent, pitch };
} else {
return { extent: this, pitch: new THREE.Vector4(0, 0, 1, 1) };
}
}
};

export default Extent;
2 changes: 1 addition & 1 deletion src/Core/Prefab/GlobeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ GlobeView.prototype.addLayer = function addLayer(layer) {
const colorLayerCount = this.getLayers(l => l.type === 'color').length;
layer.sequence = colorLayerCount;
} else if (layer.type == 'elevation') {
if (layer.protocol === 'wmts' && layer.options.tileMatrixSet !== 'WGS84G') {
if (layer.source.protocol === 'wmts' && layer.source.tileMatrixSet !== 'WGS84G') {
throw new Error('Only WGS84G tileMatrixSet is currently supported for WMTS elevation layers');
}
}
Expand Down
17 changes: 8 additions & 9 deletions src/Core/Scheduler/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
*/

import PriorityQueue from 'js-priority-queue';
import WMTSProvider from '../../Provider/WMTSProvider';
import extendedDataProvider from '../../Provider/extendedDataProvider';
import WMSProvider from '../../Provider/WMSProvider';
import TileProvider from '../../Provider/TileProvider';
import $3dTilesProvider from '../../Provider/3dTilesProvider';
import TMSProvider from '../../Provider/TMSProvider';
import PointCloudProvider from '../../Provider/PointCloudProvider';
import WFSProvider from '../../Provider/WFSProvider';
import RasterProvider from '../../Provider/RasterProvider';
import StaticProvider from '../../Provider/StaticProvider';
import CancelledCommandException from './CancelledCommandException';

Expand Down Expand Up @@ -132,21 +131,21 @@ Scheduler.prototype.constructor = Scheduler;

Scheduler.prototype.initDefaultProviders = function initDefaultProviders() {
// Register all providers
this.addProtocolProvider('wmts', WMTSProvider);
this.addProtocolProvider('wmtsc', WMTSProvider);
this.addProtocolProvider('wmts', extendedDataProvider);
this.addProtocolProvider('wmtsc', extendedDataProvider);
this.addProtocolProvider('tile', TileProvider);
this.addProtocolProvider('wms', WMSProvider);
this.addProtocolProvider('3d-tiles', $3dTilesProvider);
this.addProtocolProvider('tms', TMSProvider);
this.addProtocolProvider('xyz', TMSProvider);
this.addProtocolProvider('potreeconverter', PointCloudProvider);
this.addProtocolProvider('wfs', WFSProvider);
this.addProtocolProvider('rasterizer', RasterProvider);
this.addProtocolProvider('file', extendedDataProvider);
this.addProtocolProvider('static', StaticProvider);
};

Scheduler.prototype.runCommand = function runCommand(command, queue, executingCounterUpToDate) {
var provider = this.providers[command.layer.protocol];
var provider = this.providers[command.layer.protocol || command.layer.source.protocol];

if (!provider) {
throw new Error('No known provider for layer', command.layer.id);
Expand Down Expand Up @@ -282,9 +281,9 @@ Scheduler.prototype.addProtocolProvider = function addProtocolProvider(protocol,
if (typeof (provider.executeCommand) !== 'function') {
throw new Error(`Can't add provider for ${protocol}: missing a executeCommand function.`);
}
if (typeof (provider.preprocessDataLayer) !== 'function') {
throw new Error(`Can't add provider for ${protocol}: missing a preprocessDataLayer function.`);
}
// if (typeof (provider.preprocessDataLayer) !== 'function') {
// throw new Error(`Can't add provider for ${protocol}: missing a preprocessDataLayer function.`);
// }

this.providers[protocol] = provider;
};
Expand Down
20 changes: 10 additions & 10 deletions src/Core/TileMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ TileMesh.prototype.setSelected = function setSelected(select) {
this.material.setSelected(select);
};

TileMesh.prototype.setTextureElevation = function setTextureElevation(elevation) {
TileMesh.prototype.setTextureElevation = function setTextureElevation(elevation, offsetScale = new THREE.Vector4(0, 0, 1, 1)) {
if (this.material === null) {
return;
}

const offsetScale = elevation.pitch || new THREE.Vector4(0, 0, 1, 1);
this.setBBoxZ(elevation.min, elevation.max);

this.material.setTexture(elevation.texture, l_ELEVATION, 0, offsetScale);
Expand All @@ -149,12 +148,12 @@ TileMesh.prototype.updateGeometricError = function updateGeometricError() {
this.geometricError = this.boundingSphere.radius / SIZE_TEXTURE_TILE;
};

TileMesh.prototype.setTexturesLayer = function setTexturesLayer(textures, layerType, layerId) {
TileMesh.prototype.setTexturesLayer = function setTexturesLayer(textures, layerType, layerId, pitchs) {
if (this.material === null) {
return;
}
if (textures) {
this.material.setTexturesLayer(textures, layerType, layerId);
this.material.setTexturesLayer(textures, layerType, layerId, pitchs);
}
};

Expand Down Expand Up @@ -204,9 +203,10 @@ TileMesh.prototype.changeSequenceLayers = function changeSequenceLayers(sequence
};

TileMesh.prototype.getCoordsForLayer = function getCoordsForLayer(layer) {
if (layer.protocol.indexOf('wmts') == 0) {
OGCWebServiceHelper.computeTileMatrixSetCoordinates(this, layer.options.tileMatrixSet);
return this.wmtsCoords[layer.options.tileMatrixSet];
if (layer.protocol.indexOf('wmts') == 0 /* || layer.protocol.indexOf('file') == 0 */) {
const source = layer;
OGCWebServiceHelper.computeTileMatrixSetCoordinates(this, source.tileMatrixSet);
return this.wmtsCoords[source.tileMatrixSet];
} else if (layer.protocol == 'wms' && this.extent.crs() != layer.projection) {
if (layer.projection == 'EPSG:3857') {
const tilematrixset = 'PM';
Expand All @@ -230,9 +230,9 @@ TileMesh.prototype.getCoordsForLayer = function getCoordsForLayer(layer) {
};

TileMesh.prototype.getZoomForLayer = function getZoomForLayer(layer) {
if (layer.protocol.indexOf('wmts') == 0) {
OGCWebServiceHelper.computeTileMatrixSetCoordinates(this, layer.options.tileMatrixSet);
return this.wmtsCoords[layer.options.tileMatrixSet][0].zoom;
if (layer.source && layer.source.protocol.indexOf('wmts') == 0) {
OGCWebServiceHelper.computeTileMatrixSetCoordinates(this, layer.source.tileMatrixSet);
return this.wmtsCoords[layer.source.tileMatrixSet][0].zoom;
} else {
return this.level;
}
Expand Down
Loading

0 comments on commit f440096

Please sign in to comment.