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.

109 lines
4.3 KiB

  1. 'use strict';
  2. angular.module('app.main', ['ngRoute', 'leaflet-directive'])
  3. .config(['$routeProvider', function($routeProvider) {
  4. $routeProvider.when('/main', {
  5. templateUrl: 'views/main/main.html',
  6. controller: 'MainCtrl'
  7. });
  8. }])
  9. .controller('MainCtrl', function($scope, $http, leafletMapEvents) {
  10. //map
  11. $scope.center = {
  12. lat: 41.38014146592283,
  13. lng: 2.1773743629455566,
  14. zoom: 17
  15. };
  16. $scope.bounds = {};
  17. $scope.markers = [];
  18. $scope.paths = [];
  19. $scope.tiles = {
  20. //url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
  21. url: "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
  22. // més estils https://leaflet-extras.github.io/leaflet-providers/preview/
  23. options: {
  24. attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
  25. }
  26. };
  27. $scope.events = {
  28. map: {
  29. enable: ['dragend'],
  30. logic: 'emit'
  31. }
  32. };
  33. $scope.eventDetected = "No events yet...";
  34. console.log($scope.eventDetected);
  35. $scope.$on('leafletDirectiveMap.map-simple-map.dragend', function(event) {
  36. $scope.eventDetected = "Dragend";
  37. console.log($scope.eventDetected);
  38. console.log($scope.center);
  39. if ($scope.center.zoom > 16) {
  40. $scope.getCells($scope.center.lat, $scope.center.lng);
  41. }
  42. });
  43. var antennaIcon = {
  44. iconUrl: 'img/antenna.png',
  45. iconSize: [50, 50], // size of the icon
  46. iconAnchor: [25, 50], // point of the icon which will correspond to marker's location
  47. };
  48. var markX = {
  49. iconUrl: 'img/markX.png',
  50. iconSize: [50, 50], // size of the icon
  51. iconAnchor: [25, 50], // point of the icon which will correspond to marker's location
  52. };
  53. var markY = {
  54. iconUrl: 'img/markY.png',
  55. iconSize: [50, 50], // size of the icon
  56. iconAnchor: [25, 50], // point of the icon which will correspond to marker's location
  57. };
  58. $scope.getCells = function(lat, lng) {
  59. $scope.status = "getting data";
  60. var xLat = lat + 0.002;
  61. var xLng = lng - 0.004;
  62. var yLat = lat - 0.002;
  63. var yLng = lng + 0.004;
  64. console.log(xLat + ", " + xLng);
  65. console.log(yLat + ", " + yLng);
  66. //$http.get(urlapi + 'cells/43.73429/7.41841/43.73210/7.42196')
  67. $http.get(urlapi + 'cells/' + xLat + '/' + xLng + '/' + yLat + '/' + yLng)
  68. .then(function(data) {
  69. console.log('data success');
  70. console.log(data);
  71. $scope.cells = data.data;
  72. //draw markers on map
  73. $scope.markers = [];
  74. $scope.markers.push({
  75. lat: Number(xLat),
  76. lng: Number(xLng),
  77. icon: markX
  78. });
  79. $scope.markers.push({
  80. lat: Number(yLat),
  81. lng: Number(yLng),
  82. icon: markY
  83. });
  84. for (var i = 0; i < $scope.cells.length; i++) {
  85. $scope.markers.push({
  86. lat: Number($scope.cells[i].lat),
  87. lng: Number($scope.cells[i].lon),
  88. message: "lat:" + $scope.cells[i].lat + ", lon:" + $scope.cells[i].lon,
  89. icon: antennaIcon
  90. });
  91. }
  92. /*$scope.center = {
  93. lat: (Number($scope.cells[0].lat) + Number($scope.cells[0].lat)) / 2,
  94. lng: (Number($scope.cells[0].lon) + Number($scope.cells[0].lon)) / 2,
  95. zoom: 16
  96. };*/
  97. $scope.status = "data charged";
  98. }, function(data) {
  99. console.log('data error');
  100. });
  101. };
  102. $scope.getCells(41.38014146592283, 2.1773743629455566);
  103. $scope.status = "getting data";
  104. });