I am trying to implement a specific functionality on my map. When the user drags the map, I want a button named 'Search in this area' to appear. Once the user clicks on the button, it should disappear so that the search can't be performed again in the same area. However, after dragging the map again, the button should reappear.
Below is the code snippet:
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()
});
}
I attempted to create a function like this:
removeDummy() {
this.controlMarkerUI.parentNode.removeChild(this.controlMarkerUI);
return false;
}
This function successfully hides the button but shifts it to the right when the map is dragged, which is not the desired behavior.