我在谷歌地图的'TOP_CENTER'上有3个自定义控件。起初我只想显示2(“b1”和“searchButton”)。当点击“searchButton”时,我想删除“b1”并添加“searchBox”,而不是像这样
let b1 = document.createElement('div');
let searchBox = document.createElement('div');
let searchButton = document.createElement('div');
...
map.controls[google.maps.ControlPosition.TOP_CENTER].push(b1);
map.controls[google.maps.ControlPosition.TOP_CENTER].push(searchButton);
searchButton.addEventListener('click',()=>{
map.controls[google.maps.ControlPosition.TOP_CENTER].removeAt(0);
map.controls[google.maps.ControlPosition.TOP_CENTER].insertAt(0,searchBox);
});
“searchBox”应该添加到“searchButton”(我想要的)的左侧,但它会添加到“searchButton”的右侧。我怎样才能解决这个问题?