MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / constructor

Method constructor

src/openlayers/overlay/theme/Theme.js:42–131  ·  view source on GitHub ↗
(name, opt_options)

Source from the content-addressed store, hash-verified

40export class Theme extends ImageCanvasSource {
41
42 constructor(name, opt_options) {
43 var options = opt_options ? opt_options : {};
44 super({
45 attributions: options.attributions || "Map Data <span>© SuperMap iServer</span> with <span>© SuperMap iClient</span>",
46 canvasFunction: canvasFunctionInternal_,
47 logo: Util.getOlVersion() === '4' ? options.logo : null,
48 projection: options.projection,
49 ratio: options.ratio,
50 resolutions: options.resolutions,
51 state: options.state
52 });
53 /**
54 * @function Theme.prototype.on
55 * @description 添加专题要素事件监听。支持的事件包括: click、mousedown、mousemove、mouseout、mouseover、mouseup。
56 * @param {string} event - 事件名称。
57 * @param {RequestCallback} callback - 事件回调函数。
58 */
59 this.on = this.onInternal;
60 this.id = options.id ? options.id : CommonUtil.createUniqueID("themeLayer_");
61
62 function canvasFunctionInternal_(extent, resolution, pixelRatio, size, projection) { // eslint-disable-line no-unused-vars
63 var mapWidth = size[0] * pixelRatio;
64 var mapHeight = size[1] * pixelRatio;
65 if (!this.context) {
66 this.context = Util.createCanvasContext2D(mapWidth, mapHeight);
67 }
68 if (!this.features) {
69 return this.context.canvas;
70 }
71 this.pixelRatio = pixelRatio;
72
73 var width = this.map.getSize()[0] * pixelRatio;
74 var height = this.map.getSize()[1] * pixelRatio;
75 this.offset = [(mapWidth - width) / 2 / pixelRatio, (mapHeight - height) / 2 / pixelRatio];
76 if (!this.notFirst) {
77 this.redrawThematicFeatures(extent);
78 this.notFirst = true;
79 }
80 this.div.id = this.id;
81 this.div.className = "themeLayer";
82 this.div.style.width = mapWidth + "px";
83 this.div.style.height = mapHeight + "px";
84 this.map.getViewport().appendChild(this.div);
85 this.renderer.resize();
86 this.map.getViewport().removeChild(this.div);
87 this.themeCanvas = this.renderer.painter.root.getElementsByTagName('canvas')[0];
88 this.themeCanvas.width = mapWidth;
89 this.themeCanvas.height = mapHeight;
90 this.themeCanvas.style.width = mapWidth + "px";
91 this.themeCanvas.style.height = mapHeight + "px";
92 this.themeCanvas.getContext('2d').clearRect(0, 0, mapWidth, mapHeight);
93
94 var highLightContext = this.renderer.painter._layers.hover.ctx;
95 var highlightCanvas = highLightContext.canvas;
96 var copyHighLightContext = Util.createCanvasContext2D(mapWidth, mapHeight);
97 copyHighLightContext.drawImage(highlightCanvas, 0, 0, highlightCanvas.width, highlightCanvas.height, 0, 0, mapWidth, mapHeight);
98
99 this.redrawThematicFeatures(extent);

Callers

nothing calls this directly

Calls 7

setOpacityMethod · 0.95
addTFEventsMethod · 0.95
getSizeMethod · 0.80
createElementMethod · 0.80
removeChildMethod · 0.80
initMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected