rad = function(x) {return x*Math.PI/180;} distHaversine = function(p1, p2) { var R = 6371; // earth's mean radius in km var dLat = rad(p2.lat() - p1.lat()); var dLong = rad(p2.lng() - p1.lng()); var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(rad(p1.lat())) * Math.cos(rad(p2.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; return (d * 0.621371).toFixed(1); } function linkColor(link) { if (location.hostname == 'www.hamwan.org' || location.hostname == 'hamwan.org') { return link.STRENGTH && link.TYPE != 'SURVEY' ? '#0086db' : '#666'; } else { return link.LINK_COLOR; } } function linkOpacity() { return location.hostname == 'www.hamwan.org' || location.hostname == 'hamwan.org' ? 0.5 : 0.7; } function linkWidth(link) { return Math.sqrt((link.SPEED || 1000000) / 10000000) + 2 } function initialize() { var sites = {}; var coverage = [ { NAME: 'first 3', src: '/map/hamwancoverage.png', n: 48.34369, e: -121.6021, s: 46.90387, w: -123.0283}, { NAME: 'East Tiger', src: '/map/etiger-240.png', n: 47.7114, e: -121.7513, s: 46.99149, w: -122.8139}, { NAME: 'Triangle', src: '/map/triangle-coverage.png', n: 48.82953, e: -122.5549, s: 47.92965, w: -123.9097}, { NAME: 'Beacon', src: '/map/beacon-coverage.png', n: 48.486141, e: -120.984461, s: 46.690259, w: -123.646939}, { NAME: 'Capitol Peak', src: '/map/capitolpeak-coverage.png', n: 47.42304, e: -122.4789, s: 46.52316, w: -123.7977}, { NAME: 'Baw Faw', src: '/map/bawfaw-coverage-s1.png', n: 46.84812, e: -122.6781, s: 46.39818, w: -123.3333}, { NAME: 'Buck', src: '/map/buck-coverage.png', n: 48.651108, e: -121.594022, s: 46.855226, w: -124.264758}, { NAME: 'Crystal', src: '/map/CrystalS3.png', n: 47.835938, e: -120.185174, s: 46.040062, w: -122.815226}, { NAME: 'Lookout', src: '/map/lookout-coverage.png', n: 49.585455, e: -121.002232, s: 47.789545, w: -123.722368}, { NAME: 'Haystack', src: '/map/haystackcoverage.png', n: 48.43857, e: -121.4244, s: 47.17873, w: -122.9248} ]; var mapOptions = { center: new google.maps.LatLng(47.62378,-122.6152), // Capitol Parkish zoom: 8, scrollwheel: false, mapTypeId: google.maps.MapTypeId.TERRAIN, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU } }; var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); // Set up search/autocomplete var input = /** @type {HTMLInputElement} */(document.getElementById('searchTextField')); var autocomplete = new google.maps.places.Autocomplete(input); autocomplete.bindTo('bounds', map); var infowindow = new google.maps.InfoWindow(); var marker = new google.maps.Marker({ map: map }); google.maps.event.addListener(autocomplete, 'place_changed', function() { infowindow.close(); marker.setVisible(false); input.className = ''; var place = autocomplete.getPlace(); if (!place.geometry) { // Inform the user that the place was not found and return. input.className = 'notfound'; return; } // If the place has a geometry, then present it on a map. if (place.geometry.viewport) { map.fitBounds(place.geometry.viewport); } else { map.setCenter(place.geometry.location); map.setZoom(13); } marker.setIcon(/** @type {google.maps.Icon} */({ url: place.icon, size: new google.maps.Size(71, 71), origin: new google.maps.Point(0, 0), anchor: new google.maps.Point(17, 34), scaledSize: new google.maps.Size(35, 35) })); marker.setPosition(place.geometry.location); marker.setVisible(true); var address = ''; if (place.address_components) { address = [ (place.address_components[0] && place.address_components[0].short_name || ''), (place.address_components[1] && place.address_components[1].short_name || ''), (place.address_components[2] && place.address_components[2].short_name || '') ].join(' '); } infowindow.setContent('
" + site.COMMENT + "
" }); // Add clients to map for (var clientid in site.CLIENTS) { var client = site.CLIENTS[clientid]; client.position = new google.maps.LatLng(client.LATITUDE, client.LONGITUDE); var clientmarker = new google.maps.Marker({ position: client.position, icon: surveyicon, map: map, title: client.NAME, comment: "Signal survey
" : "") + "" + client.COMMENT + "
" }); google.maps.event.addListener(clientmarker, 'click', function() { infowindow.setContent(this.comment); infowindow.open(map, this); }); // Add client links to map if (client.STRENGTH) { var linkpolyline = new google.maps.Polyline({ path: [site.position, client.position], strokeColor: linkColor(client), strokeOpacity: linkOpacity(), strokeWeight: linkWidth(client) }); linkpolyline.setMap(map); } } // Add PtP links to map for (var linkid in site.LINKS) { var link = site.LINKS[linkid] // only plot each link once (ignore reciprocal links) if (siteid == link.SITE1_ID) { var linkpolyline = new google.maps.Polyline({ path: [site.position, sites[link.SITE2_ID].position], strokeColor: linkColor(link), strokeOpacity: linkOpacity(), strokeWeight: linkWidth(link) }); linkpolyline.setMap(map); } // Add link data to comment of both associated sites sitemarker.comment += "" + link.COMMENT + "
" } // create site infowindow (now that link data is incorporated) google.maps.event.addListener(sitemarker, 'click', function() { infowindow.setContent(this.comment); infowindow.open(map, this); }); } }); // Add mesh nodes kml map //var ActiveNodesLayer = new google.maps.KmlLayer('http://nodes.map.nwmesh.us/'); //ActiveNodesLayer.setMap(map); // Add listener for fullscreen button google.maps.event.addDomListener(document.getElementById('fullscreen'), 'click', function() { var map_container = document.getElementById('map_container') if (map_container.className == "fullscreen") { map_container.className = "map_container"; } else { map_container.className = "fullscreen"; } google.maps.event.trigger(map, 'resize'); }); // Add the controls to the map map.controls[google.maps.ControlPosition.TOP_LEFT].push(document.getElementById('search')); map.controls[google.maps.ControlPosition.RIGHT_TOP].push(document.getElementById('fullscreen')); } google.maps.event.addDomListener(window, 'load', initialize);