您可以添加自己的自定义控件并将其用作图例。
此代码将添加一个 150w x 100h 的框(灰色边框/白色背景)和其中的“Hello World”字样。您可以将文本换成图例中想要的任何 HTML。这将保持锚定在地图右上方 (G_ANCHOR_TOP_RIGHT) 10 像素和 50 像素上方。
function MyPane() {}
MyPane.prototype = new GControl;
MyPane.prototype.initialize = function(map) {
var me = this;
me.panel = document.createElement("div");
me.panel.style.width = "150px";
me.panel.style.height = "100px";
me.panel.style.border = "1px solid gray";
me.panel.style.background = "white";
me.panel.innerHTML = "Hello World!";
map.getContainer().appendChild(me.panel);
return me.panel;
};
MyPane.prototype.getDefaultPosition = function() {
return new GControlPosition(
G_ANCHOR_TOP_RIGHT, new GSize(10, 50));
//Should be _ and not _
};
MyPane.prototype.getPanel = function() {
return me.panel;
}
map.addControl(new MyPane());