Statistics
| Branch: | Tag: | Revision:

root / static / js / management-map.js @ 1d70dbce

History | View | Annotate | Download (4.4 kB)

1
var lat;
2
var lng;
3
var zoomLevel = 8;
4
var latlng = new google.maps.LatLng(lat,lng);
5
var map = '';
6
var bounds = '';
7
var image = '';
8
var infoWindow;
9
var pinImg;
10
var styles;
11
var servicesUrl;
12
var servicesEditUrl;
13

    
14
function initialize() {
15
        image = new google.maps.MarkerImage(pinImg,
16
        // This marker is 29 pixels wide by 40 pixels tall.
17
        new google.maps.Size(29, 40),
18
        // The origin for this image is 0,0.
19
        new google.maps.Point(0,0),
20
        // The anchor for this image is the base of the flagpole at 18,42.
21
        new google.maps.Point(14, 40)
22
);
23
var styleArray = [
24
{
25
        featureType: "all",
26
        stylers: [
27
        { saturation: -60 },
28
        {gamma: 1.00 }
29
        ]
30
        },{
31
        featureType: "poi.business",
32
        elementType: "labels",
33
        stylers: [
34
        { visibility: "off" }
35
        ]
36
        },
37
        { "featureType": "transit.line", "elementType": "geometry", "stylers": [ { "visibility": "off" } ] },
38
        { "featureType": "poi", "elementType": "all", "stylers": [ { "visibility": "off" } ] },
39
        {'featureType': "administrative.country",
40
        'elementType': "labels",
41
        'stylers': [
42
        { 'visibility': "off" }
43
        ]}
44

    
45
];
46
var mapOptions = {
47
        center : latlng,
48
        zoom : zoomLevel,
49
        mapTypeId : google.maps.MapTypeId.ROADMAP,
50
        styles: styleArray,
51
        mapTypeId: google.maps.MapTypeId.ROADMAP,
52
        mapTypeControlOptions: {
53
        style: google.maps.MapTypeControlStyle.DEFAULT
54
        },
55
        navigationControl: true,
56
        mapTypeControl: false,
57
        };
58
        map = new google.maps.Map(document.getElementById("map_canvas"),
59
        mapOptions);
60

    
61
        bounds = new google.maps.LatLngBounds();
62
        infoWindow = new google.maps.InfoWindow();
63

    
64
}
65

    
66

    
67
function placeMarkers(){
68
var markers = new Array();
69
$.get(servicesUrl, function(data){
70
        $.each(data, function(index, jsonMarker) {
71
        var marker = createMarker(jsonMarker);
72
        if (marker){
73
        bounds.extend(marker.position);
74
        markers.push(marker);
75
        google.maps.event.addListener(marker, 'click', function() {
76
                infoWindow.setContent( "<div><h4>"+jsonMarker.name+"</h4>"+
77

    
78
        "<div class='tabbable'>"+
79
    "<ul class='nav nav-tabs'>"+
80
    "<li class='active'><a href='#tab1' data-toggle='tab'>{% trans 'Info' %}</a></li>"+
81
    "<li><a href='#tab2' data-toggle='tab'>{% trans 'More...' %}</a></li>"+
82
    "</ul>"+
83
    "<div class='tab-content'>"+
84
    "<div class='tab-pane active' id='tab1'>"+
85
    "<dl class='dl-horizontal'>"+
86
                        "<dt>Name</dt><dd>"+jsonMarker.name+"&nbsp;</dd>"+
87
                        "<dt>Address</dt><dd>"+jsonMarker.address+"&nbsp;</dd>"+
88
                        "<dt>Encryption</dt><dd>"+jsonMarker.enc+"&nbsp;</dd>"+
89
                        "<dt>SSID</dt><dd>"+jsonMarker.SSID+"&nbsp;</dd>"+
90
                        "<dt>Number of APs</dt><dd>"+jsonMarker.AP_no+"&nbsp;</dd></dl>"+
91
    "</div>"+
92
    "<div class='tab-pane' id='tab2'>"+
93
    "<dl class='dl-horizontal'>"+
94
                        "<dt>Port Restrict</dt><dd>"+jsonMarker.port_restrict+"&nbsp;</dd>"+
95
                        "<dt>transp_proxy</dt><dd>"+jsonMarker.transp_proxy+"&nbsp;</dd>"+
96
                        "<dt>IPv6</dt><dd>"+jsonMarker.IPv6+"&nbsp;</dd>"+
97
                        "<dt>NAT</dt><dd>"+jsonMarker.NAT+"&nbsp;</dd>"+
98
                        "<dt>Wired</dt><dd>"+jsonMarker.wired+"&nbsp;</dd></dl>"+
99
    "</div>"+
100
    "</div>"+
101
    "</div>"+
102
    "<div style='text-align:right;'><a href = '" + servicesEditUrl + jsonMarker.key + "' class='btn btn-primary'>Edit</a></div>"+
103
    "</div>");
104
                infoWindow.open(map,marker);
105
     });
106
        }
107
        });
108
        var mcOptions = {gridSize: 50, maxZoom: 15, styles: styles};
109

    
110

    
111

    
112
        var markerCluster = new MarkerClusterer(map, markers, mcOptions);
113
        map.fitBounds(bounds)
114
        });
115
        }
116

    
117
        function createMarker(markerObj){
118
        var title = markerObj.name;
119
        var latLng = new google.maps.LatLng(markerObj.lat, markerObj.lng);
120
        var marker = new google.maps.Marker({
121
        'position' : latLng,
122
        'map' : map,
123
        'title': title,
124
        'icon': image,
125
        });
126
        return marker;
127
        }
128

    
129
        function clusterMarkers(markers){
130
        var markerCluster = new MarkerClusterer(map, markers);
131
        }
132

    
133
        $(document).ready(function() {
134
                mapDiv = $('#map_canvas');
135
                lat = mapDiv.data('center-lat');
136
                lng = mapDiv.data('center-lng');
137
                lat = parseFloat(lat.toString().replace(",","."));
138
                lng = parseFloat(lng.toString().replace(",","."));
139
                pinImg = mapDiv.data('pin');
140
                groupImg = mapDiv.data('group');
141
                servicesUrl = mapDiv.data('service');
142
                servicesEditUrl = mapDiv.data('service-edit');
143
                console.log(servicesEditUrl);
144
                styles = [{
145
                        url: groupImg,
146
                        height: 54,
147
                        width: 63,
148
                        textColor: '#ffffff',
149
                        textSize: 11
150
                        },
151
                        {
152
                        url: groupImg,
153
                        height: 54,
154
                        width: 63,
155
                        textColor: '#ffffff',
156
                        textSize: 11
157
                        },
158
                        {
159
                        url: groupImg,
160
                        height: 54,
161
                        width: 63,
162
                        textColor: '#ffffff',
163
                        textSize: 11
164
                }];
165
                initialize();
166
                marks = placeMarkers();
167
                clusterMarkers(marks);
168
        });