| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 3 | <head> |
| 4 | <meta http-equiv="content-type" content="text/html; charset=utf-8"/> |
| 5 | <title>Debug KGeoMap</title> |
| 6 | <script type="text/javascript"> |
| 7 | var debugTextField; |
| 8 | var codeTextField; |
| 9 | var scriptUrls = Array(); |
| 10 | var lastLoadedScript = ''; |
| 11 | var debugInitialized = false; |
| 12 | var callRunAfterInit = false; |
| 13 | function runMyScript() { |
| 14 | if (!debugInitialized) { |
| 15 | callRunAfterInit = true; |
| 16 | initializeDebug(); |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | var myCode = codeTextField.value; |
| 21 | |
| 22 | var result = eval(myCode); |
| 23 | if (result) { |
| 24 | debugTextField.value = 'Result: '+result+'\n'+debugTextField.value; |
| 25 | } |
| 26 | } |
| 27 | function kgeomapDebugHook(debugString) { |
| 28 | debugTextField.value = debugString + '\n' + debugTextField.value; |
| 29 | } |
| 30 | function clearDebugTextField() { |
| 31 | debugTextField.value = ''; |
| 32 | } |
| 33 | function initializeBackend() { |
| 34 | kgeomapDebugHook("-- Backend loaded! Calling kgeomapInitialize"); |
| 35 | kgeomapInitialize(); |
| 36 | kgeomapDebugHook("-- kgeomapInitialize called!"); |
| 37 | |
| 38 | debugInitialized = true; |
| 39 | |
| 40 | if (callRunAfterInit) { |
| 41 | runMyScript(); |
| 42 | } |
| 43 | } |
| 44 | function loadNextJavaScriptFile() { |
| 45 | |
| 46 | if (lastLoadedScript!='') { |
| 47 | kgeomapDebugHook('-- Loaded: '+lastLoadedScript); |
| 48 | lastLoadedScript = ''; |
| 49 | } |
| 50 | |
| 51 | if (scriptUrls.length==0) { |
| 52 | // all scripts loaded, continue: |
| 53 | initializeBackend(); |
| 54 | |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | var scriptUrl = scriptUrls.shift(); |
| 59 | var scriptObject = document.createElement("script"); |
| 60 | scriptObject.setAttribute("type", "text/javascript"); |
| 61 | scriptObject.setAttribute("charset", "utf-8"); |
| 62 | scriptObject.setAttribute("src", scriptUrl); |
| 63 | |
| 64 | if (scriptUrl.indexOf('loadNextJavaScriptFile')<0) { |
| 65 | scriptObject.setAttribute("onload", "loadNextJavaScriptFile();"); |
| 66 | } |
| 67 | |
| 68 | kgeomapDebugHook("-- Loading: "+scriptUrl); |
| 69 | lastLoadedScript = scriptUrl; |
| 70 | var theHeader = document.getElementsByTagName("head").item(0); |
| 71 | theHeader.appendChild(scriptObject); |
| 72 | } |
| 73 | function handleApiReady() { |
| 74 | alert('handleapiready'); |
| 75 | } |
| 76 | function loadBackendCode(backendName) { |
| 77 | |
| 78 | kgeomapDebugHook('-- Loading backend ' + backendName); |
| 79 | |
| 80 | if (backendName=='osm') { |
| 81 | scriptUrls.push('http://www.openlayers.org/api/OpenLayers.js'); |
| 82 | scriptUrls.push('http://www.openstreetmap.org/openlayers/OpenStreetMap.js'); |
| 83 | scriptUrls.push('backend-osm-js.js'); |
| 84 | } else if (backendName=='googlemaps') { |
| 85 | scriptUrls.push('http://maps.google.com/maps/api/js?sensor=false&callback=loadNextJavaScriptFile'); |
| 86 | scriptUrls.push('backend-googlemaps-js.js'); |
| 87 | } |
| 88 | |
| 89 | loadNextJavaScriptFile(); |
| 90 | } |
| 91 | function initializeDebug() { |
| 92 | debugTextField = document.getElementById("debugoutput"); |
| 93 | codeTextField = document.getElementById("codetorun"); |
| 94 | |
| 95 | document.getElementById("backendselectorform").style.display='none'; |
| 96 | |
| 97 | clearDebugTextField(); |
| 98 | |
| 99 | // determine which backend to load: |
| 100 | var backendSelector = document.getElementById("backendselector"); |
| 101 | var backendName = backendSelector.options[backendSelector.selectedIndex].value; |
| 102 | |
| 103 | loadBackendCode(backendName); |
| 104 | } |
| 105 | </script> |
| 106 | </head> |
| 107 | <body> |
| 108 | |
| 109 | <form id="backendselectorform"> |
| 110 | Backend: <select id="backendselector"><option value="osm">OpenStreetMap</option><option value="googlemaps">Google Maps</option></select> <input type="button" onclick="initializeDebug();" value="Load!"/><br/> |
| 111 | <br/> |
| 112 | </form> |
| 113 | |
| 114 | <div id="map_canvas" style="width:700px; height:400px; border: 1px solid black;"></div> |
| 115 | |
| 116 | <br/> |
| 117 | |
| 118 | <form> |
| 119 | Run code: <input type="button" value="Run!" onclick="runMyScript();"/><br/> |
| 120 | <textarea rows="5" cols="80" id="codetorun"></textarea> |
| 121 | </form> |
| 122 | |
| 123 | <br/> |
| 124 | |
| 125 | <form> |
| 126 | Debug output: <input type="button" value="Clear" onclick="clearDebugTextField();"/><br/> |
| 127 | <textarea rows="15" cols="100" id="debugoutput"></textarea> |
| 128 | </form> |
| 129 | |
| 130 | </body> |
| 131 | </html> |