You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.0 KiB

  1. 'use strict';
  2. angular.module('app.travel', ['ngRoute', 'ui-leaflet'])
  3. .config(['$routeProvider', function($routeProvider) {
  4. $routeProvider.when('/travel/:travelid', {
  5. templateUrl: 'views/travel/travel.html',
  6. controller: 'TravelCtrl'
  7. });
  8. }])
  9. .controller('TravelCtrl', function($scope, $http, $routeParams,
  10. leafletData, leafletBoundsHelpers) {
  11. $scope.travel = {};
  12. //map
  13. $scope.center = {
  14. /*lat: 0,
  15. lng: 0,
  16. zoom: 1*/
  17. };
  18. $scope.bounds = {};
  19. $scope.markers = [];
  20. $scope.tiles = {
  21. url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
  22. options: {
  23. attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
  24. }
  25. };
  26. $http.get(urlapi + 'travels/id/' + $routeParams.travelid)
  27. .then(function(data, status, headers, config) {
  28. console.log('data success');
  29. console.log(data);
  30. $scope.travel = data.data;
  31. //map
  32. $scope.markers = [];
  33. $scope.markers.push({
  34. lat: Number($scope.travel.from.lat),
  35. lng: Number($scope.travel.from.long),
  36. message: $scope.travel.from.name
  37. });
  38. $scope.markers.push({
  39. lat: Number($scope.travel.to.lat),
  40. lng: Number($scope.travel.to.long),
  41. message: $scope.travel.to.name
  42. });
  43. $scope.center = {
  44. lat: (Number($scope.travel.from.lat) + Number($scope.travel.to.lat)) / 2,
  45. lng: (Number($scope.travel.from.long) + Number($scope.travel.to.long)) / 2,
  46. zoom: 4
  47. };
  48. }, function(data, status, headers, config) {
  49. console.log('data error');
  50. });
  51. });