From 8a9c15b292cc4b94cd234c6c25bdbfd986b3e8f9 Mon Sep 17 00:00:00 2001 From: Alexander Myshov Date: Wed, 28 Jun 2023 20:28:31 +0700 Subject: [PATCH] Add cache support for addModels --- src/loader.ts | 6 ++++++ src/plugin.ts | 7 +------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/loader.ts b/src/loader.ts index ba6c75b..d7f610f 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -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); diff --git a/src/plugin.ts b/src/plugin.ts index 4da74df..ce95c5d 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -47,7 +47,7 @@ export class GltfPlugin extends Evented { * * plugin.addModels([ * { - * id: 1, + * modelId: '03a234cb', * coordinates: [82.886554, 54.980988], * modelUrl: 'models/cube_draco.glb', * rotateX: 90, @@ -149,11 +149,6 @@ export class GltfPlugin extends Evented { 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);