arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/www/js/newEvent.js
www/js/newEvent.jsRaw
 1angular.module('app.newEvent', ['pascalprecht.translate', 'ui-leaflet'])
 2
 3.controller('NewEventCtrl', function($scope, $http, $ionicModal, $timeout,
 4    $ionicLoading, $filter, leafletData, leafletBoundsHelpers) {
 5
 6    $scope.event={};
 7    $scope.event.categories=[{name: "prova"}];
 8    $scope.event.location={
 9        direction: "",
10        geo: {
11            lat: "",
12            long: "",
13            name: ""
14        }
15    };
16    $scope.postEvent = function(){
17        $http({
18            url: urlapi + 'events',
19            method: "POST",
20            data: $scope.event
21        })
22        .then(function(data) {
23            $scope.event={};
24            window.location.href="#/app/events";
25        },
26        function(response) { // optional
27                // failed
28                console.log(response);
29        });
30    };
31
32    /* map */
33
34    $scope.center= {
35        lat: 0,
36        lng: 0,
37        zoom: 1
38    };
39    $scope.markers=new Array();
40    $scope.tiles= {
41        url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
42        options: {
43            attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
44        }
45    };
46    $scope.getGeo = function(){
47
48        $scope.markers=[];
49        console.log($scope.event.location.direction);
50        $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.event.location.direction + '&format=json&limit=1')
51        .then(function(data) {
52            console.log(data);
53            if(data.data[0])
54            {
55                $scope.event.location.geo.lat=data.data[0].lat;
56                $scope.event.location.geo.long=data.data[0].lon;
57                //$scope.newtravel.from.name=data.data[0].display_name;
58                $scope.markers.push({
59                    lat: Number(data.data[0].lat),
60                    lng: Number(data.data[0].lon),
61                    message: $scope.event.location.direction
62                });
63                $scope.center= {
64                    lat: Number(data.data[0].lat),
65                    lng: Number(data.data[0].lon),
66                    zoom: 16
67                };
68            }
69        });
70
71    };
72});