Google Maps API gesture handling not working with AngularJS Material

ε祈祈猫儿з 提交于 2019-12-25 01:26:33

问题


(EDIT: When you use plain Google Maps API with AngularJS Material the problem is the same.)

When I use at the same time in my AngularJS app:

  • NgMap (https://github.com/allenhwkim/angularjs-google-maps)
  • AngularJS Material (https://github.com/angular/material)

Maps don't work properly on mobile (on desktop it is ok) - the problem is with touch gestures. Example:

https://incampo.pl/map2.html - (test on mobile!)

but when I don't use material:

angular.module("incampoApp", ["ngMap"])

instead of:

angular.module("incampoApp", ["ngMap", "ngMaterial"])

it works properly: https://incampo.pl/map.html - (test on mobile!)

My whole example code (JS compiled from typescript):

<!DOCTYPE html>
<html ng-app="incampoApp">
<head>
</head>
<body ng-controller="offerController as vm">

<div map-lazy-load="https://maps.googleapis.com/maps/api/js?key=AIzaSyAyufiB6xUh1SzM7LK2NniXGDPyY__KtP8&callback=initMap">
    <ng-map id="map" min-zoom="2" zoom="6" center="52.2,19"></ng-map>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.4/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.4/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.4/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.4/angular-messages.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.10/angular-material.min.js"></script>
<script src="//rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.min.js"></script>

<script>
    var IncampoApp;
    (function (IncampoApp) {
        var OfferController = (function () {
            function OfferController(ngMap) {

                ngMap.getMap();
            }

            OfferController.$inject = ["NgMap"];

            return OfferController;
        }());
        IncampoApp.OfferController = OfferController;
    })(IncampoApp || (IncampoApp = {}));
</script>

<script>
    var IncampoApp;
    (function (IncampoApp) {
        angular.module("incampoApp", ["ngMap", "ngMaterial"]).controller("offerController", IncampoApp.OfferController);
    })(IncampoApp || (IncampoApp = {}));
</script>
</body>
</html>

Do you have any idea why?


回答1:


I've found the solution here: https://github.com/angular/material/issues/11205

You just need to call $mdGestureProvider.skipClickHijack();

 angular.module('myapp', ['ngMaterial', 'ngMessages'])
  .config(function($mdGestureProvider) {
    // For mobile devices without jQuery loaded, do not
    // intercept click events during the capture phase.
    $mdGestureProvider.skipClickHijack();
  });



回答2:


Try this :

 <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3652.6095451920282!2d90.38946702923724!3d23.72563358206513!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3755b8dd3d3673e7%3A0xf999f4771c24183e!2sInstitute+of+AppropriateTechnology!5e0!3m2!1sen!2sbd!4v1519796378399" width="100%" height="450" frameborder="0" style="border: 0"></iframe>

This solution may help you if want simple map in your html without (Google map key). Embed Google Map with iframe



来源:https://stackoverflow.com/questions/52592964/google-maps-api-gesture-handling-not-working-with-angularjs-material

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!