Skip to content

Commit

Permalink
refactor(core): tile matrix set and projection/crs handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Jul 29, 2019
1 parent 5638615 commit f5d8cac
Show file tree
Hide file tree
Showing 31 changed files with 456 additions and 467 deletions.
3 changes: 2 additions & 1 deletion src/Converter/convertToTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export default {
return newTileGeometry(builder, paramsGeometry).then((result) => {
// build tile mesh
result.geometry._count++;
const material = new LayeredMaterial(layer.materialOptions);
const crsCount = layer.tileMatrixSets.length;
const material = new LayeredMaterial(layer.materialOptions, crsCount);
const tile = new TileMesh(result.geometry, material, layer, extent, level);

// Commented because layer.threejsLayer is undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/Converter/textureConverter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as THREE from 'three';
import Feature2Texture from 'Converter/Feature2Texture';
import Extent from 'Core/Geographic/Extent';
import CRS from 'Core/Geographic/Crs';

const extentTexture = new Extent('EPSG:4326', [0, 0, 0, 0]);

Expand All @@ -25,7 +26,7 @@ export default {
new THREE.Color(layer.backgroundLayer.paint['background-color']) :
undefined;

extentDestination.as(layer.projection, extentTexture);
extentDestination.as(CRS.formatToEPSG(layer.projection), extentTexture);
texture = Feature2Texture.createTextureFromFeature(data, extentTexture, 256, layer.style, backgroundColor);
texture.parsedData = data;
texture.coords = extentDestination;
Expand Down
52 changes: 51 additions & 1 deletion src/Core/Geographic/Crs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@ import proj4 from 'proj4';

proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs');

const TMS = [
'WMTS:WGS84',
'WMTS:PM',
];

const EPSG = [
'EPSG:4326',
'EPSG:3857',
];

function formatToTms(crs) {
if (crs) {
if (crs.includes('WMTS')) {
return crs;
}
const i = EPSG.indexOf(crs);
if (i > -1) {
return TMS[i];
} else if (crs.includes('EPSG')) {
return `WMTS:TMS:${crs.replace('EPSG:', '')}`;
}
}
}

function formatToEPSG(crs) {
if (crs) {
if (crs.includes('EPSG')) {
return crs;
} else if (EPSG[TMS.indexOf(crs)]) {
return EPSG[TMS.indexOf(crs)];
} else {
return `EPSG:${crs.match(/\d+/)[0]}`;
}
}
}

const UNIT = {
DEGREE: 1,
METER: 2,
Expand All @@ -26,7 +62,7 @@ function toUnit(crs) {
case 'EPSG:4326' : return UNIT.DEGREE;
case 'EPSG:4978' : return UNIT.METER;
default: {
const p = proj4.defs(crs);
const p = proj4.defs(formatToEPSG(crs));
if (!p) {
return undefined;
}
Expand Down Expand Up @@ -118,4 +154,18 @@ export default {
return 0.001;
}
},
/**
* format crs to European Petroleum Survey Group notation : EPSG:XXXX.
*
* @param {string} crs The crs to format
* @return {string} formated crs
*/
formatToEPSG,
/**
* format crs to tile matrix set notation : WMTS:XXXX.
*
* @param {string} crs The crs to format
* @return {string} formated crs
*/
formatToTms,
};
Loading

0 comments on commit f5d8cac

Please sign in to comment.