Skip to content

Commit

Permalink
Add cache support for addModels
Browse files Browse the repository at this point in the history
  • Loading branch information
myshov committed Jun 28, 2023
1 parent 90b5816 commit 8a9c15b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export class Loader extends GLTFLoader {
offsetY = 0,
offsetZ = 0,
} = modelOptions;

const actualModelId = String(modelId);
if (this.models.has(actualModelId)) {
return Promise.resolve();
}

const modelPosition = mapPointFromLngLat(coordinates);
const mapPointsOffsetX = geoToMapDistance(coordinates, offsetX);
const mapPointsOffsetY = geoToMapDistance(coordinates, offsetY);
Expand Down
7 changes: 1 addition & 6 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class GltfPlugin extends Evented<GltfPluginEventTable> {
*
* plugin.addModels([
* {
* id: 1,
* modelId: '03a234cb',
* coordinates: [82.886554, 54.980988],
* modelUrl: 'models/cube_draco.glb',
* rotateX: 90,
Expand Down Expand Up @@ -149,11 +149,6 @@ export class GltfPlugin extends Evented<GltfPluginEventTable> {
public async addModel(modelOptions: ModelOptions) {
await this.waitForPluginInit;

const wasAdded = this.addModelFromCache(modelOptions.modelId);
if (wasAdded) {
return Promise.resolve();
}

return this.loader.loadModel(modelOptions).then(() => {
if (modelOptions.linkedIds) {
this.map.setHiddenObjects(modelOptions.linkedIds);
Expand Down

0 comments on commit 8a9c15b

Please sign in to comment.