Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.89 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. html,
  6. body,
  7. #map_canvas {
  8. margin: 0px;
  9. padding: 0px;
  10. height: 100%;
  11. width: 100%;
  12. }
  13. </style>
  14.  
  15. <style type="text/css">
  16. .center {
  17. float: center;
  18. width:90%;
  19. height: 30%;
  20. padding: 10px;
  21. border: 1px solid;
  22. overflow: scroll;
  23. }
  24. </style>
  25.  
  26. <style>
  27. #legend {
  28. background: white;
  29. padding: 10px;
  30. }
  31. </style>
  32.  
  33. <style scoped="scoped">
  34. button.button-bar {
  35. border: 2px solid #000000;
  36. background-color: #FFFFFF;
  37. border-radius: 10px ;
  38. padding: 4px ;
  39. -webkit-transition:
  40. -webkit-transform 0.01s ease-in-out
  41. }
  42. button.button-bar:hover { -webkit-transform: scale(1.2); }
  43. </style>
  44. </head>
  45.  
  46.  
  47. <body onload="initialize()">
  48.  
  49.  
  50.  
  51.  
  52. <div id="map_canvas" style="background-color:#EEEEEE;height:70%;width:60%;float:left;"></div>
  53.  
  54.  
  55. <div id="menu" style="background-color:#0000;height:100%;width:40%;float:right;">
  56. <input type='file' id='files' name='file'/></br>
  57.  
  58. <select id="optionList" onchange="choosedata()">
  59. <option selected="selected"></option>
  60. <option value="1">IMU temperature</option>
  61. <option value="2">IMU pressure</option>
  62. <option value="3">wind temperaure</option>
  63. </select><br>
  64.  
  65.  
  66. <form>
  67. <input type="text" id='enterurl' name="url" value="http://">
  68. <input onclick="overlay()" type="button" value="enter">
  69. </form>
  70.  
  71. <p>
  72. <br>
  73. <button class="button-bar" onclick="clearall()"> Clear </button>
  74. <button class="button-bar"onclick="plotheatmap()"> Heatmap </button>
  75. <button class="button-bar"onclick="showMarkers()"> Markers </button>
  76. <button class="button-bar"onclick="showPath()"> Path </button>
  77. <button class="button-bar"onclick="Opacity()"> Opacity </button>
  78. <button class="button-bar"onclick="changeGradient()"> Gradient </button>
  79. <button class="button-bar"onclick="changeRadius()"> Radius </button>
  80. <br><br>
  81. </p>
  82.  
  83.  
  84. <div id="poly" class="center"></div>
  85. </div><br>
  86. <div id="legend">legend!</div>
  87.  
  88.  
  89.  
  90. <script
  91. src="https://maps.googleapis.com/maps/api/js?libraries=visualization,geometry"> // libraries: visualization, geometry
  92. </script>
  93.  
  94. <script>
  95. var HK = new google.maps.LatLng(22.24785990000, 114.203384299999930000);
  96. var map;
  97. var markers=[]; //create markers array
  98. var json=[]; //create array for JSON data
  99. var showlength=[]; //create array for distance
  100. var heatmapData=[]; //create artay for heatmapData
  101. var fitbound=[]; //create array to contain bound LatLng
  102. var magnitudes=[]; //create array for magnitudes
  103. var boatspeeds=[]; //create array to contain boatspeed
  104. var weight=[];
  105. Mflag=0; //signal flag for markers
  106. Pflag=0; //signal flag for path
  107.  
  108. function choosedata(){
  109. if (document.getElementById("optionList").value == "1"){
  110. callback1();polylineLength();}
  111.  
  112. else if (document.getElementById("optionList").value == "2"){
  113. callback2();polylineLength();}
  114.  
  115. else if (document.getElementById("optionList").value == "3"){
  116. callback3();polylineLength();}
  117.  
  118. }
  119.  
  120. //choose file
  121. function readBlob() {
  122. setMarkers(null); //clear markers using setAllMap function
  123. markers.length=0; //empty markers array i.e. clear all markers
  124.  
  125. var files = document.getElementById('files').files[0];
  126. var reader = new FileReader();
  127.  
  128. // If we use onload, we need to check the readyState.
  129. reader.onload = function(evt) {
  130. if (evt.target.readyState == 2) {
  131. json=[];
  132. json.push(reader.result);
  133.  
  134. }
  135. };
  136. reader.readAsText(files);
  137. }
  138.  
  139. document.getElementById('files').addEventListener('change', function(evt) {
  140. readBlob();}, false);
  141.  
  142.  
  143.  
  144.  
  145. function initialize() { //create map
  146.  
  147. var mapOptions = {
  148. zoom:10,
  149. center: HK,
  150. mapTypeId: google.maps.MapTypeId.ROAD
  151. };
  152.  
  153. map = new google.maps.Map(document.getElementById('map_canvas'),
  154. mapOptions);
  155. map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(
  156. document.getElementById('legend'));
  157.  
  158.  
  159.  
  160. }
  161.  
  162.  
  163. function overlay(){
  164. var url = document.getElementById("enterurl").value;
  165. heatlayer = new google.maps.KmlLayer({
  166. url: url,
  167. suppressInfoWindows: true,
  168. map: map
  169. });
  170.  
  171. // a event listener for future development
  172. google.maps.event.addListener(heatlayer, 'click', function(event) {
  173. document.getElementById('poly').innerHTML+= 'this is an overlay'+ 'n </br>';
  174. });
  175. }
  176.  
  177.  
  178.  
  179. function callback1(){
  180.  
  181.  
  182. var getjson = JSON.parse(json); //built in JSON commmand, text->JSON
  183. //var getjason = eval ("(" + json + ")"); //avoid using eval for security reasons
  184.  
  185.  
  186.  
  187. for (var i = 0; i < getjson.features.length; i++) {
  188. var coords = getjson.features[i].geometry.coordinates; // get coordinates
  189. var latLng = new google.maps.LatLng(coords[1], coords[0]); // swap lon/lat
  190. var magnitude = getjson.features[i].properties.imutemperature; // get magnitude
  191. var boatspeed = getjson.features[i].properties.boatspeed; // get speed
  192.  
  193. var weightedLoc = {
  194. location: latLng,
  195. weight: Math.pow(2, magnitude)
  196. };
  197.  
  198. heatmapData.push(weightedLoc); // append GeoJson data
  199. fitbound.push(latLng); // show GeoJson data
  200. magnitudes.push(magnitude); // append magnitude to array
  201. boatspeeds.push(boatspeed); // append boatspeed to array
  202.  
  203.  
  204. // add markers to data points
  205. var marker = new google.maps.Marker({
  206. position: latLng,
  207. clickable: true,
  208. });
  209. addinfo(marker,i);
  210.  
  211. markers.push(marker); //add markers to array
  212. }
  213.  
  214.  
  215.  
  216. function addinfo(marker, j) {
  217. weight[j] = magnitudes.slice(j,j+1)
  218. google.maps.event.addListener(marker, 'click', function() {
  219. document.getElementById('poly').innerHTML += '<br> point n'+ (j+1)+'<br> Lat/Lng: n' + markers[j].getPosition()+'n <br>' +'imutemperature: n' + weight.slice(j,j+1)+'n degrees </br>' +'boatspeed: n'+ boatspeeds.slice(j,j+1)+'n km/hr </br>';
  220. });
  221. };
  222.  
  223.  
  224.  
  225. heatmap = new google.maps.visualization.HeatmapLayer({ //plot heatmap
  226. data: heatmapData,
  227. dissipating: false,
  228. opacity: 0.5,
  229. radius: 0.0005,
  230. });
  231.  
  232.  
  233.  
  234.  
  235.  
  236. var bounds = new google.maps.LatLngBounds(); //create bounds
  237. for (var i = 0; i < fitbound.length; i++) {
  238. bounds.extend(fitbound[i]);
  239. }
  240.  
  241. google.maps.event.addListener(map, 'click', function() { //click to fitbounds
  242. map.fitBounds(bounds);
  243. });
  244.  
  245. var polylineLength = 0; //function calculating distance
  246. for (var i = 0; i < fitbound.length; i++) {
  247. if (i > 0) polylineLength += google.maps.geometry.spherical.computeDistanceBetween(fitbound[i], fitbound[i-1]);
  248. }
  249. showlength[0]=(polylineLength);
  250.  
  251. document.getElementById('legend').innerHTML = 'i m legend1';
  252.  
  253. }
  254.  
  255. function callback2(){
  256.  
  257.  
  258. var getjson = JSON.parse(json); //built in JSON commmand, text->JSON
  259. //var getjason = eval ("(" + json + ")"); //avoid using eval for security reasons
  260.  
  261.  
  262.  
  263. for (var i = 0; i < getjson.features.length; i++) {
  264. var coords = getjson.features[i].geometry.coordinates; // get coordinates
  265. var latLng = new google.maps.LatLng(coords[1], coords[0]); // swap lon/lat
  266. var magnitude = getjson.features[i].properties.imupressure; // get weight
  267. var boatspeed = getjson.features[i].properties.boatspeed;
  268.  
  269. var weightedLoc = {
  270. location: latLng,
  271. weight: Math.pow(2, magnitude)
  272. };
  273.  
  274. heatmapData.push(weightedLoc); // append GeoJson data
  275. fitbound.push(latLng); // show GeoJson data
  276. magnitudes.push(magnitude);
  277. boatspeeds.push(boatspeed); // append boatspeed to array
  278.  
  279. // add markers to data points
  280. var marker = new google.maps.Marker({
  281. position: latLng,
  282. clickable: true,
  283. });
  284. addinfo(marker,i);
  285. markers.push(marker); //add markers to array
  286. }
  287.  
  288.  
  289.  
  290. function addinfo(marker, j) {
  291. weight[j]=magnitudes.slice(j,j+1)
  292. google.maps.event.addListener(marker, 'click', function() {
  293. document.getElementById('poly').innerHTML += '<br> point n'+ (j+1)+ '<br>Lat/Lng: n' + markers[j].getPosition()+'n <br>' +'imupressure: n' + weight.slice(j,j+1)+'n atm </br>'+'boatspeed: n'+ boatspeeds.slice(j,j+1)+'n km/hr </br>';
  294. });
  295.  
  296. }
  297.  
  298.  
  299. heatmap = new google.maps.visualization.HeatmapLayer({ //plot heatmap
  300. data: heatmapData,
  301. dissipating: false,
  302. opacity: 0.5,
  303. radius: 0.0005,
  304.  
  305. });
  306.  
  307.  
  308.  
  309.  
  310.  
  311. var bounds = new google.maps.LatLngBounds(); //create bounds
  312. for (var i = 0; i < fitbound.length; i++) {
  313. bounds.extend(fitbound[i]);
  314. }
  315.  
  316. google.maps.event.addListener(map, 'click', function() { //click to fitbounds
  317. map.fitBounds(bounds);
  318. });
  319.  
  320. var polylineLength = 0; //function calculating distance
  321. for (var i = 0; i < fitbound.length; i++) {
  322. if (i > 0) polylineLength += google.maps.geometry.spherical.computeDistanceBetween(fitbound[i], fitbound[i-1]);
  323. }
  324. showlength[0]=(polylineLength);
  325. document.getElementById('legend').innerHTML = 'i am lengend 2';
  326. }
  327.  
  328. function callback3(){
  329.  
  330.  
  331. var getjson = JSON.parse(json); //built in JSON commmand, text->JSON
  332. //var getjason = eval ("(" + json + ")"); //avoid using eval for security reasons
  333.  
  334.  
  335.  
  336. for (var i = 0; i < getjson.features.length; i++) {
  337. var coords = getjson.features[i].geometry.coordinates; // get coordinates
  338. var latLng = new google.maps.LatLng(coords[1], coords[0]); // swap lon/lat
  339. var magnitude = getjson.features[i].properties.windtemperature; // get weight
  340. var boatspeed = getjson.features[i].properties.boatspeed;
  341.  
  342. var weightedLoc = {
  343. location: latLng,
  344. weight: Math.pow(2, magnitude)
  345. //weight: (magnitude)
  346. };
  347.  
  348. heatmapData.push(weightedLoc); // append GeoJson data
  349. fitbound.push(latLng); // show GeoJson data
  350. magnitudes.push(magnitude);
  351. boatspeeds.push(boatspeed); // append boatspeed to array
  352.  
  353. // add markers to data points
  354. var marker = new google.maps.Marker({
  355. position: latLng,
  356. clickable: true,
  357. });
  358. addinfo(marker,i);
  359. markers.push(marker); //add markers to array
  360. }
  361.  
  362. function addinfo(marker, j) {
  363. weight[j] = magnitudes.slice(j,j+1)
  364. google.maps.event.addListener(marker, 'click', function() {
  365. document.getElementById('poly').innerHTML += '<br> point n'+ (j+1)+'<br> Lat/Lng: n' + markers[j].getPosition()+'n <br>' +'windtemperature: n' + weight.slice(j,j+1)+'n degrees </br>'+'boatspeed: n'+ boatspeeds.slice(j,j+1)+'n km/hr </br>';
  366. });
  367. }
  368.  
  369.  
  370. heatmap = new google.maps.visualization.HeatmapLayer({ //plot heatmap
  371. data: heatmapData,
  372. dissipating: false,
  373. opacity: 0.5,
  374. radius: 0.0005,
  375.  
  376. });
  377.  
  378.  
  379.  
  380.  
  381.  
  382. var bounds = new google.maps.LatLngBounds(); //create bounds
  383. for (var i = 0; i < fitbound.length; i++) {
  384. bounds.extend(fitbound[i]);
  385. }
  386.  
  387. google.maps.event.addListener(map, 'click', function() { //click to fitbounds
  388. map.fitBounds(bounds);
  389. });
  390.  
  391. var polylineLength = 0; //function calculating distance
  392. for (var i = 0; i < fitbound.length; i++) {
  393. if (i > 0) polylineLength += google.maps.geometry.spherical.computeDistanceBetween(fitbound[i], fitbound[i-1]);
  394. }
  395. showlength[0]=(polylineLength);
  396. document.getElementById('legend').innerHTML = 'i am lengend 3';
  397. }
  398.  
  399.  
  400. //plot heatmap
  401. function plotheatmap(){
  402. heatmap.setMap(heatmap.getMap()? null:map);
  403. }
  404.  
  405. // Show distance of sailpath.
  406. function polylineLength(){
  407. document.getElementById('poly').innerHTML+="distance: n"+showlength.toString()+"n m</br>";
  408. }
  409.  
  410. // Sets the map on all markers in the array.
  411. function setMarkers(map) {
  412. for (var i = 0; i < markers.length; i++) {
  413. markers[i].setMap(map),
  414. markers[0].setIcon("http://maps.google.com/mapfiles/ms/micons/blue.png"),
  415. markers[i].setIcon("http://cdn1.iconfinder.com/data/icons/fatcow/32x32_0440/flag_red.png"),
  416. markers[(markers.length)-1].setIcon("http://maps.google.com/mapfiles/ms/micons/yellow.png");
  417. }
  418. }
  419.  
  420. function setPath(){
  421. for (var i = 0; i < markers.length; i++){
  422. if (boatspeeds[i]>0 & boatspeeds[i]<=0.4 ){
  423. var path = [markers[i].getPosition(),markers[i+1].getPosition()];
  424. var addpath = new google.maps.Polyline({
  425. strokeColor: '#ffffff',
  426. strokeOpacity: 1.0,
  427. strokeWeight: 7,
  428. path: path
  429. });
  430. addpath.setMap(map)
  431. }
  432. else if (boatspeeds[i]>=0.5 & boatspeeds[i]<=0.9){
  433. var path = [markers[i].getPosition(),markers[i+1].getPosition()];
  434. var addpath = new google.maps.Polyline({
  435. strokeColor: '#03d10c',
  436. strokeOpacity: 1.0,
  437. strokeWeight: 7,
  438. path: path
  439. });
  440. addpath.setMap(map)
  441. }
  442. else if (boatspeeds[i]>=1 & boatspeeds[i]<=1.4){
  443. var path = [markers[i].getPosition(),markers[i+1].getPosition()];
  444. var addpath = new google.maps.Polyline({
  445. strokeColor: '#ffef00',
  446. strokeOpacity: 1.0,
  447. strokeWeight: 7,
  448. path: path
  449. });
  450. addpath.setMap(map)
  451. }
  452. else if (boatspeeds[i]>=1.5 & boatspeeds[i]<=1.9){
  453. var path = [markers[i].getPosition(),markers[i+1].getPosition()];
  454. var addpath = new google.maps.Polyline({
  455. strokeColor: '#b80000',
  456. strokeOpacity: 1.0,
  457. strokeWeight: 7,
  458. path: path
  459. });
  460. addpath.setMap(map)
  461. }
  462. }
  463. }
  464.  
  465.  
  466.  
  467. // Shows/hide any markers currently in the array.
  468. function showMarkers() {
  469. if (Mflag == 0){
  470. setMarkers(map),
  471. Mflag=1;
  472. }
  473. else if(Mflag == 1){
  474. setMarkers(null),
  475. Mflag=0;
  476. }
  477. }
  478.  
  479.  
  480. function showPath(){
  481. if (Pflag == 0){
  482. setPath(map),
  483. Pflag=1;
  484. }
  485. else if(Pflag == 1){
  486. setPath(null),
  487. Pflag=0;
  488. }
  489. }
  490.  
  491.  
  492.  
  493. //change radius
  494. function changeRadius() {
  495. heatmap.set('radius', heatmap.get('radius') ? null : 0.0005); //set radius
  496. }
  497.  
  498.  
  499. //change opacity
  500. function Opacity() {
  501. heatmap.set('opacity', heatmap.get('opacity') ? null:0.4);
  502. }
  503.  
  504. function changeGradient() {
  505. var gradient = [
  506. 'rgba(0, 255, 255, 0)',
  507. 'rgba(0, 255, 255, 0.5)',
  508. 'rgba(0, 191, 255, 1)',
  509. 'rgba(0, 127, 255, 1)',
  510. 'rgba(0, 63, 255, 1)',
  511. 'rgba(0, 0, 255, 1)',
  512. 'rgba(0, 0, 223, 1)',
  513. 'rgba(0, 0, 191, 1)',
  514. 'rgba(0, 0, 159, 1)',
  515. 'rgba(0, 0, 127, 1)',
  516. 'rgba(64, 0, 124, 1)',
  517. 'rgba(154, 0, 110, 1)',
  518. 'rgba(195, 0, 135, 1)',
  519. 'rgba(255, 0, 0, 1)'
  520. ]
  521.  
  522. heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
  523. }
  524.  
  525.  
  526. //clear all add-on layers
  527. function clearall() {
  528. heatmap.setMap(null),
  529. setMarkers(null),
  530. fitbound.length=0,
  531. markers.length=0,
  532. heatmapData.length=0,
  533. magnitudes.length=0,
  534. heatlayer.setMap(null);
  535. }
  536.  
  537. </script>
  538. </div>
  539. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement