Skip to content

Commit b1c576f

Browse files
committed
feat: add Util.warnOnce
1 parent f747e46 commit b1c576f

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

packages/layer-3dtiles/src/layer/renderer/LRUCache.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as maptalks from 'maptalks';
12
/**
23
* from mapbox-gl-js
34
* A [least-recently-used cache](http://en.wikipedia.org/wiki/Cache_algorithms)
@@ -77,13 +78,11 @@ class LRUCache {
7778

7879
shrink() {
7980
if (this.currentSize > this.max) {
80-
let warned = false;
8181
const iterator = this.data.keys();
8282
let item = iterator.next();
8383
while (this.currentSize > this.max && item.value !== undefined) {
84-
if (!warned && this.data.get(item.value).current) {
85-
warned = true;
86-
console.warn(`current maxGPUMemory(${this.max / 1024 / 1024}) for Geo3DTilesLayer is not enough, one or more current tiles will be discarded.`);
84+
if (this.data.get(item.value).current) {
85+
maptalks.Util.warnOnce(`current maxGPUMemory(${this.max / 1024 / 1024}) for Geo3DTilesLayer is not enough, one or more current tiles will be discarded.`);
8786
}
8887
const removedData = this.getAndRemove(item.value);
8988
if (removedData) {

packages/layer-gltf/src/GLTFMarker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ export default class GLTFMarker extends Marker {
646646
const length = vec3.length([max[0] - min[0], max[1] - min[1], max[2] - min[2]]);
647647
const pixelSize = length / map.getGLScale();
648648
if (pixelSize < 20) {
649-
console.warn('Model\'s size on screen is too small, try to increase its symbol.scaleX/Y/Z');
649+
Util.warnOnce('Model\'s size on screen is too small, try to increase its symbol.scaleX/Y/Z');
650650
this.fire('smallonscreen');
651651
}
652652
}

packages/maptalks/src/core/util/common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,11 @@ export function toRadian(d: number) {
153153
export function toDegree(r: number) {
154154
return r / pi;
155155
}
156+
157+
const warned = new Set();
158+
export function warnOnce(message) {
159+
if (!warned.has(message)) {
160+
console.warn(message);
161+
warned.add(message);
162+
}
163+
}

0 commit comments

Comments
 (0)