Skip to content

Commit d17b6ad

Browse files
ugcwasm 模块重命名解决与wasm 模块加载冲突 review by luox
1 parent 2de4f48 commit d17b6ad

File tree

3 files changed

+72
-70
lines changed

3 files changed

+72
-70
lines changed

src/common/util/GeometryAnalysis.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export class GeometryAnalysis extends Events {
3030
constructor(Module) {
3131
super();
3232
if (Module) {
33-
window.Module = Module;
33+
window.ugcModule = Module;
3434
}
35-
if (!window.Module) {
36-
window.Module = defaultModule;
35+
if (!window.ugcModule) {
36+
window.ugcModule = defaultModule;
3737
}
38-
this.module = window.Module;
38+
this.module = window.ugcModule;
3939
this.addEventType('loaded');
4040
if (this.module.calledRun) {
4141
/**

src/common/util/UGCWasmAll.js

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

src/common/wasm/util.js

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export function geojsonCoordsToPoint2Ds(coords) {
1111
const length = coords.length;
1212
const dim = 2; // coords[0].length
1313
const coordArr = new Float64Array(coords.flat());
14-
const coordPtr = window.Module._malloc(length * dim * 8);
15-
window.Module.HEAPF64.set(coordArr, coordPtr / 8);
16-
const seqPtr = window.Module._UGCWasm_Geometry_CreatePoint2DsFromBuffer(coordPtr, length);
17-
window.Module._free(coordPtr);
14+
const coordPtr = window.ugcModule._malloc(length * dim * 8);
15+
window.ugcModule.HEAPF64.set(coordArr, coordPtr / 8);
16+
const seqPtr = window.ugcModule._UGCWasm_Geometry_CreatePoint2DsFromBuffer(coordPtr, length);
17+
window.ugcModule._free(coordPtr);
1818
return seqPtr;
1919
}
2020

@@ -28,33 +28,33 @@ export function geojsonCoords2UGDoubleArray(coords) {
2828
}
2929
const length = coords.length
3030
const coordArr = new Float64Array(coords)
31-
const coordPtr = window.Module._malloc(length * 8)
32-
window.Module.HEAPF64.set(coordArr, coordPtr / 8)
33-
const pDoubleArray = window.Module._UGCWasm_Helper_CreateDoubleArray(coordPtr, length)
34-
window.Module._free(coordPtr)
31+
const coordPtr = window.ugcModule._malloc(length * 8)
32+
window.ugcModule.HEAPF64.set(coordArr, coordPtr / 8)
33+
const pDoubleArray = window.ugcModule._UGCWasm_Helper_CreateDoubleArray(coordPtr, length)
34+
window.ugcModule._free(coordPtr)
3535

3636
return pDoubleArray
3737
}
3838

3939
export function getJSArrayFromUGDoubleArray(pDoubleArray) {
4040
// get length of doublearray
41-
var length = window.Module._UGCWasm_Helper_GetDoubleArrayLength(pDoubleArray);
41+
var length = window.ugcModule._UGCWasm_Helper_GetDoubleArrayLength(pDoubleArray);
4242

4343
// allocate memory 一个double是8个字节
44-
const pBuffer = window.Module._malloc(length * 8);
44+
const pBuffer = window.ugcModule._malloc(length * 8);
4545

4646
// copy doublearray to buffer
47-
window.Module._UGCWasm_Helper_GetBufferFromDoubleArray(pDoubleArray, pBuffer);
47+
window.ugcModule._UGCWasm_Helper_GetBufferFromDoubleArray(pDoubleArray, pBuffer);
4848

4949
// get double in buffer to Float64Array
50-
const view = new Float64Array(window.Module.HEAPF64.buffer, pBuffer, length);
50+
const view = new Float64Array(window.ugcModule.HEAPF64.buffer, pBuffer, length);
5151
const coords = [];
5252
for (let i = 0; i < length; i++) {
5353
coords.push(view[i]);
5454
}
5555

5656
// free buffer memory
57-
window.Module._free(pBuffer);
57+
window.ugcModule._free(pBuffer);
5858

5959
return coords;
6060
}
@@ -83,13 +83,13 @@ export function ugGeometry2Geojson(pUGGeo) {
8383
if (!pUGGeo) {
8484
return null;
8585
}
86-
const geomType = window.Module._UGCWasm_Geometry_GetType(pUGGeo);
86+
const geomType = window.ugcModule._UGCWasm_Geometry_GetType(pUGGeo);
8787
switch (geomType) {
8888
case 1: {
8989
// UGGeoPoint
9090
const point2d = [];
91-
var x = window.Module._UGCWasm_GeoPoint_GetX(pUGGeo);
92-
var y = window.Module._UGCWasm_GeoPoint_GetY(pUGGeo);
91+
var x = window.ugcModule._UGCWasm_GeoPoint_GetX(pUGGeo);
92+
var y = window.ugcModule._UGCWasm_GeoPoint_GetY(pUGGeo);
9393
point2d.push(x, y)
9494

9595
// create geojson point
@@ -104,23 +104,23 @@ export function ugGeometry2Geojson(pUGGeo) {
104104
// UGGeoLine
105105
const outlines = [];
106106
// get part count
107-
const partCount = window.Module._UGCWasm_GeoLine_GetPartCount(pUGGeo);
107+
const partCount = window.ugcModule._UGCWasm_GeoLine_GetPartCount(pUGGeo);
108108
for (let j = 0; j < partCount; j++) {
109109
// get part j point count
110-
var count = window.Module._UGCWasm_GeoLine_GetPartPointCount(pUGGeo, j);
110+
var count = window.ugcModule._UGCWasm_GeoLine_GetPartPointCount(pUGGeo, j);
111111
// 一个double是8个字节,而一个point2D是两个double,所以需要申请 点个数 * 2 * 8
112-
const pBuffer = window.Module._malloc(count * 2 * 8);
112+
const pBuffer = window.ugcModule._malloc(count * 2 * 8);
113113

114114
// get part j points
115-
window.Module._UGCWasm_GeoLine_GetPart2(pUGGeo, pBuffer, j);
115+
window.ugcModule._UGCWasm_GeoLine_GetPart2(pUGGeo, pBuffer, j);
116116

117117
// Float64Array to line part coordinates
118-
const view = new Float64Array(window.Module.HEAPF64.buffer, pBuffer, count * 2);
118+
const view = new Float64Array(window.ugcModule.HEAPF64.buffer, pBuffer, count * 2);
119119
const coords = [];
120120
for (let i = 0; i < count * 2; i = i + 2) {
121121
coords.push([view[i], view[i + 1]]);
122122
}
123-
window.Module._free(pBuffer);
123+
window.ugcModule._free(pBuffer);
124124

125125
outlines.push(coords);
126126
}
@@ -137,23 +137,23 @@ export function ugGeometry2Geojson(pUGGeo) {
137137
// UGGeoRegion
138138
const outlines = [];
139139
// get part count
140-
const partCount = window.Module._UGCWasm_GeoRegion_GetPartCount(pUGGeo);
140+
const partCount = window.ugcModule._UGCWasm_GeoRegion_GetPartCount(pUGGeo);
141141
for (let j = 0; j < partCount; j++) {
142142
// get part j point count
143-
const count = window.Module._UGCWasm_GeoRegion_GetPartPointCount(pUGGeo, j);
143+
const count = window.ugcModule._UGCWasm_GeoRegion_GetPartPointCount(pUGGeo, j);
144144
// 一个double是8个字节,而一个point2D是两个double,所以需要申请 点个数 * 2 * 8
145-
const pBuffer = window.Module._malloc(count * 2 * 8);
145+
const pBuffer = window.ugcModule._malloc(count * 2 * 8);
146146

147147
// get part j points
148-
window.Module._UGCWasm_GeoRegion_GetPart2(pUGGeo, pBuffer, j);
148+
window.ugcModule._UGCWasm_GeoRegion_GetPart2(pUGGeo, pBuffer, j);
149149

150150
// Float64Array to line part coordinates
151-
const view = new Float64Array(window.Module.HEAPF64.buffer, pBuffer, count * 2);
151+
const view = new Float64Array(window.ugcModule.HEAPF64.buffer, pBuffer, count * 2);
152152
const coords = [];
153153
for (let i = 0; i < count * 2; i = i + 2) {
154154
coords.push([view[i], view[i + 1]]);
155155
}
156-
window.Module._free(pBuffer);
156+
window.ugcModule._free(pBuffer);
157157

158158
outlines.push(coords);
159159
}
@@ -202,49 +202,49 @@ export function geojson2UGGeometry(geojson) {
202202
// geojson.geometries.forEach((feature) => {
203203
// geoms.push(geojsonToGeosGeom(feature, geos))
204204
// })
205-
// const geomsPtr = geos.window.Module._malloc(geoms.length * 4)
205+
// const geomsPtr = geos.window.ugcModule._malloc(geoms.length * 4)
206206
// const geomsArr = new Uint32Array(geoms)
207-
// geos.window.Module.HEAPU32.set(geomsArr, geomsPtr / 4)
207+
// geos.window.ugcModule.HEAPU32.set(geomsArr, geomsPtr / 4)
208208
// const multiGeomsPtr = geos.GEOSGeom_createCollection(
209209
// 7, // geos.GEOS_GEOMETRYCOLLECTION
210210
// geomsPtr,
211211
// geoms.length
212212
// )
213-
// geos.window.Module._free(geomsPtr)
213+
// geos.window.ugcModule._free(geomsPtr)
214214
// return multiGeomsPtr
215215
// }
216216
case 'Point':
217217
if (geojson.coordinates.length === 0) {
218-
return window.Module._UGCWasm_GeoPoint_New()
218+
return window.ugcModule._UGCWasm_GeoPoint_New()
219219
} else {
220-
return window.Module._UGCWasm_GeoPoint_New2(
220+
return window.ugcModule._UGCWasm_GeoPoint_New2(
221221
geojson.coordinates[0],
222222
geojson.coordinates[1]
223223
)
224224
}
225225
case 'LineString':
226226
if (geojson.coordinates.length === 0) {
227-
return window.Module._UGCWasm_GeoLine_New()
227+
return window.ugcModule._UGCWasm_GeoLine_New()
228228
} else {
229-
const pGeoLine = window.Module._UGCWasm_GeoLine_New()
229+
const pGeoLine = window.ugcModule._UGCWasm_GeoLine_New()
230230
const pPoint2Ds = geojsonCoordsToPoint2Ds(geojson.coordinates)
231-
window.Module._UGCWasm_GeoLine_AddPart2(pGeoLine, pPoint2Ds, geojson.coordinates.length)
231+
window.ugcModule._UGCWasm_GeoLine_AddPart2(pGeoLine, pPoint2Ds, geojson.coordinates.length)
232232

233233
return pGeoLine
234234
}
235235
case 'Polygon':
236236
if (geojson.coordinates.length === 0) {
237-
return window.Module._UGCWasm_GeoRegion_New()
237+
return window.ugcModule._UGCWasm_GeoRegion_New()
238238
} else {
239-
const pGeoRegion = window.Module._UGCWasm_GeoRegion_New()
239+
const pGeoRegion = window.ugcModule._UGCWasm_GeoRegion_New()
240240

241241
const pPoint2Ds0 = geojsonCoordsToPoint2Ds(geojson.coordinates[0])
242-
window.Module._UGCWasm_GeoRegion_AddPart2(pGeoRegion, pPoint2Ds0, geojson.coordinates[0].length)
242+
window.ugcModule._UGCWasm_GeoRegion_AddPart2(pGeoRegion, pPoint2Ds0, geojson.coordinates[0].length)
243243

244244
if (geojson.coordinates.length > 1) {
245245
for (let i = 1; i < geojson.coordinates.length; i++) {
246246
const pPoint2Dsi = geojsonCoordsToPoint2Ds(geojson.coordinates[i])
247-
window.Module._UGCWasm_GeoRegion_AddPart2(pGeoRegion, pPoint2Dsi, geojson.coordinates[i].length)
247+
window.ugcModule._UGCWasm_GeoRegion_AddPart2(pGeoRegion, pPoint2Dsi, geojson.coordinates[i].length)
248248
}
249249
}
250250

@@ -263,30 +263,30 @@ export function geojson2UGGeometry(geojson) {
263263
// )
264264
// )
265265
// }
266-
// const pointsPtr = geos.window.Module._malloc(points.length * 4)
266+
// const pointsPtr = geos.window.ugcModule._malloc(points.length * 4)
267267
// const pointsArr = new Uint32Array(points)
268-
// geos.window.Module.HEAPU32.set(pointsArr, pointsPtr / 4)
268+
// geos.window.ugcModule.HEAPU32.set(pointsArr, pointsPtr / 4)
269269
// const multiPointPtr = geos.GEOSGeom_createCollection(
270270
// 4, // geos.GEOS_MULTIPOINT
271271
// pointsPtr,
272272
// points.length
273273
// )
274-
// geos.window.Module._free(pointsPtr)
274+
// geos.window.ugcModule._free(pointsPtr)
275275
// return multiPointPtr
276276
// }
277277
case 'MultiLineString':
278278
if (geojson.coordinates.length === 0) {
279-
return window.Module._UGCWasm_GeoLine_New()
279+
return window.ugcModule._UGCWasm_GeoLine_New()
280280
} else {
281-
const pGeoLine = window.Module._UGCWasm_GeoLine_New()
281+
const pGeoLine = window.ugcModule._UGCWasm_GeoLine_New()
282282

283283
const pPoint2Ds0 = geojsonCoordsToPoint2Ds(geojson.coordinates[0])
284-
window.Module._UGCWasm_GeoLine_AddPart2(pGeoLine, pPoint2Ds0, geojson.coordinates[0].length)
284+
window.ugcModule._UGCWasm_GeoLine_AddPart2(pGeoLine, pPoint2Ds0, geojson.coordinates[0].length)
285285

286286
if (geojson.coordinates.length > 1) {
287287
for (let i = 1; i < geojson.coordinates.length; i++) {
288288
const pPoint2Dsi = geojsonCoordsToPoint2Ds(geojson.coordinates[i])
289-
window.Module._UGCWasm_GeoLine_AddPart2(pGeoLine, pPoint2Dsi, geojson.coordinates[i].length)
289+
window.ugcModule._UGCWasm_GeoLine_AddPart2(pGeoLine, pPoint2Dsi, geojson.coordinates[i].length)
290290
}
291291
}
292292

@@ -314,28 +314,28 @@ export function geojson2UGGeometry(geojson) {
314314
// let holesPtr = null
315315
// if (holes.length > 0) {
316316
// const holesArr = new Uint32Array(holes)
317-
// holesPtr = geos.window.Module._malloc(holes.length * 4)
318-
// geos.window.Module.HEAPU32.set(holesArr, holesPtr / 4)
317+
// holesPtr = geos.window.ugcModule._malloc(holes.length * 4)
318+
// geos.window.ugcModule.HEAPU32.set(holesArr, holesPtr / 4)
319319
// }
320320
// const polyPtr = geos.GEOSGeom_createPolygon(
321321
// shell,
322322
// holesPtr,
323323
// holes.length
324324
// )
325325
// if (holes.length > 0) {
326-
// geos.window.Module._free(holesPtr)
326+
// geos.window.ugcModule._free(holesPtr)
327327
// }
328328
// polygons.push(polyPtr)
329329
// }
330-
// const polygonsPtr = geos.window.Module._malloc(polygons.length * 4)
330+
// const polygonsPtr = geos.window.ugcModule._malloc(polygons.length * 4)
331331
// const polygonsArr = new Uint32Array(polygons)
332-
// geos.window.Module.HEAPU32.set(polygonsArr, polygonsPtr / 4)
332+
// geos.window.ugcModule.HEAPU32.set(polygonsArr, polygonsPtr / 4)
333333
// const multiPolyPtr = geos.GEOSGeom_createCollection(
334334
// 6, // geos.GEOS_MULTIPOLYGON
335335
// polygonsPtr,
336336
// polygons.length
337337
// )
338-
// geos.window.Module._free(polygonsPtr)
338+
// geos.window.ugcModule._free(polygonsPtr)
339339
// return multiPolyPtr
340340
// }
341341
default:

0 commit comments

Comments
 (0)