Skip to content

Commit f3b6376

Browse files
committed
fix GraphicLayer UT;review by qiw
1 parent 159c6d5 commit f3b6376

File tree

6 files changed

+328
-581
lines changed

6 files changed

+328
-581
lines changed

src/common/commontypes/Util.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,33 @@ const DOTS_PER_INCH = 96;
127127
*/
128128

129129
const Util = {
130+
131+
/**
132+
* @function Util.extend
133+
* @description 对象拷贝赋值。
134+
* @param {Object} dest - 目标对象。
135+
* @param {Object} arguments - 待拷贝的对象。
136+
* @returns {Object} 赋值后的目标对象。
137+
*/
138+
assign(dest) {
139+
for (var index = 0; index < Object.getOwnPropertyNames(arguments).length; index++) {
140+
var arg = Object.getOwnPropertyNames(arguments)[index];
141+
if (arg == "caller" || arg == "callee" || arg == "length" || arg == "arguments") {
142+
continue;
143+
}
144+
var obj = arguments[arg];
145+
if (obj) {
146+
for (var j = 0; j < Object.getOwnPropertyNames(obj).length; j++) {
147+
var key = Object.getOwnPropertyNames(obj)[j];
148+
if (arg == "caller" || arg == "callee" || arg == "length" || arg == "arguments") {
149+
continue;
150+
}
151+
dest[key] = obj[key];
152+
}
153+
}
154+
}
155+
return dest;
156+
},
130157
/**
131158
* @memberOf CommonUtil
132159
* @description 复制源对象的所有属性到目标对象上,源对象上的没有定义的属性在目标对象上也不会被设置。

src/common/overlay/graphic/GraphicLayerRenderer.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
export class GraphicLayerRenderer {
3737

3838
constructor(id, options, callbackOptions, mapOptions) {
39-
let opt = CommonUtil.extend(this, defaultProps, options);
39+
let opt = CommonUtil.assign(this, defaultProps, options);
4040
/**
4141
* @member {string} GraphicLayerRenderer.prototype.id
4242
* @description 高效率点图层 ID。
@@ -63,7 +63,7 @@
6363
this.mapOptions.mapContainer.appendChild(this.canvas);
6464
}
6565
this._initContainer();
66-
let mapState = this.callbackOptions.getState();
66+
let mapState = this.getState();
6767
let {
6868
data,
6969
color,
@@ -162,7 +162,7 @@
162162
outline: this.outline
163163
};
164164

165-
CommonUtil.extend(this, styleOpt, styleOptions);
165+
CommonUtil.assign(this, styleOpt, styleOptions);
166166
this.update();
167167
}
168168

@@ -304,7 +304,7 @@
304304
viewportChanged: true,
305305
updateTriggersChanged: true
306306
});
307-
let state = this.callbackOptions.getState();
307+
let state = this.getState();
308308
let width = parseInt(this.canvas.style.width);
309309
let height = parseInt(this.canvas.style.height);
310310
state.width = width;
@@ -327,7 +327,7 @@
327327
* @description 删除该图层。
328328
*/
329329
remove() {
330-
this.CanvasContainer.removeChild(this.canvas);
330+
this.mapOptions.mapContainer.removeChild(this.canvas);
331331
}
332332

333333
/**
@@ -383,7 +383,7 @@
383383
* @description 绘制图层。
384384
*/
385385
draw() {
386-
let mapState = this.callbackOptions.getState();
386+
let mapState = this.getState();
387387
let deckOptions = {};
388388

389389
for (let key in mapState) {
@@ -419,5 +419,22 @@
419419
canvas.style.height = mapCanvas.style.height;
420420
return canvas;
421421
}
422+
423+
getState() {
424+
let mapState = this.callbackOptions.getMapState();
425+
return {
426+
data: this.graphics,
427+
color: this.color,
428+
radius: this.radius,
429+
opacity: this.opacity,
430+
highlightColor: this.highlightColor,
431+
radiusScale: this.radiusScale,
432+
radiusMinPixels: this.radiusMinPixels,
433+
radiusMaxPixels: this.radiusMaxPixels,
434+
strokeWidth: this.strokeWidth,
435+
outline: this.outline,
436+
...mapState
437+
};
438+
}
422439
}
423440

0 commit comments

Comments
 (0)