Skip to content

Commit

Permalink
Merge pull request #4390 from nboisteault/lazy-load-jsts-buffer
Browse files Browse the repository at this point in the history
lazy load jsts buffer
  • Loading branch information
nboisteault authored Apr 29, 2024
2 parents 23c72c9 + 2d41537 commit f766786
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
46 changes: 24 additions & 22 deletions assets/src/modules/SelectionTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -118,29 +115,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) {
Expand Down
5 changes: 3 additions & 2 deletions assets/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit f766786

Please sign in to comment.