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.

62 lines
1.9 KiB

  1. angular.module('app.mapEvents', ['pascalprecht.translate', 'ui-leaflet'])
  2. .controller('MapEventsCtrl', function($scope, $http, $ionicModal,
  3. $timeout, $ionicLoading, $filter,
  4. leafletBoundsHelpers, $cordovaSocialSharing) {
  5. //map
  6. $scope.center = {
  7. lat: 0,
  8. lng: 0,
  9. zoom: 1
  10. };
  11. $scope.markers = [];
  12. $scope.tiles = {
  13. url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
  14. options: {
  15. attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
  16. }
  17. };
  18. $scope.events = [];
  19. $scope.page = 0;
  20. $http.get(urlapi + 'events')
  21. .then(function(data) {
  22. console.log('data success events');
  23. console.log(data); // for browser console
  24. //$scope.events = data.data; // for UI
  25. $scope.events = data.data;
  26. $scope.$broadcast('scroll.refreshComplete'); //refresher stop
  27. for (var i = 0; i < $scope.events.length; i++) {
  28. if ($scope.events[i].location) {
  29. var msg = "<a href='#/app/events/" + $scope.events[i]._id + "'>" +
  30. "<h4>" + $scope.events[i].title + "</h4>" +
  31. "<img src='" + $scope.events[i].img + "' style='width:100%;'>" +
  32. $scope.events[i].description + "</a>";
  33. $scope.markers.push({
  34. lat: Number($scope.events[i].location.geo.lat),
  35. lng: Number($scope.events[i].location.geo.long),
  36. message: msg
  37. });
  38. $scope.center = {
  39. lat: Number($scope.events[i].location.geo.lat),
  40. lng: Number($scope.events[i].location.geo.long),
  41. zoom: 12
  42. };
  43. }
  44. }
  45. }, function(data) {
  46. console.log('data error');
  47. $scope.$broadcast('scroll.refreshComplete'); //refresher stop
  48. $ionicLoading.show({
  49. template: 'Error connecting server',
  50. noBackdrop: true,
  51. duration: 2000
  52. });
  53. });
  54. });