Skip to content

Instantly share code, notes, and snippets.

@amarinelli
Created September 29, 2014 18:53
Show Gist options
  • Save amarinelli/d927fc683084e464d909 to your computer and use it in GitHub Desktop.
Save amarinelli/d927fc683084e464d909 to your computer and use it in GitHub Desktop.
Load .json file based on feature name from map click
require(["dojo/request/xhr"], function(xhr){
var category
feat = //code to get selected feature element
fcName = feat.attributes.Name;
fcType = feat.attributes.Type
//The following if statement does not cover all feature cases
//such as Ruins and Towns...
if (fcType == "City") {
category = "GoTCities"
} else if (fcType == "Castle") {
category = "GoTCastles"
} else {
category = "GoTNobleHouses"
}
xhr(["json", category, fcName + ".json"].join("/"), {
handleAs:"json"
}).then(function(data){
console.log(data);
//example usage
textArea = document.getElementById("card_id");
textArea.innerHTML = ("<p><b>" + data.name + "</b></p><p>" + data.summary + "</p>");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment