Skip to content

Commit

Permalink
Update cesium to version 1.106.1
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap committed Jul 3, 2023
1 parent 3df202c commit e9e3883
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 153 deletions.
10 changes: 5 additions & 5 deletions build/buildConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function mapArgumentsToObject(args, func) {
const getCesiumPath = ({ prod, paths }) => {
return prod
? path.join(paths.base, 'node_modules', 'cesium', 'Build', 'Cesium')
: path.join(paths.base, 'node_modules', 'cesium', 'Source');
: path.join(paths.base, 'node_modules', 'cesium', 'Build', 'CesiumUnminified');
};

module.exports = (...args) => mapArgumentsToObject(args, ({
Expand Down Expand Up @@ -178,16 +178,16 @@ module.exports = (...args) => mapArgumentsToObject(args, ({
Buffer: ['buffer', 'Buffer']
}),
new NormalModuleReplacementPlugin(/proj4$/, path.join(paths.framework, "libs", "proj4")),
// it's not possible to load directly from the module name `cesium/Build/Cesium/Widgets/widgets.css`
// see https://github.com/CesiumGS/cesium/issues/9212
new NormalModuleReplacementPlugin(/^cesium\/index\.css$/, path.join(paths.base, "node_modules", "cesium/Build/Cesium/Widgets/widgets.css")),
new NoEmitOnErrorsPlugin()]
.concat(castArray(plugins))
.concat(prod ? prodPlugins : devPlugins),
resolve: {
fallback: {
timers: false,
stream: false
stream: false,
http: false,
https: false,
zlib: false
},
extensions: [".js", ".jsx"],
alias: assign({}, {
Expand Down
16 changes: 8 additions & 8 deletions build/testConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assign = require('object-assign');
const nodePath = require('path');
const webpack = require('webpack');
const ProvidePlugin = require("webpack/lib/ProvidePlugin");
const NormalModuleReplacementPlugin = require("webpack/lib/NormalModuleReplacementPlugin");

const {
VERSION_INFO_DEFINE_PLUGIN
} = require('./BuildUtils');
Expand All @@ -23,7 +23,7 @@ module.exports = ({browsers = [ 'ChromeHeadless' ], files, path, testFile, singl
files: [
...files,
// add all assets needed for Cesium library
{ pattern: './node_modules/cesium/Source/**/*', included: false }
{ pattern: './node_modules/cesium/Build/CesiumUnminified/**/*', included: false }
],

plugins: [
Expand Down Expand Up @@ -131,7 +131,10 @@ module.exports = ({browsers = [ 'ChromeHeadless' ], files, path, testFile, singl
resolve: {
fallback: {
timers: false,
stream: false
stream: false,
http: false,
https: false,
zlib: false
},
alias: assign({}, {
jsonix: '@boundlessgeo/jsonix',
Expand All @@ -154,12 +157,9 @@ module.exports = ({browsers = [ 'ChromeHeadless' ], files, path, testFile, singl
}),
new webpack.DefinePlugin({
// Define relative base path in cesium for loading assets
'CESIUM_BASE_URL': JSON.stringify('base/node_modules/cesium/Source')
'CESIUM_BASE_URL': JSON.stringify('base/node_modules/cesium/Build/CesiumUnminified')
}),
VERSION_INFO_DEFINE_PLUGIN,
// it's not possible to load directly from the module name `cesium/Build/Cesium/Widgets/widgets.css`
// see https://github.com/CesiumGS/cesium/issues/9212
new NormalModuleReplacementPlugin(/^cesium\/index\.css$/, nodePath.join(basePath, 'node_modules', 'cesium/Build/Cesium/Widgets/widgets.css'))
VERSION_INFO_DEFINE_PLUGIN
]
},
webpackServer: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"buffer": "6.0.3",
"canvas-to-blob": "0.0.0",
"canvg-browser": "1.0.0",
"cesium": "1.91.0",
"cesium": "1.106.1",
"chroma-js": "1.3.7",
"classnames": "2.2.5",
"codemirror": "5.18.2",
Expand Down
9 changes: 3 additions & 6 deletions web/client/components/map/cesium/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/
import * as Cesium from 'cesium';
// it's not possible to load directly from the module name `cesium/Build/Cesium/Widgets/widgets.css`
// see https://github.com/CesiumGS/cesium/issues/9212
import 'cesium/index.css';

import 'cesium/Build/Cesium/Widgets/widgets.css';
import '@znemz/cesium-navigation/dist/index.css';
import viewerCesiumNavigationMixin from '@znemz/cesium-navigation';

Expand Down Expand Up @@ -358,8 +355,8 @@ class CesiumMap extends React.Component {
msId = feature.tileset.msId;
// 3d tile feature does not contain a geometry in the Cesium3DTileFeature class
// it has content but refers to the whole tile model
const propertyNames = feature.getPropertyNames();
properties = Object.fromEntries(propertyNames.map(key => [key, feature.getProperty(key)]));
const getPropertyIds = feature.getPropertyIds();
properties = Object.fromEntries(getPropertyIds.map(key => [key, feature.getProperty(key)]));
} else if (feature?.id instanceof Cesium.Entity && feature.id.id && feature.id.properties) {
const {properties: {propertyNames}, entityCollection: {owner: {name}}} = feature.id;
properties = Object.fromEntries(propertyNames.map(key => [key, feature.id.properties[key].getValue(0)]));
Expand Down
80 changes: 39 additions & 41 deletions web/client/components/map/cesium/__tests__/Layer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ReactDOM from 'react-dom';
import CesiumLayer from '../Layer';
import expect from 'expect';
import * as Cesium from 'cesium';

import { waitFor } from '@testing-library/react';
import assign from 'object-assign';

import '../../../../utils/cesium/Layers';
Expand Down Expand Up @@ -1207,8 +1207,8 @@ describe('Cesium layer', () => {
map={map}
/>, document.getElementById('container'));
expect(cmp).toBeTruthy();
expect(cmp.layer.tileSet).toBeTruthy();
expect(cmp.layer.tileSet._url).toBe('/tileset.json');
expect(cmp.layer.resource).toBeTruthy();
expect(cmp.layer.resource.request.url).toBe('/tileset.json');
});
it('Use proxy when needed', () => {
const options = {
Expand All @@ -1234,8 +1234,8 @@ describe('Cesium layer', () => {
map={map}
/>, document.getElementById('container'));
expect(cmp).toBeTruthy();
expect(cmp.layer.tileSet).toBeTruthy();
expect(cmp.layer.tileSet._url).toBe('/mapstore/proxy/?url=http%3A%2F%2Fservice.org%2Ftileset.json');
expect(cmp.layer.resource).toBeTruthy();
expect(cmp.layer.resource.request.url).toBe('/mapstore/proxy/?url=http%3A%2F%2Fservice.org%2Ftileset.json');
});
it('should create a 3d tiles layer with visibility set to false', () => {
const options = {
Expand All @@ -1262,7 +1262,7 @@ describe('Cesium layer', () => {
/>, document.getElementById('container'));
expect(cmp).toBeTruthy();
expect(cmp.layer).toBeTruthy();
expect(cmp.layer.tileSet).toBeFalsy();
expect(cmp.layer.getTileSet).toBeFalsy();
});
it('should create a 3d tiles layer with and offset applied to the height', (done) => {
const options = {
Expand Down Expand Up @@ -1290,32 +1290,25 @@ describe('Cesium layer', () => {
/>, document.getElementById('container'));
expect(cmp).toBeTruthy();
expect(cmp.layer).toBeTruthy();
expect(cmp.layer.tileSet).toBeTruthy();
expect(Cesium.Matrix4.toArray(cmp.layer.tileSet.modelMatrix)).toEqual(
[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
]
);
cmp.layer.tileSet.readyPromise.then(() => {
expect(Cesium.Matrix4.toArray(cmp.layer.tileSet.modelMatrix).map(Math.round)).toEqual(
[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
19, -74, 64, 1
]
);
done();
});
waitFor(() => expect(!!cmp.layer.getTileSet()).toBe(true))
.then(() => {
expect(Cesium.Matrix4.toArray(cmp.layer.getTileSet().modelMatrix).map(Math.round)).toEqual(
[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
19, -74, 64, 1
]
);
done();
})
.catch(done);
});

it('should not crash if the heightOffset is not a number', () => {
it('should not crash if the heightOffset is not a number', (done) => {
const options = {
type: '3dtiles',
url: 'http://service.org/tileset.json',
url: 'base/web/client/test-resources/3dtiles/tileset.json',
title: 'Title',
visibility: true,
heightOffset: NaN,
Expand All @@ -1338,18 +1331,21 @@ describe('Cesium layer', () => {
/>, document.getElementById('container'));
expect(cmp).toBeTruthy();
expect(cmp.layer).toBeTruthy();
expect(cmp.layer.tileSet).toBeTruthy();
expect(Cesium.Matrix4.toArray(cmp.layer.tileSet.modelMatrix)).toEqual(
[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
]
);
waitFor(() => expect(!!cmp.layer.getTileSet()).toBe(true))
.then(() => {
expect(Cesium.Matrix4.toArray(cmp.layer.getTileSet().modelMatrix)).toEqual(
[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
]
);
done();
}).catch(done);
});

it('should create a vector layer', () => {
it('should create a vector layer', (done) => {
const options = {
type: 'vector',
features: [{ type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [0, 0] } }],
Expand All @@ -1375,10 +1371,11 @@ describe('Cesium layer', () => {
expect(cmp).toBeTruthy();
expect(cmp.layer).toBeTruthy();
expect(cmp.layer.dataSource).toBeTruthy();
expect(cmp.layer.dataSource.entities.values.length).toBe(1);
expect(cmp.layer.detached).toBe(true);
waitFor(() => expect(cmp.layer.dataSource.entities.values.length).toBe(1))
.then(() => done());
});
it('should create a vector layer queryable', () => {
it('should create a vector layer queryable', (done) => {
const options = {
type: 'vector',
features: [{ type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [0, 0] } }],
Expand All @@ -1405,9 +1402,10 @@ describe('Cesium layer', () => {
expect(cmp).toBeTruthy();
expect(cmp.layer).toBeTruthy();
expect(cmp.layer.dataSource).toBeTruthy();
expect(cmp.layer.dataSource.entities.values.length).toBe(1);
expect(cmp.layer.detached).toBe(true);
expect(cmp.layer.dataSource.queryable).toBe(false);
waitFor(() => expect(cmp.layer.dataSource.entities.values.length).toBe(1))
.then(() => done());
});
it('should create a wfs layer', () => {
const options = {
Expand Down
3 changes: 1 addition & 2 deletions web/client/components/map/cesium/plugins/EmptyLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

import Layers from '../../../../utils/cesium/Layers';
import {
when,
GeographicTilingScheme
} from 'cesium';

function EmptyImageryProvider({ color = '#ffffff' } = {}) {
this._tilingScheme = new GeographicTilingScheme();
this._readyPromise = when.resolve(true);
this._readyPromise = Promise.resolve(true);
// create a tile 1px x 1px of color white to simulate an empty background
this._canvas = document.createElement('canvas');
this._canvas.width = 1;
Expand Down
85 changes: 48 additions & 37 deletions web/client/components/map/cesium/plugins/ThreeDTilesLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,40 +88,50 @@ Layers.registerType('3dtiles', {
create: (options, map) => {
if (options.visibility && options.url) {

const tileSet = map.scene.primitives.add(new Cesium.Cesium3DTileset({
showCreditsOnScreen: true,
url: new Cesium.Resource({
url: options.url,
proxy: needProxy(options.url) ? new Cesium.DefaultProxy(getProxyUrl()) : undefined
// TODO: axios supports also adding access tokens or credentials (e.g. authkey, Authentication header ...).
// if we want to use internal cesium functionality to retrieve data
// we need to create a utility to set a CesiumResource that applies also this part.
// in addition to this proxy.
})
}));

// assign the original mapstore id of the layer
tileSet.msId = options.id;
let tileSet;
const resource = new Cesium.Resource({
url: options.url,
proxy: needProxy(options.url) ? new Cesium.DefaultProxy(getProxyUrl()) : undefined
// TODO: axios supports also adding access tokens or credentials (e.g. authkey, Authentication header ...).
// if we want to use internal cesium functionality to retrieve data
// we need to create a utility to set a CesiumResource that applies also this part.
// in addition to this proxy.
});
Cesium.Cesium3DTileset.fromUrl(resource,
{
showCreditsOnScreen: true
}
).then((_tileSet) => {
tileSet = _tileSet;
map.scene.primitives.add(tileSet);
// assign the original mapstore id of the layer
tileSet.msId = options.id;

ensureReady(tileSet, () => {
updateModelMatrix(tileSet, options);
clip3DTiles(tileSet, options, map);
getStyle(options)
.then((style) => {
if (style) {
tileSet.style = new Cesium.Cesium3DTileStyle(style);
}
});
ensureReady(tileSet, () => {
updateModelMatrix(tileSet, options);
clip3DTiles(tileSet, options, map);
getStyle(options)
.then((style) => {
if (style) {
tileSet.style = new Cesium.Cesium3DTileStyle(style);
}
});
});
});

return {
detached: true,
tileSet,
getTileSet: () => tileSet,
resource,
remove: () => {
map.scene.primitives.remove(tileSet);
if (tileSet) {
map.scene.primitives.remove(tileSet);
}
},
setVisible: (visible) => {
tileSet.show = !!visible;
if (tileSet) {
tileSet.show = !!visible;
}
}
};
}
Expand All @@ -139,29 +149,30 @@ Layers.registerType('3dtiles', {
layer.remove();
return null;
}
const tileSet = layer?.getTileSet();
if (
(!isEqual(newOptions.clippingPolygon, oldOptions.clippingPolygon)
|| newOptions.clippingPolygonUnion !== oldOptions.clippingPolygonUnion
|| newOptions.clipOriginalGeometry !== oldOptions.clipOriginalGeometry)
&& layer?.tileSet) {
ensureReady(layer.tileSet, () => {
clip3DTiles(layer.tileSet, newOptions, map);
&& tileSet) {
ensureReady(tileSet, () => {
clip3DTiles(tileSet, newOptions, map);
});
}
if (!isEqual(newOptions.style, oldOptions.style) && layer?.tileSet) {
ensureReady(layer.tileSet, () => {
if (!isEqual(newOptions.style, oldOptions.style) && tileSet) {
ensureReady(tileSet, () => {
getStyle(newOptions)
.then((style) => {
if (style && layer?.tileSet) {
layer.tileSet.makeStyleDirty();
layer.tileSet.style = new Cesium.Cesium3DTileStyle(style);
if (style && tileSet) {
tileSet.makeStyleDirty();
tileSet.style = new Cesium.Cesium3DTileStyle(style);
}
});
});
}
if (layer?.tileSet && newOptions.heightOffset !== oldOptions.heightOffset) {
ensureReady(layer.tileSet, () => {
updateModelMatrix(layer.tileSet, newOptions);
if (tileSet && newOptions.heightOffset !== oldOptions.heightOffset) {
ensureReady(tileSet, () => {
updateModelMatrix(tileSet, newOptions);
});
}
return null;
Expand Down
Loading

0 comments on commit e9e3883

Please sign in to comment.