From 2d41537fbd6988085e1ff72d4b0c759789f15261 Mon Sep 17 00:00:00 2001 From: nboisteault Date: Fri, 26 Apr 2024 17:58:42 +0200 Subject: [PATCH] lazy load jsts buffer --- .gitignore | 7 ++++- .gitlab-ci.yml | 6 ++++ assets/src/modules/SelectionTool.js | 46 +++++++++++++++-------------- assets/webpack.common.js | 5 ++-- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 5d0e417fb2..2ebece469c 100644 --- a/.gitignore +++ b/.gitignore @@ -61,7 +61,12 @@ lizmap/www/assets/js/timemanager.js lizmap/www/assets/js/timemanager.js.map lizmap/www/assets/js/view.js lizmap/www/assets/js/view.js.map - +lizmap/www/assets/js/137.bundle.js +lizmap/www/assets/js/137.bundle.js.map +lizmap/www/assets/js/BufferOp.bundle.js +lizmap/www/assets/js/BufferOp.bundle.js.map +lizmap/www/assets/js/OLparser.bundle.js +lizmap/www/assets/js/OLparser.bundle.js.map # Docs docs/js diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2386e60ad8..d14e159515 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,6 +42,12 @@ build: - lizmap/www/assets/js/timemanager.js.map - lizmap/www/assets/js/view.js - lizmap/www/assets/js/view.js.map + - lizmap/www/assets/js/137.bundle.js + - lizmap/www/assets/js/137.bundle.js.map + - lizmap/www/assets/js/BufferOp.bundle.js + - lizmap/www/assets/js/BufferOp.bundle.js.map + - lizmap/www/assets/js/OLparser.bundle.js + - lizmap/www/assets/js/OLparser.bundle.js.map tags: - fabric diff --git a/assets/src/modules/SelectionTool.js b/assets/src/modules/SelectionTool.js index 8ce56bc6ca..46e42fbb2e 100644 --- a/assets/src/modules/SelectionTool.js +++ b/assets/src/modules/SelectionTool.js @@ -4,10 +4,7 @@ * @copyright 2023 3Liz * @license MPL-2.0 */ -import {mainLizmap, mainEventDispatcher} from '../modules/Globals.js'; - -import BufferOp from 'jsts/org/locationtech/jts/operation/buffer/BufferOp.js'; -import OLparser from 'jsts/org/locationtech/jts/io/OL3Parser.js'; +import { mainLizmap, mainEventDispatcher } from '../modules/Globals.js'; import { LinearRing, @@ -115,29 +112,34 @@ export default class SelectionTool { // Handle buffer if any this._bufferLayer.getSource().clear(); if (this._bufferValue > 0) { - const parser = new OLparser(); - parser.inject( - Point, - LineString, - LinearRing, - Polygon, - MultiPoint, - MultiLineString, - MultiPolygon - ); + Promise.all([ + import(/* webpackChunkName: 'OLparser' */ 'jsts/org/locationtech/jts/io/OL3Parser.js'), + import(/* webpackChunkName: 'BufferOp' */ 'jsts/org/locationtech/jts/operation/buffer/BufferOp.js') + ]).then(([{ default: OLparser }, { default: BufferOp }]) => { + const parser = new OLparser(); + parser.inject( + Point, + LineString, + LinearRing, + Polygon, + MultiPoint, + MultiLineString, + MultiPolygon + ); - // Convert the OpenLayers geometry to a JSTS geometry - const jstsGeom = parser.read(selectionFeature.getGeometry()); + // Convert the OpenLayers geometry to a JSTS geometry + const jstsGeom = parser.read(selectionFeature.getGeometry()); - // Create a buffer - const jstsbBufferedGeom = BufferOp.bufferOp(jstsGeom, this._bufferValue); + // Create a buffer + const jstsbBufferedGeom = BufferOp.bufferOp(jstsGeom, this._bufferValue); - const bufferedFeature = new Feature(); - bufferedFeature.setGeometry(parser.write(jstsbBufferedGeom)); + const bufferedFeature = new Feature(); + bufferedFeature.setGeometry(parser.write(jstsbBufferedGeom)); - this._bufferLayer.getSource().addFeature(bufferedFeature); + this._bufferLayer.getSource().addFeature(bufferedFeature); - selectionFeature = this.featureDrawnBuffered; + selectionFeature = this.featureDrawnBuffered; + }); } for (const featureType of this.allFeatureTypeSelected) { diff --git a/assets/webpack.common.js b/assets/webpack.common.js index 21ef56c063..58e85eca79 100644 --- a/assets/webpack.common.js +++ b/assets/webpack.common.js @@ -17,9 +17,10 @@ export default { 'bottom-dock': './src/legacy/bottom-dock.js', }, output: { - filename: '../../lizmap/www/assets/js/[name].js', + filename: '[name].js', chunkFilename: '[name].bundle.js', - path: resolve(__dirname, 'dist') + publicPath: '/assets/js/', + path: resolve(__dirname, '../lizmap/www/assets/js/') }, module: { rules: [