我发现setAt()
andremoveAt()
方法不适用于地图控件。Google 仅在其代码示例中使用push()
和方法。clear()
此外,display
在隐藏和重新显示控件后,该属性可能会导致控件相互叠加。我发现该visibility
物业效果最好。在具有谷歌地图样式的自定义控件构造函数和显示/隐藏控件的方法下方。
function CustomControl(options) { // constructor
"use strict";
this.div = document.createElement('div');
this.div.style.visibility = "visible";
var controlUI = document.createElement('div'); // Set CSS for the control border
controlUI.style.backgroundColor = '#fff';
controlUI.style.backgroundClip = 'padding-box';
controlUI.style.border = '1px solid rgba(0, 0, 0, 0.15)';
controlUI.style.borderRadius = '2px';
controlUI.style.boxShadow = 'rgba(0,0,0,.3) 0px 1px 4px -1px';
controlUI.style.cursor = 'pointer';
controlUI.style.margin = '5px 5px 15px';
controlUI.style.minWidth = '120px';
controlUI.style.textAlign = 'left';
controlUI.style.position = 'relative';
if (options.title) {
controlUI.title = options.title;
}
if (options.visibility) { // "visible" or "hidden"
controlUI.style.visibility = options.visibility;
}
this.div.appendChild(controlUI);
var controlText = document.createElement('div'); //Set CSS for the control interior
controlText.style.color = 'rgb(25,25,25)';
controlText.style.fontFamily = 'Roboto,Arial,sans-serif';
controlText.style.fontSize = '11px';
controlText.style.fontWeight = '500';
controlText.style.padding = '1px 6px';
if (options.text) {
controlText.innerHTML = options.text;
}
controlUI.appendChild(controlText);
if (options.index) {
this.div.index = options.index;
}
if (options.handler) {
google.maps.event.addDomListener(controlUI, 'click', options.handler);
}
if (options.position) {
this.position = options.position;
}
if (options.sequence) {
this.sequence = options.sequence;
}
this.setVisible = function(bolean) { // method
var visibility;
if (bolean) { //true
visibility = "visible";
} else {
visibility = "hidden";
}
controlUI.style.visibility = visibility;
}
}