var csInterface = new CSInterface();

csInterface.addEventListener(
    "com.markusbergelt.geolayers2.dlg_simpleAlert", 
    function(event) {
        dlg_simpleAlert(event.data.title, event.data.description);
    }
)

csInterface.addEventListener(
    "com.markusbergelt.geolayers2.downloadFile", 
    function(event) {
        downloadFilePromise(event.data.sourceURI, event.data.destination).then(function(pathToFile){
            csInterface.evalScript('mb_GEOlayers2HostInterface.runAsyncJob(' + JSON.stringify(event.data.callbackJobID) + "," + JSON.stringify(pathToFile) + ');');
        }).catch(function(reason){
            console.log(reason)
            csInterface.evalScript('mb_GEOlayers2HostInterface.cancelAsyncJob(' + JSON.stringify(event.data.callbackJobID) + ');');
        })
    }
)

csInterface.addEventListener(
    "com.markusbergelt.geolayers2.consoleLog", 
    function(event) {
        console.log(event.data.toLog);
    }
)
csInterface.addEventListener(
    "com.markusbergelt.geolayers2.applyStyleset", 
    function(event) {
        var newStyleset = event.data;
        angular.element($("#baseController")).scope().applyStyleset(newStyleset, true)
    }
)
csInterface.addEventListener(
    "com.markusbergelt.geolayers2.setPropsInPrefs", 
    function(event) {
        angular.extend(preferences, event.data)
    }
)

csInterface.addEventListener(
    "com.markusbergelt.geolayers2.updateProgressbar", 
    function(event) {
        updateProgressbar(event.data.percentage, event.data.style, event.data.description);
    }
)
    
