Ionic 2 struggles to manage a menu overlaying a Google Maps component

I have developed an Ionic V2 side menu application and incorporated a GMaps element into it. However, I am facing issues with handling elements that appear in front of the map. The buttons on the side menu become disabled when they are overlapped by the map, and the same issue occurs with the pop-up of an Ionic select element.

Therefore, my question is: what mistake am I making? Why am I unable to interact with any element that appears in front of the Google map?

The specific area in red that I cannot handle is shown below:

https://i.sstatic.net/IghqT.png https://i.sstatic.net/M9riZ.png

This is the HTML code for my map:

<ion-header>
  <ion-navbar>
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Carte</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <ion-row center>
    <ion-col width-25 center>
      <ion-label>Jours :</ion-label>
    </ion-col>
    <ion-col width-25 center>
      <ion-select [(ngModel)]="gender">
        <ion-option value="f" selected="true">Female</ion-option>
        <ion-option value="m">Male</ion-option>
      </ion-select>
    </ion-col>
    <ion-col width-25 center>
      <ion-label>Horaires :</ion-label>
    </ion-col>
    <ion-col width-25 center>
      <ion-select [(ngModel)]="gender">
        <ion-option value="f" selected="true">Female</ion-option>
        <ion-option value="m">Male</ion-option>
      </ion-select>
    </ion-col>
  </ion-row>
  <div #map id="map" style="height:90%;"></div>
</ion-content>

This is the TypeScript code for my map:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { GoogleMap, GoogleMapsEvent, GoogleMapsLatLng, CameraPosition, GoogleMapsMarkerOptions, GoogleMapsMarker } from 'ionic-native';

@Component({
  selector: 'page-gmap',
  templateUrl: 'gmap.html'
})
export class GMap {

  constructor(public navCtrl: NavController) {}

  ngAfterViewInit() {
   this.loadMap();
  }

  loadMap() {
    let element: HTMLElement = document.getElementById('map');
    let map = new GoogleMap(element);

    // listen to MAP_READY event
    map.one(GoogleMapsEvent.MAP_READY).then(() => console.log('Map is ready!'));
    // create LatLng object
    let ionic: GoogleMapsLatLng = new GoogleMapsLatLng(43.0741904,-89.3809802);
    // create CameraPosition
    let position: CameraPosition = {
      target: ionic,
      zoom: 18,
      tilt: 30
    };
    // move the map's camera to position
    map.moveCamera(position);
    // create new marker
    let markerOptions: GoogleMapsMarkerOptions = {
      position: ionic,
      title: 'Ionic'
    };

    map.addMarker(markerOptions).then((marker: GoogleMapsMarker) => {
      marker.showInfoWindow();
    });
 }
}

Answer №1

Give this a try...

// Fixing the side menu issue...
let sideMenu = this.menuController.get('left');

if (sideMenu) {
  sideMenu.ionOpen.subscribe(() => {
    if (this.map) {
      this.map.setClickable(false);
    }
  });

  sideMenu.ionClose.subscribe(() => {
    if (this.map) {
      this.map.setClickable(true);
    }
  });
}

Answer №2

In order for all elements over the map that need to be clickable, they must be contained within the div where the map is linked.

Your code structure should resemble:

<ion-header>
    <ion-navbar>
        <button ion-button menuToggle>
        <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Carte</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
    <div #map id="map" style="height:90%;">
        <ion-row center>
            <ion-col width-25 center>
                <ion-label>Jours :</ion-label>
            </ion-col>
            <ion-col width-25 center>
                <ion-select [(ngModel)]="gender">
                    <ion-option value="f" selected="true">Female</ion-option>
                    <ion-option value="m">Male</ion-option>
              </ion-select>
            </ion-col>
            <ion-col width-25 center>
                <ion-label>Horaires :</ion-label>
            </ion-col>
            <ion-col width-25 center>
                <ion-select [(ngModel)]="gender">
                    <ion-option value="f" selected="true">Female</ion-option>
                    <ion-option value="m">Male</ion-option>
                </ion-select>
            </ion-col>
        </ion-row>
    </div>
</ion-content>

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

How to create a responsive image that appears over a button when hovering in Bootstrap?

My goal is to display an image over a button when hovering. I've tried adding the .img-responsive class in Bootstrap while including the image in the HTML, but it's not working as expected with my current method of loading images. The buttons the ...

Tips for steering clear of getting caught in the initial focus trap

I have implemented Focus-trap (https://www.npmjs.com/package/focus-trap) in my modal to enhance keyboard accessibility. Here is a snippet of my code: <FocusTrap focusTrapOptions={{onDeactivate: onClose}} > <div> ... </div> <Focu ...

Issue: Anticipated the primary reducer to be a function, but was presented with: 'undefined' in Vanilla JS with Redux

Exploring the world of Redux, I decided to try out some code from a tutorial on YouTube. Building a simple Vanilla JS App, I integrated Redux into it. However, upon running the app in the terminal, an error message popped up saying: "Error: Expected the ro ...

Unable to adjust the padding of the material UI Select component

I'm having trouble adjusting the padding of the Select component in order to align it with the size of my other text fields. Despite knowing that I need to make changes to nested components, I have yet to discover a viable solution. <div className ...

Converting JSON data into a JavaScript array and retrieving the array through an AJAX request from PHP

Currently, I am working on a project where I have created a function named AjaxRequest to manage all my AJAX requests. While making the requests is not an issue, receiving and placing the data back onto the page has proven to be quite challenging. Within ...

Is it necessary to save the details of a specific position in local storage when sliding?

Currently, I am in the process of replicating a webpage design from . I have written the code for the functionality where images and phrases change on every slide. There are three different phrases and images that are being displayed, and my goal is to sto ...

Discover how to set up lazy loaded child routes within a parent route that is also loaded lazily in Angular 2

Struggling to implement lazy loading for my app has been a series of challenges. I successfully implemented lazy loading for the main route, /admin, but now I am facing issues while adding another route, /admin/login. This is what I tried: admin-router.m ...

Use regular expressions to exclude occurrences of the character 'n' from your text

Looking for a regular expression to validate input, specifically filtering out all special characters except "underscore". All characters within the range [a-zA-Z0-9\underscore] are permitted and can appear multiple times. However, my expression shoul ...

Zod vow denial: ZodError consistently delivers an empty array

My goal is to validate data received from the backend following a specific TypeScript structure. export interface Booking { locationId: string; bookingId: number; spotId: string; from: string; to: string; status: "pending" | "con ...

How to showcase the data retrieved via BehaviorSubject in Angular

I've been working on retrieving data from an API using a service and passing it to components using BehaviorSubject in order to display it on the screen: Here is the service code snippet: @Injectable({ providedIn: 'root', }) export clas ...

Declare the variable as a number, yet unexpectedly receive a NaN in the output

I'm facing an issue with a NaN error in my TypeScript code. I've defined a variable type as number and loop through an element to retrieve various balance amounts. These values are in the form of "$..." such as $10.00 and $20.00, so I use a repla ...

discovering a new type of mutation through the use of Vuex

Vue Component computed: { score () { this.$store.commit('fetchCoordinates'); console.log(this.$store.getters.cordinate); } } store.js export default { state: { lat:'ok', }, getters:{ cordinate(state){ r ...

The system displayed an 'Error' stating that the variable 'index' is defined in the code but is never actually utilized, resulting in the (no-unused-vars) warning

I have configured eslint and eslint-plugin-react for my project. Upon running ESLint, I am encountering no-unused-vars errors for every React component in the codebase. It seems like ESLint is not properly identifying JSX or React syntax. Any suggestions ...

Retrieve the complete line of text from both a textarea and an editable div

When I right-click inside a textarea, the entire line regarding the current cursor position is displayed. I am trying to achieve the same with an editable div, but it's not working. The console is empty, showing an empty string. Can someone please hel ...

Displaying content based on changing conditions fetched from the database

We are currently developing a dynamic form system where users can create custom questions in the admin panel and set conditions to display them based on the values of other questions. ng-show="((UserCode==10003 && Name=='Ankur') ||(State ...

Display the image title in a separate div when hovering over it

As a beginner in jQuery, I am working on creating a gallery that displays the title attribute of an image in a separate div when hovering over the image. The title should disappear when the mouse moves away from the image. I hope that explanation is clear! ...

Error: Missing semicolon at line 1005 in Vue computed function. Vetur is indicating this issue

As a beginner in vue3, I am venturing into building some side projects. However, I keep encountering an error message stating ';' expected.Vetur(1005) when attempting to utilize the computed function. Strangely enough, sometimes the same syntax w ...

What is the best way to obtain the current time in a specific city?

Is there a simpler way to display the current time for a specific location without having to deal with factors like daylight savings time? I am searching for a more straightforward solution to always show the time for a particular city, zip code, or any o ...

Pass the PHP data back to my existing webpage for JavaScript to retrieve

I recently set up a form on my WordPress website for users to submit data. Once the form is submitted, I use AJAX to create a new post without having to reload the page. I now need to figure out how to pass the post ID, a simple integer, back to the page s ...

Issue with Zebra_Calendar and JSON compatibility in Internet Explorer 7

I have integrated the Zebra_Calendar jQuery plugin on my website, but encountered an issue when including a JSON implementation. Specifically, I am facing an "Object Doesn't Support This Property or Method" error related to string.split during initial ...