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