Я хочу добиться такого поведения: я открываю карту, и когда я ее перетаскиваю, появляется кнопка «Поиск в этой области».После того, как я нажму кнопку, я хочу, чтобы она исчезла, чтобы пользователь больше не мог искать в той же области.После того, как я перетащу карту, кнопка снова появится.
Это код:
controlMarkerUI = document.createElement('div')
controlText = document.createElement('div')
mapReady(map) {
this.my_map = map
var self = this
google.maps.event.addListener(this.my_map, 'dragend', function () {
self.redo_search_button(self.my_map)
});
}
redo_search_button(map) {
this.controlMarkerUI.style.cursor = 'pointer'
this.controlMarkerUI.style.backgroundColor = '#fff';
this.controlMarkerUI.style.marginTop = '10px'
this.controlMarkerUI.style.border = '2px solid #fff'
this.controlMarkerUI.style.borderRadius = '3px'
this.controlMarkerUI.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)'
this.controlMarkerUI.style.textAlign = 'center'
this.controlMarkerUI.title = 'Click to redo search in this area'
this.controlText.style.color = 'rgb(25,25,25)';
this.controlText.style.fontFamily = 'Roboto,Arial,sans-serif';
this.controlText.style.fontSize = '16px';
this.controlText.style.lineHeight = '38px';
this.controlText.style.paddingLeft = '5px';
this.controlText.style.paddingRight = '5px';
this.controlText.innerHTML = 'Search in this area';
this.controlMarkerUI.appendChild(this.controlText);
map.controls[google.maps.ControlPosition.TOP_CENTER].push(this.controlMarkerUI)
var this_ = this
this.controlMarkerUI.addEventListener('click', function () {
this_.redo_search() // refresh the markers
this_.removeDummy()
});
}
Я попытался вызвать функцию
removeDummy() {
this.controlMarkerUI.parentNode.removeChild(this.controlMarkerUI);
return false;
}
, это сделаеткнопка исчезнет, но также будет перемещать кнопку вправо при каждом перетаскивании карты.