Skip to content

Commit eccdab1

Browse files
authored
Merge pull request #956 from openlayers/updates
Draw canvas when cloning overlay and update dependencies
2 parents 3d17933 + c9eebe3 commit eccdab1

File tree

11 files changed

+64
-47
lines changed

11 files changed

+64
-47
lines changed

CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
# v 2.13 - 2021-05-20
4+
5+
* Changes
6+
* Port to CesiumJS 1.81
7+
* Port dev environment to webpack5
8+
* Copy canvas image when cloning overlay
9+
* Use tile fonction in MVT imagery provider (handle minus, ...)
10+
311
# v 2.12 - 2021-01-18
412

513
* Changes

buildtools/webpack.commons.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const path = require('path');
22

3-
43
const babelPresets = [['@babel/preset-env', {
54
'targets': {
65
'browsers': ['ie 11'],
@@ -31,16 +30,6 @@ const olcsRule = {
3130
}
3231
};
3332

34-
const htmlRule = {
35-
test: /\.html$/,
36-
use: [{
37-
loader: 'html-loader',
38-
options: {
39-
minimize: false,
40-
attributes: false
41-
}
42-
}]
43-
};
4433

4534
const iconRule = {
4635
test: /\.(png|svg)$/,
@@ -59,7 +48,6 @@ const config = {
5948
rules: [
6049
olRule,
6150
olcsRule,
62-
htmlRule,
6351
iconRule
6452
]
6553
},

buildtools/webpack.examples.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ for (const filename of glob.sync('examples/*.html', {onlyFiles: true})) {
2424
plugins.push(
2525
new HtmlWebpackPlugin({
2626
template: `examples/${name}.html`,
27-
chunksSortMode: 'manual',
2827
filename: `${exampleFilenamePrefix + name}.html`,
2928
chunks: ['commons', name],
3029
})

buildtools/webpack.prod.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
const webpack = require('webpack');
21
const TerserPlugin = require('terser-webpack-plugin');
32

43
module.exports = {
54
mode: 'production',
65
output: {
76
filename: '[name].[chunkhash:20].js'
87
},
9-
plugins: [
10-
new webpack.optimize.ModuleConcatenationPlugin(),
11-
],
128
optimization: {
139
minimizer: [
1410
new TerserPlugin({
1511
terserOptions: {
12+
sourceMap: true,
13+
ecma: 5,
1614
compress: {
17-
drop_console: true
15+
drop_console: true,
16+
drop_debugger: true,
1817
}
1918
},
20-
cache: true,
2119
parallel: true,
22-
sourceMap: true,
2320
})
2421
]
2522
}

examples/lazy.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
</head>
1010
<body>
1111
<div>Delay downloading the Cesium script and initializing the 3D globe.</div>
12-
<div>This is an experimental feature.</div>
1312
<div id="map" style="width:600px;height:400px;"></div>
1413
<input type="button" value="Enable/disable 3D" onclick="javascript:manager.toggle3d()" />
1514
<script>LAZY_CESIUM = true</script>

examples/oldfashioned.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<html>
22
<head>
33
<meta charset="UTF-8">
4-
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v6.0.1/css/ol.css" integrity="sha384-HXAuTFMQWNDZ/4IG/MfVsEkypK3j3m+YAkkiTtRL8t9eQ7r/8SVUUQBndfB07tc3" crossorigin="anonymous" type="text/css">
4+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/css/ol.css" crossorigin="anonymous" type="text/css">
55
<link rel="stylesheet" href="../olcs.css" type="text/css">
66
<style>
77
#map { height: 300px; width: 500px }
88
</style>
9-
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v6.0.1/build/ol.js" integrity="sha384-UCAz1oyIBXM+bvGDRT5xTIbyMXZH6HZPNcnmcx3G4t7GK8oH7NyHUazlQiihaPOl" crossorigin="anonymous"></script>
9+
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/build/ol.js" crossorigin="anonymous"></script>
1010
<script src="../olcesium.js"></script>
11-
<script src="https://cesiumjs.org/releases/1.62/Build/CesiumUnminified/Cesium.js" integrity="sha384-xdu1zCj18Cxd087NG9y3HKgg8M4sni94AL0zjbuV2Hpi6E955z4Wq24aKNr4fBcJ" crossorigin="anonymous"></script>
11+
<!-- In production you should use the minified Cesium for better performances -->
12+
<script src="https://cdn.jsdelivr.net/npm/cesium@1.81.0/Build/CesiumUnminified/Cesium.js" crossorigin="anonymous"></script>
1213
</head>
1314
<body>
1415
<p>Old-fashioned example</p>
@@ -28,12 +29,12 @@
2829
zoom: 3
2930
})
3031
});
31-
32+
3233
var ol3d = new olcs.OLCesium({
3334
map: ol2d,
3435
});
3536
ol3d.setEnabled(true);
36-
37+
3738
var setEnabled = function() {ol3d.setEnabled(!ol3d.getEnabled())};
3839
document.getElementById('enable').addEventListener('click', setEnabled);
3940
</script>

jsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"baseUrl": ".",
5+
"paths": {
6+
"cesium/*": ["./node_modules/@camptocamp/cesium/Source/*"]
7+
},
8+
"target": "es6"
9+
},
10+
"include": [
11+
"src/**/*",
12+
"./node_modules/@camptocamp/cesium/Source/**/*"
13+
"./node_modules/ol/**/*"
14+
]
15+
}

package.json

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "ol-cesium",
3-
"version": "2.12.1",
3+
"version": "2.13.0",
44
"description": "OpenLayers Cesium integration library",
55
"scripts": {
66
"build-examples": "cross-env NODE_ENV=production TARGET=examples webpack --progress --bail",
77
"build-library": "cross-env NODE_ENV=production TARGET=library webpack --progress --bail",
88
"build-library-debug": "cross-env NODE_ENV=development TARGET=library webpack --progress --bail",
99
"build-umd": "cross-env NODE_ENV=production TARGET=umd webpack --progress --bail",
10-
"start": "cross-env DEV_SERVER=1 NODE_ENV=development TARGET=examples webpack-dev-server --port 3000 --progress --watch --bail --debug",
10+
"start": "cross-env DEV_SERVER=1 NODE_ENV=development TARGET=examples webpack serve --port 3000 --progress --bail",
1111
"typecheck": "tsc --pretty",
1212
"doc": "typedoc --name ol-cesium --excludeExternals --out dist/apidoc --entryPoints src/index.library.js --tsconfig ./tsconfig.json"
1313
},
@@ -26,30 +26,31 @@
2626
"cesium": ">= 1.62.0"
2727
},
2828
"devDependencies": {
29-
"@babel/core": "7.12.10",
30-
"@babel/preset-env": "7.12.11",
31-
"@mapbox/geojsonhint": "3.0.0",
29+
"@babel/core": "^7.14.3",
30+
"@babel/preset-env": "^7.14.2",
31+
"@mapbox/geojsonhint": "^3.0.1",
32+
"@types/webpack": "^5.28.0",
3233
"babel-loader": "8.2.2",
33-
"cesium": "1.77.0",
34-
"copy-webpack-plugin": "6.2.1",
34+
"cesium": "^1.81.0",
35+
"copy-webpack-plugin": "^8.1.1",
3536
"cross-env": "7.0.3",
36-
"eslint": "7.18.0",
37+
"eslint": "^7.26.0",
3738
"eslint-config-openlayers": "12.0.0",
38-
"eslint-import-resolver-webpack": "0.13.0",
39+
"eslint-import-resolver-webpack": "^0.13.1",
3940
"fast-glob": "3.2.5",
40-
"fs-extra": "9.0.1",
41-
"html-loader": "1.3.2",
42-
"html-webpack-plugin": "4.5.1",
43-
"htmlparser2": "6.0.0",
44-
"jsdoc": "3.6.6",
41+
"fs-extra": "^10.0.0",
42+
"html-loader": "^2.1.2",
43+
"html-webpack-plugin": "^5.3.1",
44+
"htmlparser2": "^6.1.0",
45+
"jsdoc": "^3.6.7",
4546
"nomnom": "1.8.1",
4647
"ol": "6.5.0",
47-
"proj4": "2.7.0",
48+
"proj4": "^2.7.2",
4849
"temp": "0.9.4",
49-
"typedoc": "0.20.16",
50-
"typescript": "4.1.3",
51-
"webpack": "4.44.2",
52-
"webpack-cli": "3.3.12",
50+
"typedoc": "^0.20.36",
51+
"typescript": "^4.2.4",
52+
"webpack": "^5.37.1",
53+
"webpack-cli": "^4.7.0",
5354
"webpack-dev-server": "3.11.2",
5455
"webpack-merge": "5.7.3"
5556
}

src/olcs/MVTImageryProvider.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {toContext} from 'ol/render.js';
55
import {get as getProjection} from 'ol/proj.js';
66
import {VERSION as OL_VERSION} from 'ol/util.js';
77
import LRUCache from 'ol/structs/LRUCache.js';
8+
import {getForProjection as getTilegridForProjection} from 'ol/tilegrid.js';
9+
import {createFromTemplates as createTileUrlFunctions} from 'ol/tileurlfunction.js';
810

911

1012
const format = new MVT();
@@ -40,6 +42,9 @@ export default class MVTImageryProvider {
4042
this.tileCache = new LRUCache(cacheSize);
4143
this.featureCache = options.featureCache || new LRUCache(cacheSize);
4244
// to avoid too frequent cache grooming we allow x2 capacity
45+
46+
const tileGrid = getTilegridForProjection(this.projection_);
47+
this.tileFunction_ = createTileUrlFunctions(this.urls, tileGrid);
4348
}
4449

4550
getTileCredits() {
@@ -103,7 +108,7 @@ export default class MVTImageryProvider {
103108
}
104109

105110
getUrl_(z, x, y) {
106-
const url = this.urls[0].replace('{x}', x).replace('{y}', y).replace('{z}', z);
111+
const url = this.tileFunction_([z, x, y]);
107112
return url;
108113
}
109114

src/olcs/SynchronizedOverlay.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ class SynchronizedOverlay extends olOverlay {
184184
handleElementChanged() {
185185
function cloneNode(node, parent) {
186186
const clone = node.cloneNode();
187+
if (node.nodeName === 'CANVAS') {
188+
const ctx = clone.getContext('2d');
189+
ctx.drawImage(node, 0, 0);
190+
}
187191
if (parent) {
188192
parent.appendChild(clone);
189193
}

0 commit comments

Comments
 (0)