Skip to content

Commit fbde177

Browse files
committed
JS: Replace proj4js by proj4rs WASM
Proj4rs is Rust adaptation of Proj4. It provides a JS API like proj4js to be reusable with OpenLayers. * Source code https://github.com/3liz/proj4rs * JavaScript Demo https://docs.3liz.org/proj4rs/
1 parent 53bc9ab commit fbde177

File tree

7 files changed

+26
-24
lines changed

7 files changed

+26
-24
lines changed

assets/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import executeJSFromServer from './modules/ExecuteJSFromServer.js';
3232

3333
import olDep from './dependencies/ol.js';
3434
import litHTMLDep from './dependencies/lit-html.js';
35-
import proj4 from 'proj4';
35+
import {proj4} from 'proj4rs/proj4.js';
3636

3737
lizMap.ol = olDep;
3838
lizMap.litHTML = litHTMLDep;

assets/src/legacy/map.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,9 @@ window.lizMap = function() {
654654
var wmsBbox = firstLayer.bbox[proj.ref].bbox;
655655
var wmsBounds = OpenLayers.Bounds.fromArray( wmsBbox );
656656
var initBounds = OpenLayers.Bounds.fromArray( config.options.initialExtent );
657-
if ( !initBounds.intersectsBounds( wmsBounds ) )
657+
if ( !initBounds.intersectsBounds( wmsBounds ) ) {
658658
OpenLayers.Projection.defaults[proj.ref].yx = true;
659+
}
659660
}
660661
}
661662
}

assets/src/modules/Lizmap.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import WMSCapabilities from 'ol/format/WMSCapabilities.js';
3131
import WFSCapabilities from 'ol-wfs-capabilities';
3232
import { Coordinate as olCoordinate } from 'ol/coordinate.js'
3333
import { Extent as olExtent, intersects as olExtentIntersects} from 'ol/extent.js';
34-
import { transform as olTransform, transformExtent as olTransformExtent, get as getProjection, clearAllProjections, addCommon } from 'ol/proj.js';
34+
import { transform as olTransform, transformExtent as olTransformExtent, get as getProjection } from 'ol/proj.js';
3535
import { register } from 'ol/proj/proj4.js';
3636

37-
import proj4 from 'proj4';
37+
import { proj4 } from 'proj4rs/proj4.js';
3838
import ProxyEvents from './ProxyEvents.js';
3939

4040
/**
@@ -116,30 +116,15 @@ export default class Lizmap {
116116
&& Math.abs(extent[2] - bbox.extent[3]) < Math.abs(extent[2] - bbox.extent[2])
117117
&& Math.abs(extent[3] - bbox.extent[2]) < Math.abs(extent[3] - bbox.extent[3])) {
118118
// If inverted axis are closest, we have to update the projection definition
119-
proj4.defs(configProj.ref, configProj.proj4+' +axis=neu');
120-
// Clear all cached projections and transforms.
121-
clearAllProjections();
122-
// Add transforms to and from EPSG:4326 and EPSG:3857. This function should
123-
// need to be called again after `clearAllProjections()`
124-
// @see ol/proj.js#L731
125-
addCommon();
126-
// Need to register projections again
127-
register(proj4);
119+
projectProj.axisOrientation_ = 'neu';
128120
break;
129121
}
130122
// Transform extent from project projection to CRS:84
131123
const geoExtent = olTransformExtent(bbox.extent, bbox.crs, 'CRS:84');
132124
// Check intersects between transform extent and provided extent by WMS Capapbilities
133125
if (!olExtentIntersects(geoExtent, wmsLayer.EX_GeographicBoundingBox)) {
134126
// if extents do not intersect, we have to update the projection definition
135-
proj4.defs(configProj.ref, configProj.proj4+' +axis=neu');
136-
clearAllProjections();
137-
// Add transforms to and from EPSG:4326 and EPSG:3857. This function should
138-
// need to be called again after `clearAllProjections()`
139-
// @see ol/proj.js#L731
140-
addCommon();
141-
// Need to re register projections again
142-
register(proj4);
127+
projectProj.axisOrientation_ = 'neu';
143128
break;
144129
}
145130
}

assets/webpack.dev.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ import common from './webpack.common.js';
33

44
export default merge(common, {
55
mode: 'development',
6-
devtool: 'eval-source-map'
6+
devtool: 'eval-source-map',
7+
experiments: {
8+
asyncWebAssembly: true,
9+
syncWebAssembly: true
10+
},
711
});

assets/webpack.prod.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ import common from './webpack.common.js';
33

44
export default merge(common, {
55
mode: 'production',
6-
devtool: 'source-map'
6+
devtool: 'source-map',
7+
experiments: {
8+
asyncWebAssembly: true,
9+
syncWebAssembly: true
10+
},
711
});

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"ol-wfs-capabilities": "^2.0.0",
4646
"playwright-ctrf-json-reporter": "^0.0.x",
4747
"postcss-lit": "^1.2.0",
48-
"proj4": "^2.11.0",
48+
"proj4rs": "^0.0.1",
4949
"shpjs": "^6.1.0",
5050
"stylelint": "^16.15.x",
5151
"stylelint-config-standard": "^37.0.0",

0 commit comments

Comments
 (0)