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.

73 lines
2.7 KiB

  1. 'use strict';
  2. angular.module('app.travels', ['ngRoute', 'ui-leaflet'])
  3. .config(['$routeProvider', function($routeProvider) {
  4. $routeProvider.when('/travels', {
  5. templateUrl: 'views/travels/travels.html',
  6. controller: 'TravelsCtrl'
  7. });
  8. }])
  9. .controller('TravelsCtrl', function($scope, $http) {
  10. $scope.travels = [];
  11. $scope.loadMorePagination = true;
  12. $scope.page = 0;
  13. //map
  14. $scope.center = {};
  15. $scope.bounds = {};
  16. $scope.markers = [];
  17. $scope.paths = [];
  18. $scope.tiles = {
  19. url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
  20. options: {
  21. attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
  22. }
  23. };
  24. $http.get(urlapi + 'travels?page=' + $scope.page)
  25. .then(function(data) {
  26. console.log('data success');
  27. console.log(data);
  28. $scope.travels = data.data;
  29. //draw markers on map
  30. $scope.markers = [];
  31. for (var i = 0; i < $scope.travels.length; i++) {
  32. $scope.markers.push({
  33. lat: Number($scope.travels[i].from.lat),
  34. lng: Number($scope.travels[i].from.long),
  35. message: $scope.travels[i].from.name
  36. });
  37. $scope.markers.push({
  38. lat: Number($scope.travels[i].to.lat),
  39. lng: Number($scope.travels[i].to.long),
  40. message: $scope.travels[i].to.name
  41. });
  42. }
  43. //draw lines between markers on map
  44. $scope.paths = {};
  45. var paths = [];
  46. for (var i = 0; i < $scope.markers.length; i++) {
  47. var x = $scope.markers[i].lat;
  48. var y = $scope.markers[i].lng;
  49. paths.push([x, y]);
  50. }
  51. $scope.paths = {
  52. p1: {
  53. color: '#9575CD',
  54. weight: 8,
  55. latlngs: paths
  56. }
  57. };
  58. //var maplines = L.polyline(lines).addTo(map)
  59. $scope.center = {
  60. lat: (Number($scope.travels[0].from.lat) + Number($scope.travels[0].to.lat)) / 2,
  61. lng: (Number($scope.travels[0].from.long) + Number($scope.travels[0].to.long)) / 2,
  62. zoom: 4
  63. };
  64. }, function(data) {
  65. console.log('data error');
  66. });
  67. });