简体   繁体   English

AngularJs传单指令图在带有离子的手机上无法正确呈现

[英]AngularJs leaflet directive map not rendering correctly on mobile with ionic

I recently started to give Ionic a go and I use Angular Leaflet Directive . 我最近开始放手Ionic,并使用Angular Leaflet Directive for the geolocation to display 显示的地理位置

All is okay, but I have a problem what I am not able to resolve. 一切都很好,但是我有一个我无法解决的问题。

Everything is working on pc. 一切都在PC上运行。

But on mobile the paths are not showing up, and the map is gray 但在移动设备上,路径未显示,地图为灰色

在此处输入图片说明

My Cotroller 我的主编

.controller('ShowCtrl', function($scope, $stateParams, $ionicLoading, $timeout, $http, leafletData) {

  $ionicLoading.show({template: 'Downloading...'});

  $scope.center = {};
  $scope.paths = {};
  $scope.markers = {};
  $scope.defaults = {};
  $scope.map = {};

    $http({
    method: 'GET',
    url: 'https://api.foursquare.com/v2/venues/'+$stateParams.id,
     params: {
          'client_id'     : 'xxx',
          'client_secret' : 'xxx',
          'v'             : '20130815',
        }
  }).then(function successCallback(data) {
      $timeout(function () {

         $scope.place = data.data.response.venue;
         $scope.title = data.data.response.venue.name;

            angular.extend($scope, {
                center: {
                    lat: $scope.lat,
                    lng:  $scope.long,
                    zoom: 12
                },
                paths: {
                    p1: {
                        color: '#ff612f',
                        weight: 5,
                        latlngs: [
                            { lat: data.data.response.venue.location.lat, lng: data.data.response.venue.location.lng },
                            { lat: $scope.lat, lng: $scope.long }
                        ],
                    }
                },
                markers: {
                    destination: {
                        lat: data.data.response.venue.location.lat,
                        lng: data.data.response.venue.location.lng,
                        message: data.data.response.venue.name,
                        focus: true,
                        draggable: false,
                        icon: {
                            iconUrl: 'lib/leaflet/dist/images/marker-icon2.png',
                        }
                    },
                    mylocation: {
                        lat: $scope.lat,
                        lng:  $scope.long,
                        icon: {
                            iconUrl: 'lib/leaflet/dist/images/marker-icon.png',
                        }
                    }
                },
                defaults: {
                    scrollWheelZoom: false,
                    zoomControl:false 
                }
            });
          $ionicLoading.hide();
     }, 2000);
    });
});

Map 地图

<leaflet id="map" center="center" paths="paths"  markers="markers" defaults="defaults"></leaflet>

Could please someone give me a hand? 可以请人帮我吗?

Which Cordova version are you using? 您正在使用哪个Cordova版本?

A recent version now forces the use of cordova-plugin-whitelist . 现在,最新版本强制使用cordova-plugin-whitelist Because of this, you have to allow each and every HTTP request you make. 因此,您必须允许您发出的每个HTTP请求。

Leaflet tiles are fetched from the web, so you have to allow them. 传单是从网上获取的,因此您必须允许它们。

The standard & recommended meta for this is: 为此的标准和推荐元是:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *">

Just include this line in the head of your HTML, and it should work better. 只需将这一行添加到HTML的head ,它应该会更好地工作。

Okay the problem was that i had to initialize tileLayer before the ajax call 好的问题是我必须在ajax调用之前初始化tileLayer

like this 像这样

$scope.defaults = { zoomControl: false, layerControl: false, tileLayer: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'};

$http({
    method: 'GET',
    url: 'https://api.foursquare.com/v2/venues/'+$stateParams.id,
     params: {
          'client_id'     : 'xxx',
          'client_secret' : 'xxx',
          'v'             : '20130815',
        }
  }).then(function successCallback(data) {
      $timeout(function () {

         $scope.place = data.data.response.venue;
         $scope.title = data.data.response.venue.name;

            angular.extend($scope, {
                markers: {
                    destination: {
                        lat: data.data.response.venue.location.lat,
                        lng: data.data.response.venue.location.lng,
                        message: data.data.response.venue.name,
                        focus: true,
                        draggable: false,
                        icon: {
                            iconUrl: 'lib/leaflet/dist/images/marker-icon2.png',
                        }
                    },
                    mylocation: {
                        lat: $scope.lat,
                        lng:  $scope.long,
                        icon: {
                            iconUrl: 'lib/leaflet/dist/images/marker-icon.png',
                        }
                    }
                }
            });
          $ionicLoading.hide();
     }, 2000);
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM