- Timestamp:
- 03/05/2019 03:14:44 PM (7 years ago)
- Location:
- trunk/src/cptms
- Files:
-
- 4 added
- 1 moved
-
GreenLights.otf (added)
-
cgi-bin (added)
-
cgi-bin/saveMessage.py (added)
-
cms_demo.html (moved) (moved from trunk/src/cptms/kmldemo1.html) (5 diffs)
-
messagefile.txt (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cptms/cms_demo.html
r294 r295 7 7 <title>KML Click Demo</title> 8 8 <style> 9 @font-face { 10 font-family: GreenLights; 11 src: url('GreenLights.otf'); 12 } 9 13 html, body { 10 14 height: 370px; … … 14 18 #map { 15 19 height: 560px; 16 width: 500px;20 width: 100%; 17 21 overflow: hidden; 18 float: left;19 22 border: thin solid #333; 20 23 } 21 #cms- message {22 height: 90px;23 width: 250px;24 #cms-name { 25 height: 30px; 26 width: 350px; 24 27 overflow: hidden; 25 float: left;26 28 background-color: #ECECFB; 27 29 border: thin solid #333; 28 30 border-left: none; 29 31 } 32 #cms-message { 33 height: 90px; 34 width: 550px; 35 overflow: hidden; 36 float: left; 37 border: thin solid #333; 38 border-left: none; 39 font-family: GreenLights; 40 font-size: xx-large; 41 background-color: black; 42 color: GoldenRod; 43 } 30 44 #userinput { 31 45 height: 90px; 32 width: 250px;46 width: 175px; 33 47 overflow: hidden; 34 float: left;35 48 background-color: #ECECFB; 36 49 border: thin solid #333; … … 40 53 </head> 41 54 <body> 42 <div id=" map"></div>55 <div id="cms-name" style="display: none;"></div> 43 56 <div id="cms-message" style="display: none;"></div> 44 57 <div id="userinput" style="display: none;"> 45 <input id='userReply' type='text' /> 58 <input id='userReply' type='text' /> 59 <input id='cmsID' value="" type='hidden'/> 46 60 <button onclick="handleSubmit();">Submit</button> 47 61 </div> 62 <div id="map"></div> 48 63 <script> 49 64 var centerPoint = {lat: 33.693385, lng: -117.798937}; 50 65 var map; 51 var src="https://raw.githubusercontent.com/jdalbey/map-spikes/master/cms_single_dyer_rd.kml"; 66 //var src="http://git.tokomak.net:8888/raw-attachment/ticket/75/dyer1.txt" 67 var src="https://raw.githubusercontent.com/jdalbey/map-spikes/master/cms_two_signs.kml"; 68 52 69 // var src = "https://www.arb.ca.gov/smp/met/kml/faa.kml"; 53 70 // var src="https://raw.githubusercontent.com/jdalbey/map-spikes/master/la_airports.kml" … … 62 79 var kmlLayer = new google.maps.KmlLayer(src, { 63 80 suppressInfoWindows: true, 64 preserveViewport: true, // false for zoom to placemarks81 preserveViewport: false, // false for zoom to placemarks 65 82 map: map 66 83 }); 67 84 kmlLayer.addListener('click', function(event) { 68 85 // grab description from kml file 69 var content = event.featureData.infoWindowHtml; 70 var cmsMsg = document.getElementById('cms-message'); 71 cmsMsg.innerHTML = content; // assign current msg to display 72 cmsMsg.style.display = 'block' 86 var feature = event.featureData; 87 //var content = event.featureData.infoWindowHtml; 88 var cmsName = document.getElementById('cms-name'); 89 cmsName.innerHTML = feature.name; // put sign name in display 90 cmsName.style.display = 'block' 91 cmsID = feature.id 92 getMessage(cmsID); // note: this is async 73 93 var userReply = document.getElementById('userReply'); 74 userReply.value = ""; // clear the response area 94 userReply.value = "" // clear the response area 95 document.getElementById('cmsID').value=cmsID ; 75 96 var userInput = document.getElementById('userinput'); 76 97 userInput.style.display = 'block' 98 console.log("clicked on: "+feature.id+" - " + feature.name); 77 99 }); 78 100 } … … 82 104 document.getElementById('cms-message').style.display = 'none' 83 105 document.getElementById('userinput').style.display = 'none' 106 document.getElementById('cms-name').style.display = 'none' 84 107 // recover the user's response 85 108 var response = document.getElementById('userReply').value; 86 alert("Message update: " +response);109 saveMessage(response); 87 110 } 111 112 function loadJSON(inFile,callback) { 113 114 var xobj = new XMLHttpRequest(); 115 xobj.overrideMimeType("application/json"); 116 xobj.open('GET', inFile, true); 117 xobj.onreadystatechange = function () { 118 if (xobj.readyState == 4 && xobj.status == "200") { 119 callback(xobj.responseText); 120 } 121 }; 122 // We want ajax to ignore any cached responses 123 xobj.setRequestHeader('If-Modified-Since', 'Sat, 01 Jan 2000 01:01:01 GMT') 124 xobj.send(null); 125 } 126 var messageList; 127 // retrieve the current cms message file 128 function getMessage(cmsID) 129 { 130 loadJSON("messagefile.txt",function(response) 131 { 132 // Parse JSON string into object 133 messageList = JSON.parse(response); 134 // TODO: select a message from json for the given cmsID 135 console.log("get by cmsID="+cmsID); 136 var cmsSign = document.getElementById('cms-message'); 137 if (cmsSign.length==0) cmsSign = " "; 138 cmsSign.innerHTML = messageList[cmsID]; 139 cmsSign.style.display = 'block' 140 }); 141 } 142 // Save an updated cms message to the file 143 // NB: cms id's are one-based, json array is zero-based. 144 function saveMessage(outMessage,cmsID) 145 { 146 var cmsID = document.getElementById('cmsID').value; 147 console.log("Saving " + outMessage + " for cmsID " + cmsID) 148 messageList[cmsID] = outMessage; 149 var xhttp = new XMLHttpRequest(); 150 xhttp.open("GET", "/cgi-bin/saveMessage.py?msg="+JSON.stringify(messageList), true); 151 xhttp.send(); 152 153 // Using POST might be a better idea ... haven't tried this yet 154 // var xhr = new XMLHttpRequest(); 155 // xhr.open("POST", "/cgi-bin/saveMessage.py?", true); 156 // xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 157 158 // send the collected data as JSON 159 // xhr.send(JSON.stringify(messageList)); 160 } 161 88 162 </script> 89 163 <script async defer
Note: See TracChangeset
for help on using the changeset viewer.
