Skip to content

Commit abbb239

Browse files
authored
ROU-12774: Fix TerraDraw dispose crash and TypeScript type errors (#260)
* Fixing the way dispose of the tool is made * Remove extra space * Suppress S7764 rule in sonar cloud This rule is not relevant for our project, as this rule is intended to improve portability, consistency, and testing across different JavaScript environments (browsers, Web Workers, and Node.js). * Use window for better type reference * Fix type of return configs * Fix type for compiler (OS.coordinates) * Bump version of OutSystems Maps * Remove unnecessary code * Lint over the code * Fixing the way removal of a tool is made * Text typo * Invoking stop only if the enabled
1 parent 139d66a commit abbb239

17 files changed

Lines changed: 63 additions & 35 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OutSystems Maps · v2.3.0
1+
# OutSystems Maps · v2.3.1
22

33
![GitHub License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg) ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)
44

gulp/DefaultSpecs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const constants = {
1919

2020
// Store the default project specifications
2121
const specs = {
22-
version: '2.3.0',
22+
version: '2.3.1',
2323
name: 'OutSystems Maps',
2424
description: '',
2525
url: 'Website:\n • ' + constants.websiteUrl,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "outsystems-maps",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"description": "OutSystems Maps",
55
"author": "UI Components Team",
66
"license": "BSD-3-Clause",

sonar-project.properties

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ sonar.sources=src
1515
sonar.exclusions=**/node_modules/**,**/dist/**,**/*.min.js
1616

1717
# JavaScript/TypeScript settings
18-
sonar.javascript.lcov.reportPaths=coverage/lcov.info
18+
sonar.javascript.lcov.reportPaths=coverage/lcov.info
19+
20+
# Suppress S7764 (prefer globalThis over window) project-wide.
21+
# Runtime-injected browser globals are declared via `interface Window` augmentation
22+
# in Global.d.ts — `window.x` is the only access pattern TypeScript resolves correctly.
23+
sonar.issue.ignore.multicriteria=e1
24+
sonar.issue.ignore.multicriteria.e1.ruleKey=typescript:S7764
25+
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.ts

src/OSFramework/Maps/Constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// eslint-disable-next-line @typescript-eslint/no-unused-vars
22
namespace OSFramework.Maps.Constants {
33
/* OutSystems Maps Version */
4-
export const OSMapsVersion = '2.3.0';
4+
export const OSMapsVersion = '2.3.1';
55

66
/**
77
* Maps Set OutSystems platform in use (O11/ODC).

src/Providers/DrawingTools/TerraDraw/Configuration/DrawConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ namespace Provider.DrawingTools.TerraDraw.Configuration {
88
public allowDrag: boolean;
99
public uniqueId: string;
1010

11-
public abstract getProviderConfig(): unknown[];
11+
public abstract getProviderConfig(): unknown;
1212
}
1313
}

src/Providers/DrawingTools/TerraDraw/Configuration/DrawFilledShapeConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Provider.DrawingTools.TerraDraw.Configuration {
1717
* strokeWeight → styles.outlineWidth
1818
* strokeOpacity → styles.outlineOpacity
1919
*/
20-
public getProviderConfig(): unknown[] {
20+
public getProviderConfig(): unknown {
2121
return {
2222
styles: {
2323
fillColor: this.fillColor ?? '#aaaaaa',
@@ -26,7 +26,7 @@ namespace Provider.DrawingTools.TerraDraw.Configuration {
2626
outlineWidth: this.strokeWeight ?? 2,
2727
outlineOpacity: this.strokeOpacity ?? 1,
2828
},
29-
} as unknown as unknown[];
29+
};
3030
}
3131
}
3232
}

src/Providers/DrawingTools/TerraDraw/Configuration/DrawMarkerConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ namespace Provider.DrawingTools.TerraDraw.Configuration {
1414
export class DrawMarkerConfig extends DrawConfig {
1515
public iconUrl: string;
1616

17-
public getProviderConfig(): unknown[] {
17+
public getProviderConfig(): unknown {
1818
return {
1919
styles: {
2020
markerUrl: this.iconUrl ?? '',
2121
},
22-
} as unknown as unknown[];
22+
};
2323
}
2424
}
2525
}

src/Providers/DrawingTools/TerraDraw/Configuration/DrawPolylineConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace Provider.DrawingTools.TerraDraw.Configuration {
1212
* strokeOpacity → styles.lineStringOpacity
1313
*/
1414
export class DrawPolylineConfig extends DrawBasicShapeConfig {
15-
public getProviderConfig(): unknown[] {
15+
public getProviderConfig(): unknown {
1616
return {
1717
styles: {
1818
lineStringColor: this.strokeColor ?? '#555555',
1919
lineStringWidth: this.strokeWeight ?? 2,
2020
lineStringOpacity: this.strokeOpacity ?? 1,
2121
},
22-
} as unknown as unknown[];
22+
};
2323
}
2424
}
2525
}

src/Providers/DrawingTools/TerraDraw/DrawingTools.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Provider.DrawingTools.TerraDraw {
3535

3636
// Always include a select mode so the user can deselect drawing without reloading
3737
modes.push(
38-
new globalThis.terraDraw.TerraDrawSelectMode({
38+
new window.terraDraw.TerraDrawSelectMode({
3939
flags: {
4040
circle: { feature: { draggable: true } },
4141
linestring: {
@@ -67,14 +67,14 @@ namespace Provider.DrawingTools.TerraDraw {
6767
* support hot-swapping modes, so the entire instance must be replaced.
6868
*/
6969
private _buildTerraDraw(): void {
70-
if (this._provider) {
70+
if (this._provider?.enabled) {
7171
this._provider.stop();
7272
}
7373

74-
this._provider = new globalThis.terraDraw.TerraDraw({
74+
this._provider = new window.terraDraw.TerraDraw({
7575
adapter: this._getAdapter(),
7676
modes: this._buildModes(),
77-
}) as TerraDrawProviderCompatible;
77+
});
7878

7979
this._provider.on('finish', (id, context) => this._onFinish(id, context));
8080

@@ -93,7 +93,7 @@ namespace Provider.DrawingTools.TerraDraw {
9393

9494
private _getAdapter(): TerraDrawGoogleMapsAdapter {
9595
if (this.config.providerType === OSFramework.Maps.Enum.ProviderType.Google) {
96-
return new globalThis.terraDrawGoogleMapsAdapter.TerraDrawGoogleMapsAdapter({
96+
return new window.terraDrawGoogleMapsAdapter.TerraDrawGoogleMapsAdapter({
9797
map: this.map.provider as google.maps.Map,
9898
lib: google.maps,
9999
coordinatePrecision: 9,
@@ -196,9 +196,9 @@ namespace Provider.DrawingTools.TerraDraw {
196196
}
197197

198198
public changeProperty(propertyName: string, value: unknown): void {
199-
const propValue = OSFramework.Maps.Enum.OS_Config_DrawingTools[propertyName];
200199
super.changeProperty(propertyName, value);
201200
if (this.isReady) {
201+
const propValue = OSFramework.Maps.Enum.OS_Config_DrawingTools[propertyName];
202202
if (propValue === OSFramework.Maps.Enum.OS_Config_DrawingTools.position) {
203203
const modeNames = this.tools.map((t) => t.type);
204204
this._ui?.refresh(modeNames, value as string);
@@ -208,10 +208,13 @@ namespace Provider.DrawingTools.TerraDraw {
208208

209209
public dispose(): void {
210210
if (this.isReady) {
211-
// Resets the mouse icon to its default state.
212-
// This prevents the tool's custom mouse icon from persisting after the provider is destroyed.
213-
this._provider.setMode(Constants.ModeName.Select);
214-
this._provider.stop();
211+
// If the provider is not enabled, it means that it was never started.
212+
if (this.provider.enabled) {
213+
// Resets the mouse icon to its default state.
214+
// This prevents the tool's custom mouse icon from persisting after the provider is destroyed.
215+
this._provider.setMode(Constants.ModeName.Select);
216+
this._provider.stop();
217+
}
215218
this._ui?.dispose();
216219
}
217220
this._provider = undefined;
@@ -235,10 +238,12 @@ namespace Provider.DrawingTools.TerraDraw {
235238
tool && this._modeToTool.delete(tool.type);
236239

237240
if (this.isReady) {
238-
// Resets the mouse icon to its default state.
239-
// This prevents the tool's custom mouse icon from persisting after the provider is destroyed.
240-
this._provider.setMode(Constants.ModeName.Select);
241-
241+
// If the provider is not enabled, it means that it was never started.
242+
if (this.provider.enabled) {
243+
// Resets the mouse icon to its default state.
244+
// This prevents the tool's custom mouse icon from persisting after the provider is destroyed.
245+
this._provider.setMode(Constants.ModeName.Select);
246+
}
242247
this._buildTerraDraw();
243248

244249
this._provider.start();

0 commit comments

Comments
 (0)