Google map with a fully visible HTML element on top

When certain points on a Google map are clicked, a small popup box appears. This works fine in the regular small Google map mode.

However, when the Google map is switched to full screen mode by clicking the full screen button (which is shown when `fullScreenControl` is set to true), the popup no longer shows up on top of the map. Upon inspecting the element, it seems to be at the correct position and size but remains invisible.

I've tried increasing the z-index value for the popup, but still haven't had any luck getting it to display properly.

Is there a way to make this work in full screen mode?

Answer №1

The issue arises when Google Maps goes into fullscreen mode, causing one of its own inner divs to take over the screen. Everything outside of this div becomes invisible, even with z-index settings.

To overcome this obstacle, I devised a two-step solution:

1) To ensure visibility, I moved the custom elements inside the inner div. However, creating the inner div only happens after the google.maps.Map is initialized. Using jQuery, I included the following code right after the map object creation:

var $map = $("#map");
var map = new google.maps.Map(
    $map.get(0),
    {/*map options*/},
);
var $fullscreenDiv = $map.children("div:first");
$("#mybutton1, #mybutton2").appendTo($fullscreenDiv);

2) Despite moving the elements, they still remained hidden without an explicit z-index value. The specific value didn't matter much, so I set it to z-index: 2147483647 for assured visibility.

#mybutton1, #mybutton2 {
    z-index: 2147483647;
}

Answer №2

A method that does not require jQuery. In agreement with sanchopancho13's suggestion, it is necessary to place your customized menu inside the Google Maps DIV after the map has been initialized. The JavaScript "appendChild" function accomplishes this task. If the specified element already exists in the DOM, the JavaScript "appendChild" function moves the element along with all child elements and associated event handlers.

https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild

Therefore, craft your custom menu or panel in standard HTML (including event handlers):

<div id="customPanel">
  <button onclick="action1()">Custom Button 1</button>
  <button onclick="action2()">Custom Button 2</button>
  <button onclick="action3()">Custom Button 3</button>
  <button onclick="action4()">Custom Button 4</button>
</div>

Initialize the map, locate its first DIV element, and insert your DIV within the Google Map DIV:

var map = new google.maps.Map(map, { yourMapOptions });
var mapDiv = document.getElementById('map').getElementsByTagName('div')[0];
mapDiv.appendChild(document.getElementById("customPanel"));

This approach is effective for displaying the map in full-screen mode as well as normal mode. As emphasized earlier, adjusting the Z-index is crucial to ensure visibility of your custom panel:

CSS:

#customPanel {
  z-index: 1;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to retrieve state within a property of a React class component?

I have encountered an issue with a React Class Component where I am trying to separate a part of the rendered JSX but unable to access the Component's state within the separated JSX as a property of the class. The scenario is quite similar to the fol ...

Is it possible to selectively process assets based on their type using Gulp and Useref?

Is it possible to selectively process css and js assets using gulp-useref based on the build type specified in the html tags? <!-- build:<type>(alternate search path) <path> --> ... HTML Markup, list of script / link tags. <!-- endbui ...

How to extract keys with the highest values in a JavaScript hashmap or object

Here is an example for you to consider: inventory = {'Apple':2, 'Orange' :1 , 'Mango' : 2} In this inventory, both Apple and Mango have the maximum quantity. How can I create a function that returns both Apple and Mango as t ...

Trying to update the +/- icon on an accordion dropdown, however, the local HTML file is not loading the JavaScript file. (Using Bootstrap 4)

I'm completely new to JS and struggling a bit, so please be patient. I've been searching online for a few days now without much luck. I'm using Bootstrap 4 and trying to create an accordion with a +/- icon that changes when expanded or colla ...

expanding the div based on the filtered content inside

My current setup involves using jQuery filters to refine the selection of products. All the products are contained within their own individual divs, which are then placed inside a single "large div". When a filter is applied, the divs containing products ...

JavaScript-based tool for extracting content from Sketch file

My goal is to extract the contents of a .sketch file. I have a file named myfile.sketch. When I rename the file extension to myfile.zip and extract it in Finder, I can see the files inside. However, when I try the same process on the server using Node.js ...

What is causing readHTMLTable to encounter difficulties when attempting to parse Premier League standings for the month of May?

The official Premier league website offers a wealth of statistical data for the league's teams over different seasons (such as this one). I utilized the readHTMLTable function from the XML R package to extract these tables. However, I encountered an i ...

The Bootstrap v5 dropdown feature is malfunctioning as the drop-down menu fails to appear

I've been struggling to create a dropdown menu using Bootstrap, but it doesn't seem to be working as expected. Despite that, I have no issues utilizing the framework for styling purposes. The Bootstrap js link is placed at the bottom of the body ...

Processing JSON data from a variable using jQuery without needing to make an AJAX call

Is there a way to make jQuery process a JSON string from a variable without using an AJAX call? The JSON string will be generated from JSON2HTML, but using jQuery.getJSON requires an unnecessary AJAX call, which can waste resources. Does anyone have a solu ...

Unbind a prepared statement in a node.js environment using SQL

Utilizing the node-mssql library (https://github.com/patriksimek/node-mssql) and encountered a problem when attempting to execute a second request, resulting in the following error: this.connection.pool.acquire(done); ^ TypeEr ...

Extracting information from a Weather API and sharing it on Twitter

Can anyone help me troubleshoot my Twitter bot setup for tweeting out city temperatures? I attempted switching to a different API, but nothing seems to be resolving the issue. console.log('initiating twitter bot...') var Twit = require('t ...

Python script for automating captcha scraping

I recently started learning about web scraping and decided to try scraping the website www.mediamarkt.de using Python and BeautifulSoup. However, whenever I make a request to the website using the following commands page = requests.get(url, headers=headers ...

Combining JavaScript functions and Vue.js methods through chaining

When working within a Vue component, I have a scenario where I am invoking a function from a separate JavaScript file. The requirement is to then trigger a method within my component once the first function has finished executing: Here is an example of my ...

The function createReadStream completes execution without resolving

Currently, I am in the process of developing a program that is aimed at iterating through files within a specified directory in a Linux environment. I have implemented a custom function called "myReadFile" which returns a new promise, and it is expected ...

Translation of country codes into the complete names of countries

Currently, my code is utilizing the ipinfo.io library to retrieve the user's country information successfully. This is the snippet of code I am using to fetch the data: $.get("https://ipinfo.io?token=0000000000", function(response) { console.log ...

Updating the legend boxes of a chart in Chart Js to match the style of the graph lines

I need assistance updating the legend boxes of my graphs with graph line style. https://i.sstatic.net/zhi4L.pngActual Consumption https://i.sstatic.net/dAjlp.png Average Use https://i.sstatic.net/YMC7I.png Here is the code snippet I am currently using, ...

Leveraging a spritesheet in conjunction with createPattern()

Looking for guidance on a task I can't find clear information on. I have a large sprite sheet named textures.png, with each texture being 64x64 pixels. My goal is to create patterns out of these textures. The createPattern() function works well but o ...

Inexperienced with Bootstrap/CSS: Cannot open dropdown by clicking (CDN properly installed)

I am having trouble getting my Bootstrap dropdown to toggle correctly, despite placing the JS script last. I have checked multiple resources and it was suggested that CDN may not have been imported correctly. I have also tested this on different browsers w ...

Guide to triggering a popover from within another popover using jQuery

Currently, I have a situation where a popover is triggered by clicking on a button. The goal is to trigger another popover from the first popover by clicking on some content within it. If you'd like to see a demonstration, check out this JSFiddle lin ...

Arrange pictures and div elements in a horizontal layout

I am facing an issue with my code that is displaying 5 'cards' in a messed up layout instead of a straight line. I have tried to align them vertically, but some are still higher and not in the right positions. For reference, I want the layout to ...