Created
September 29, 2014 18:53
-
-
Save amarinelli/d927fc683084e464d909 to your computer and use it in GitHub Desktop.
Load .json file based on feature name from map click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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