index.html 11.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
{% extends "base.html" %}
{% load i18n %}
	{% block currentpagetitle %}{% trans "Home" %}{% endblock %}
    {% block homepage %}class="active"{% endblock %}
    {% block hometop %}class="active"{% endblock %}
    {% block extrahead %}
    <style type="text/css">
        .headtitle {font-family: "Franklin Gothic Demi", "Franklin Gothic", "ITC Franklin Gothic", Arial, sans-serif; letter-spacing: -1px; }
    </style>
    <script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/markerclusterer.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
	var lat = "{{MAP_CENTER.0}}";
	var lat = parseFloat(lat.replace(",","."));
	var lng = "{{MAP_CENTER.1}}";
	var lng = parseFloat(lng.replace(",","."));
	var zoomLevel = 6;
	var latlng = new google.maps.LatLng(lat,lng);
	var map = '';
	var bounds = '';
	var image = '';
	var infoWindow;
	addr = {};

	var styles = [ {
		url : '/static/img/edugroup.png',
		height : 54,
		width : 63,
		textColor : '#ffffff',
		textSize : 11
	}, {
		url : '/static/img/edugroup.png',
		height : 54,
		width : 63,
		textColor : '#ffffff',
		textSize : 11
	}, {
		url : '/static/img/edugroup.png',
		height : 54,
		width : 63,
		textColor : '#ffffff',
		textSize : 11
	} ];

	function initialize() {
		image = new google.maps.MarkerImage('/static/img/edupin.png',
		// This marker is 29 pixels wide by 40 pixels tall.
		new google.maps.Size(29, 40),
		// The origin for this image is 0,0.
		new google.maps.Point(0, 0),
		// The anchor for this image is the base of the flagpole at 18,42.
		new google.maps.Point(14, 40));

		var styleArray = [ {
			featureType : "all",
			stylers : [ {
				saturation : -60
			}, {
				gamma : 1.00
			} ]
		}, {
			featureType : "poi.business",
			elementType : "labels",
			stylers : [ {
				visibility : "off"
			} ]
		}, {
			"featureType" : "transit.line",
			"elementType" : "geometry",
			"stylers" : [ {
				"visibility" : "off"
			} ]
		}, {
			"featureType" : "poi",
			"elementType" : "all",
			"stylers" : [ {
				"visibility" : "off"
			} ]
		}, {
			'featureType' : "administrative.country",
			'elementType' : "labels",
			'stylers' : [ {
				'visibility' : "off"
			} ]
		}

		];

	geocoder = new google.maps.Geocoder();
	// disable scrolling/draging in maps
	if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
		isDraggable = false;
		isScrollable = true;
	} else {
		isDraggable = true;
		isScrollable = false;
	}

	var mapOptions = {
			center : latlng,
			zoom : zoomLevel,
			mapTypeId : google.maps.MapTypeId.ROADMAP,
			styles : styleArray,
			mapTypeId : google.maps.MapTypeId.ROADMAP,
			mapTypeControlOptions : {
				style : google.maps.MapTypeControlStyle.DEFAULT
			},
			navigationControl : true,
			mapTypeControl : false,
			scrollwheel: isScrollable,
			draggable: isDraggable
		};
		map = new google.maps.Map(document.getElementById("map_canvas"),
				mapOptions);


		var homeControlDiv = document.createElement('div');
		homeControlDiv.className='roundButtonHolder';
		homeControlDiv.id="locationButton";
		var homeControl = new HomeControl(homeControlDiv, map);

		homeControlDiv.index = 1;
		map.controls[google.maps.ControlPosition.TOP_LEFT].push(homeControlDiv);

		bounds = new google.maps.LatLngBounds();
		infoWindow = new google.maps.InfoWindow();
		google.maps.event.addListener(map, 'idle', function() {
			center = map.getCenter();
			geocode(center);
			zoom = map.getZoom();
			if (zoom > 12){
				$("#showCityBtn").show();
				$("#showCountryBtn").hide();
			}
			else if ((zoom <= 12) && (zoom > 7)){
				$("#showCityBtn").hide();
				$("#showCountryBtn").show();
			}
			else {
				$("#showCityBtn").hide();
				$("#showCountryBtn").hide();
			}
		});


	}

	var markers = new Array();
	function placeMarkers() {

		$
				.get(
						"{% url get-all-services %}",
						function(data) {
							$
									.each(
											data,
											function(index, jsonMarker) {
												var marker = createMarker(jsonMarker);
												if (marker) {
													bounds
															.extend(marker.position);
													markers.push(marker);
													google.maps.event
															.addListener(
																	marker,
																	'click',
																	function() {
																		infoWindow.setContent ( "<div><h4>"
																				+ jsonMarker.inst
																				+ "</h4>"
																				+

																				"<div class='tabbable'>"
																				+ "<ul class='nav nav-tabs'>"
																				+ "<li class='active'><a href='#tab1' data-toggle='tab'>{% trans 'Info' %}</a></li>"
																				+ "<li><a href='#tab2' data-toggle='tab'>{% trans 'More...' %}</a></li>"
																				+ "</ul>"
																				+ "<div class='tab-content'>"
																				+ "<div class='tab-pane active' id='tab1'>"
																				+ "<dl class='dl-horizontal'>"
																				+ "<dt>{% trans 'Name' %}</dt><dd>"
																				+ jsonMarker.name
																				+ "&nbsp;</dd>"
																				+ "<dt>{% trans 'Address' %}</dt><dd>"
																				+ jsonMarker.address
																				+ "&nbsp;</dd>"
																				+ "<dt>{% trans 'Encryption' %}</dt><dd>"
																				+ jsonMarker.enc
																				+ "&nbsp;</dd>"
																				+ "<dt>{% trans 'SSID' %}</dt><dd>"
																				+ jsonMarker.SSID
																				+ "&nbsp;</dd>"
																				+ "<dt>{% trans 'Number of APs' %}</dt><dd>"
																				+ jsonMarker.AP_no
																				+ "&nbsp;</dd></dl>"
																				+ "</div>"
																				+ "<div class='tab-pane' id='tab2'>"
																				+ "<dl class='dl-horizontal'>"
																				+ "<dt>{% trans 'Port Restrict' %}</dt><dd>"
																				+ jsonMarker.port_restrict
																				+ "&nbsp;</dd>"
																				+ "<dt>{% trans 'transp_proxy' %}</dt><dd>"
																				+ jsonMarker.transp_proxy
																				+ "&nbsp;</dd>"
																				+ "<dt>IPv6</dt><dd>"
																				+ jsonMarker.IPv6
																				+ "&nbsp;</dd>"
																				+ "<dt>NAT</dt><dd>"
																				+ jsonMarker.NAT
																				+ "&nbsp;</dd>"
																				+ "<dt>{% trans 'Wired' %}</dt><dd>"
																				+ jsonMarker.wired
																				+ "&nbsp;</dd></dl>"
																				+ "</div>"
																				+ "</div>"
																				+ "</div>"
																				+ "</div>");
																		infoWindow
																				.open(
																						map,
																						marker);
																	});
												}
											});
							var mcOptions = {
								gridSize : 50,
								maxZoom : 15,
								styles : styles
							};

							var markerCluster = new MarkerClusterer(map,
									markers, mcOptions);
							map.fitBounds(bounds)
						});
	}

	function createMarker(markerObj) {
		var title = markerObj.name;
		var address = markerObj.address;
		var latLng = new google.maps.LatLng(markerObj.lat, markerObj.lng);
		var marker = new google.maps.Marker({
			'position' : latLng,
			'map' : map,
			'title' : title,
			'address' : address,
			'icon' : image,
		});
		return marker
	}

	function clusterMarkers(markers) {
		var markerCluster = new MarkerClusterer(map, markers);
	}

	function rad(x) {
		return x * Math.PI / 180;
	}

	function find_closest_marker(event) {
		var lat = event.latLng.lat();
		var lng = event.latLng.lng();
		var R = 6371; // radius of earth in km
		var distances = [];
		var closest = -1;
		for (i = 0; i < markers.length; i++) {
			var mlat = markers[i].position.lat();
			var mlng = markers[i].position.lng();
			var dLat = rad(mlat - lat);
			var dLong = rad(mlng - lng);
			var a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
					+ Math.cos(rad(lat)) * Math.cos(rad(lat))
					* Math.sin(dLong / 2) * Math.sin(dLong / 2);
			var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
			var d = R * c;
			distances[i] = d;
			if (closest == -1 || d < distances[closest]) {
				closest = i;
			}
		}

	}

	function geocode(position){
		addr = {};
		geocoder
		.geocode(
				{
					'latLng' : position
				},
				function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						if (results.length >= 1) {
							for ( var ii = 0; ii < results[0].address_components.length; ii++) {
								var street_number = route = street = city = state = zipcode = country = formatted_address = '';
								var types = results[0].address_components[ii].types
										.join(",");
								if (types == "sublocality,political"
										|| types == "locality,political"
										|| types == "neighborhood,political"
										|| types == "political") {
									addr.city = (city == '' || types == "locality,political") ? results[0].address_components[ii].long_name
											: city;
								}
								if (types == "country,political") {
									addr.country = results[0].address_components[ii].long_name;
								}
							}
						}
					}
				});
	}

	function codeAddress(address) {
	    geocoder.geocode( { 'address': address}, function(results, status) {
	      if (status == google.maps.GeocoderStatus.OK) {
	        map.setCenter(results[0].geometry.location);
	    	map.fitBounds(results[0].geometry.bounds)
	      } else {
	      }
	    });
	  }

	function HomeControl(controlDiv, map) {

		  // Set CSS styles for the DIV containing the control
		  // Setting padding to 5 px will offset the control
		  // from the edge of the map.
		  controlDiv.style.padding = '5px';

		  // Set CSS for the control border.
		  var controlUI = document.createElement('button');
		  controlUI.className='btn btn-warning roundButton';
		  controlUI.id = "showCityBtn";
		  extraCSS = 'background-image: url(/static/img/city.png);background-position: center center; background-repeat: no-repeat;';
		  controlUI.style.cssText='display:none; cursor:pointer; white-space:nowrap; position:absolute; '+extraCSS;
		  controlUI.title = "City View";

		  // Set CSS for the control border.
		  var controlUI2 = document.createElement('button');
		  controlUI2.className='btn btn-warning roundButton';
		  controlUI2.id = "showCountryBtn";
		  extraCSS2 = 'background-image: url(/static/img/country.png);background-position: center center; background-repeat: no-repeat;';
		  controlUI2.style.cssText='display:none; cursor:pointer; white-space:nowrap; position:absolute; '+extraCSS2;
		  controlUI2.title = "Country View";

		  controlDiv.appendChild(controlUI);
		  controlDiv.appendChild(controlUI2);

		  // Setup the click event listeners: simply set the map to Chicago.
		  google.maps.event.addDomListener(controlUI, 'click', function() {
		    codeAddress(addr.city+','+addr.country);
		  });
		  google.maps.event.addDomListener(controlUI2, 'click', function() {
			    codeAddress(addr.country);
			  });

		}

	$(document).ready(function() {
		initialize();
		marks = placeMarkers();
		clusterMarkers(marks);
	});
</script>
{% endblock %}


					{% block subcontent %}
					<h4>{% trans "Eduroam in" %} {% trans COUNTRY_NAME %}</h4>
					<hr>

					<div id="map_canvas" style="width:100%; height:600px; overflow: hidden;"></div>
					{% endblock %}