diff --git a/worldmap/worldmap.js b/worldmap/worldmap.js index 26e3b79..12a50f7 100644 --- a/worldmap/worldmap.js +++ b/worldmap/worldmap.js @@ -54,6 +54,32 @@ var iconSz = { "Command": 44 }; +var filesAdded = ''; + +var loadStatic = function(fileName){ + if(filesAdded.indexOf(fileName) !== -1) + return + var head = document.getElementsByTagName('head')[0] + if(fileName.indexOf('js') !== -1) { + var script = document.createElement('script') + script.src = fileName + script.type = 'text/javascript' + console.log("Loading: ",fileName) + head.append(script) + filesAdded += ' ' + fileName + } else if (fileName.indexOf('css') !== -1) { + var style = document.createElement('link') + style.href = fileName + style.type = 'text/css' + style.rel = 'stylesheet' + console.log("Loading: ",fileName) + head.append(style); + filesAdded += ' ' + fileName + } else { + console.log("Unsupported file type: ",fileName) + } +} + // L.PM.setOptIn(true); // Create the socket @@ -2899,6 +2925,19 @@ function doCommand(cmd) { } } } + if (cmd.hasOwnProperty("loadStatic")) { + console.log("load Static files",JSON.stringify(cmd.loadStatic.fileNames)); + cmd.loadStatic.fileNames.forEach(fileName => loadStatic(fileName)); + } + if (cmd.hasOwnProperty("customCmd")) { + console.log("custom Command",JSON.stringify(cmd.customCmd)); + try { + eval(cmd.customCmd); + } + catch (e) { + console.log("ERR - custom command: ", JSON.stringify(cmd.customCmd)); + } + } } // handle any incoming GEOJSON directly - may style badly