issue with ionic/angular leaflet directive - inability to use zoom in/out buttons

Encountering issues with the default zoom in/out buttons on a leaflet map. They work fine when the page is loaded directly, but do not function when switching states to one where the leaflet directive is present. Here is an example:

http://codepen.io/anon/pen/JkyEg?editors=101

The code:

HTML

<html ng-app="app">
    <head>
        <meta charset="utf-8"/>
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"/>
        <link href="http://code.ionicframework.com/1.0.0-beta.11/css/ionic.min.css" rel="stylesheet"/>
        <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
        <title>Leaflet example</title> 
    </head>
    <body>
        <ion-nav-view></ion-nav-view>

        <script type="text/ng-template" id="locations.html">
          <ion-view title="Locations">
            <ion-content>
                <ion-list can-swipe="true">
                    <ion-item ng-click="locationOnClick(location)" class="item item-icon-left" ng-repeat="location in locations">
                        <i class="icon ion-location"></i>
                        <h2>{{location.name}}</h2>
                    </ion-item>
                </ion-list>
            </ion-content>
          </ion-view>
        </script>
        <script type="text/ng-template" id="location.html">
          <ion-view title="{{location.name}}">
            <ion-nav-bar class="bar-positive" animation="nav-title-slide-ios7">
                <a ui-sref="locations" class="button icon-left ion-chevron-left button-clear ">Locations</a>
            </ion-nav-bar>
            <ion-content>
                <leaflet height="480px"></leaflet>
            </ion-content>
        </ion-view>
        </script>
        <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
        <script src="http://code.ionicframework.com/1.0.0-beta.11/js/ionic.bundle.min.js"></script>
      <script src="http://tombatossals.github.io/angular-leaflet-directive/dist/angular-leaflet-directive.min.js"></script>
    </body>                                                                
</html>    

JS

angular.module('app', [
  'ionic',
  'leaflet-directive'
])
  .config(function($stateProvider, $urlRouterProvider) {
      $stateProvider
          .state('locations', {
              url: "/locations",
              templateUrl:"locations.html",
              controller: 'LocationsCtrl'
          })
          .state('location', {
              url: "/location/:locationId",
              templateUrl: "location.html",
              controller: 'LocationCtrl'
          });


      // if none of the above states are matched, use this as the fallback
      $urlRouterProvider.otherwise('/locations');

  })
.factory('locationService', function(){
  var _locations = [{
        id: 1,
        name: 'Sample location',
        lat: 50,
        lng: 50
      }];
  return {
    getAll: function(){
      return _locations;
    },
    getById: function(id){
      return _locations.filter(function(loc){ return loc.id === id; })[0];
    }
  }
})
.controller('LocationsCtrl', function($scope, $location, locationService){
  $scope.locations = locationService.getAll();

  $scope.locationOnClick = function(location){
    $location.path('/location/'+location.id);
  };
})
.controller('LocationCtrl', function($scope, $stateParams, locationService){
  $scope.location = locationService.getById($stateParams.locationId);
})

Answer №1

The resolution turned out to be quite straightforward. It was discovered that Ionic was intercepting all non-framework click events. To address this issue with the leaflet map container, it was necessary to include the attribute data-tap-disabled="true"

<ion-content data-tap-disabled="true">
    <leaflet height="480px"></leaflet>
</ion-content>

Answer №2

It appears that there is a bug in the touch events handler of Ionic. Fortunately, one of my coworkers has devised a temporary solution until it is resolved.

In essence, you can use his customized version of ionic.bundle.js () and include 'data-do-not-set-coordinates="true"' to any tag that links to the map.

http://codepen.io/anon/pen/sHpoy?editors=101

 <h2 data-do-not-set-coordinates="true">{{location.name}}</h2>

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

Tips for iterating through nested objects with a for loop

Struggling with validations in an Angular 5 application? If you have a form with name, email, gender, and address grouped under city, state, country using FormGroupname, you might find this code snippet helpful: export class RegistrationComponent implemen ...

"Optimizing Pagination in AngularJS: A Guide to Fixing

Can someone please help me with the code below? I am having an issue where my page 1 is not displaying any data and it only starts showing data from page 2. I've been trying to solve this for the past 3 hours with no success. I am new to angularjs and ...

Ionic applications utilize nested views that load within one another

Take a look at my Plunker example to see the code snippet below in action. .state('tabs', { url: "/tab", abstract: true, cache: false, templateUrl: "tabs.html" // controller: &a ...

Error retrieving individual user information from the list via REST API

routes user.js view layout.ejs user.ejs users.ejs app.js REST API - "" I am facing an issue with two GET requests. In users.ejs, I am rendering three dynamic buttons with specific href values. In user.ejs, I am rendering a single user. ...

Capturing the row selected within a table using AngularJS

Displayed below is an HTML Code that includes a table which retrieves items from costList and presents them in separate rows. The objective is to exhibit the item value when a row is clicked. How can this be achieved using Angular? Your help is greatly a ...

Trigger the React useEffect only when the inputed string matches the previous one

Currently, I am in the process of creating my own custom useFetch hook. export const useFetch = <T extends unknown>( url: string, options?: RequestInit ) => { const [loading, setLoading] = useState(false); const [error, setError] = ...

"Discover the method for tallying the quantity of radio buttons based on their names within AngularJS

Can anyone guide me on how to determine the number of radio buttons by name in AngularJS using a directive? <label ng-repeat="elements in [1,2,3,4,5,6,7]"> <input type="radio" name="phone" ng-model="phone" value="example"> </label& ...

An issue with the Babel version is preventing the Express API from starting up successfully

Error! Message: [nodemon] starting `babel-node index.js` C:\Users\Zara Gunner\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-ma ...

Is there a way to establish a connection with a secondary Firestore database in Node.js, allowing for the use of multiple Firestore databases

I have set up multiple firestore databases within my project. Using the command line, I created these databases and can view them in the Firestore Databases preview by following the instructions outlined here: https://cloud.google.com/blog/products/databas ...

Different approach for binding in Vue.js

Seeking Alternatives I am curious to find out if Vue.js offers a different approach for outputting data beyond the conventional curly braces. Is there a syntax similar to Angular's ng-bind directive that I could utilize? Although Vue.js primarily ut ...

The OrbitControls fail to function even after being imported, referenced, and no errors appearing in the inspector

Issue I am facing a challenge while working on a ThreeJS scene where I am trying to incorporate OrbitControls for proper navigation. Despite having all my objects, including gridHelpers, displaying correctly on the page, the OrbitControls functionality se ...

"Encountering a delay in the passport authentication callback process

After multiple attempts to solve this issue independently, I have turned to the Stack Overflow community in search of guidance. I am implementing user authentication using passport. It has already been initialized in my main express.js file following the ...

execute a function following a change in window size

I have multiple functions running on $(window).resize(). One of the functions involves a complex animation that uses many div elements. $window.resize(function() { // some functions doAnim(); } The issue I am encountering is that the resize() fun ...

The function .css() in jQuery is malfunctioning

This task should be a piece of cake... All I want is to hide the buttons when a user is logged in and display the log out button instead. jQuery().ready(function($) { if ($("body").hasClass("logged-in")) { $(".logged-out-button").css("display", " ...

Exploring the functionality of inline easing when using the ScrollTo plug-in

Attempting to utilize the ScrollTo plug-in with an easing effect. I prefer not to include the easing plug-in file, as I will only use it once and for a single easing effect. The specific 'easeOutBack' function I aim to implement is: easeOutBac ...

Changing the map behavior when it is moved in Leaflet

I am currently using Leaflet to design a map that includes a personalized sound layer. Each tile on the map features an <audio> element, and I am exploring methods to adjust the audio playback as the user navigates around the map (specifically by mod ...

In JavaScript, generate a new column when the text exceeds the height of a div

Is it possible to create a multicolumn layout in HTML that flows from left to right, rather than top to bottom? I am looking to define the height and width of each text column div, so that when the text overflows the box, a new column is automatically ge ...

Exciting Update: Next.js V13 revalidate not triggering post router.push

Currently using Next.js version 13 for app routing, I've encountered an issue with the revalidate feature not triggering after a router.push call. Within my project, users have the ability to create blog posts on the /blog/create page. Once a post is ...

React does not allow for images to be used as background elements

I am currently working on a web page and I have attempted to use both jpg and png images as backgrounds, but they do not seem to display on the page. import './Entrada.css' const Entrada = () => { return( <div style={{ b ...

Maintain the visibility of the jQuery dropdown menu even when navigating to a different page within the

I am experiencing an issue with my dropdown menu. Whenever I click on a "dropdown link", it opens another page on my website, but the menu closes in the process. I want to ensure that the menu stays open and highlights the clicked "dropdown link" in bold. ...