arnaucube
arnaucube/cellMapVisualizerPublic Self-hosted repository
cellMapVisualizer/web/views/main/main.js
web/views/main/main.jsRaw
 1'use strict';
 2
 3angular.module('app.main', ['ngRoute', 'ui-leaflet'])
 4
 5.config(['$routeProvider', function($routeProvider) {
 6  $routeProvider.when('/main', {
 7    templateUrl: 'views/main/main.html',
 8    controller: 'MainCtrl'
 9  });
10}])
11
12.controller('MainCtrl', function($scope, $http) {
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        url: "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
21        // més estils https://leaflet-extras.github.io/leaflet-providers/preview/
22        options: {
23            attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
24        }
25    };
26    //var antennaIcon = L.icon({
27    var antennaIcon = {
28        iconUrl: 'img/antenna.png',
29        iconSize:     [50, 50], // size of the icon
30        iconAnchor:   [25, 50], // point of the icon which will correspond to marker's location
31    };
32
33    $http.get(urlapi + 'cells/43.73429/7.41841/43.73210/7.42196')
34        .then(function(data) {
35            console.log('data success');
36            console.log(data);
37            $scope.cells = data.data;
38            //draw markers on map
39            $scope.markers = [];
40            for (var i = 0; i < $scope.cells.length; i++) {
41                $scope.markers.push({
42                    lat: Number($scope.cells[i].lat),
43                    lng: Number($scope.cells[i].lon),
44                    message: $scope.cells[i].mcc,
45                    icon: antennaIcon
46                });
47            }
48
49            $scope.center = {
50                lat: (Number($scope.cells[0].lat) + Number($scope.cells[0].lat)) / 2,
51                lng: (Number($scope.cells[0].lon) + Number($scope.cells[0].lon)) / 2,
52                zoom: 16
53            };
54        }, function(data) {
55            console.log('data error');
56        });
57});