2016-10-10 123 views
0

我有一個顯示空白頁面的路由/視圖。我很確定它幾天前正在按照我現在的方式工作,這導致我認爲這是我的Google Maps API密鑰的問題,但沒有錯誤或警告,所以我認爲它必須與我的路由設置。但我有另一種看法設立完全相同的方式和一個沒有工作...AngularJS:顯示空白頁面的路由

破碎的看法:http://alainwebdesign.ca/pl2/#/49.2/-122.66

工作的看法:http://alainwebdesign.ca/pl2/#/getLocation

控制器(我註釋掉the.config爲谷歌地圖API,因爲我有我的觀點searchRadius.html腳本參考):

(function (window, ng) { 
    ng.module('app', ['uiGmapgoogle-maps', 'ui.router']) 



    .config(function ($stateProvider) { //had: , $stateChangeError included in the function parameters, but that caused error 
     $stateProvider.state('searchRadius', { 
      url: '/:lat/:lon', 
      templateUrl: 'searchRadius.html', //changed from index to searchRadius.html 
      controller: 'MapsCtrl', 
     }); 
    }) 


    ////ALREADY HAVE GOOGLE MAPS KEY ON searchRadius.html 
    .config(['uiGmapGoogleMapApiProvider', function (GoogleMapApi) { 
     GoogleMapApi.configure({ 
      key: 'AIzaSyC_XEbbw3sNm4XlLAgqMJTggeHLDUdV-pY', 
      v: '3', 
      libraries: 'weather,geometry,visualization' 
     }); 
    } ]) 

.controller('MapsCtrl', ['$scope', "uiGmapLogger", "uiGmapGoogleMapApi", "$interval", "$state", "$stateParams", 
    function ($scope, $log, GoogleMapApi, $interval, $state, $stateParams) { 
     $log.currentLevel = $log.LEVELS.debug; 
     var center = { latitude: parseFloat($stateParams.lat), longitude: parseFloat($stateParams.lon) }; 
     alert(JSON.stringify(center)); 
     Object.freeze(center); //caused TypeError: Cannot assign to read only property ('latitude') ... 

     console.log($stateParams); 

     $scope.map = { 
      center: center, 
      pan: false, 
      zoom: 16, 
      refresh: false, 
      events: {}, 
      bounds: {} 
     }; 

     $scope.map.circle = { 
      id: 1, 
      center: center, 
      radius: 500, //(current time - date lost)*km/hour 
      stroke: { 
       color: '#08B21F', 
       weight: 2, 
       opacity: 1 
      }, 

      fill: { 
       color: '#08B21F', 
       opacity: 0.5 
      }, 
      geodesic: false, // optional: defaults to false 
      draggable: false, // optional: defaults to false 
      clickable: true, // optional: defaults to true 
      editable: false, // optional: defaults to false 
      visible: true, // optional: defaults to true 
      events: { 
       dblclick: function() { 
        $log.debug("circle dblclick"); 
       }, 
       radius_changed: function (gObject) { 
        var radius = gObject.getRadius(); 
        $log.debug("circle radius radius_changed " + radius); 
       } 
      } 
     } 

     //Increase Radius: 
     $interval(function(){ 
      $scope.map.circle.radius += 30; //dynamic var 
     }, 1000); //end of interval function 


    } ]); //end of controller 

})(window, angular); 

searchRadius.html:

<div style="height: 100%"> <!--took out: ng-if="map.center !== undefined"--> 
    <ui-gmap-google-map 
         center='map.center' 
         zoom='map.zoom' 
         draggable='map.draggable' 
         dragging='map.dragging' 
         refresh='map.refresh' 
         options='map.options' 
         events='map.events' 
         pan='map.pan'> 


     <ui-gmap-circle 
         center='map.circle.center' 
         radius='map.circle.radius' 
         fill='map.circle.fill' 
         stroke='map.circle.stroke' 
         clickable='map.circle.clickable' 
         draggable='map.circle.draggable' 
         editable='map.circle.editable' 
         visible='map.circle.visible' 
         events='map.circle.events'> 

     </ui-gmap-circle> 


    </ui-gmap-google-map> 
<script src='//maps.googleapis.com/maps/api/js?key=AIzaSyC_XEbbw3sNm4XlLAgqMJTggeHLDUdV-pY'></script> 
</div> 

回答

1

將2個文件組合成1個文件,並在一行中初始化$ stateProvider。

+0

您的意思是我上面爲我的控制器發佈的代碼與我目前用於searchRadius.html的代碼相同?是的,它是 – Tom

+0

我想爲我的getlocation.html視圖使用getLoc.js,而searchRaidus.js爲我的searchRadius.html,但也許我設置了錯誤? – Tom

+0

對不起,我不知道你在說什麼。但我使用路由將MapsCtrl控制器鏈接到searchRadius.html這裏:'templateUrl:'searchRadius.html', controller:'MapsCtrl','所以路徑應該沒問題吧? – Tom