Skip to content

Instantly share code, notes, and snippets.

@stevage
Last active August 17, 2016 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevage/20942517c8e45b973df6437eb83ea77e to your computer and use it in GitHub Desktop.
Save stevage/20942517c8e45b973df6437eb83ea77e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<body>
<iframe id="embedded-national-map" frameBorder="0" width="1200" height="600" src="http://nationalmap.gov.au/#clean"></iframe>
<script>
var xhr2 = new XMLHttpRequest();
xhr2.open('GET', 'polygon.geojson', true);
xhr2.onload = function() {
if (xhr2.status === 200) {
if (xhr2.response) {
var item = {
type: 'geojson',
name: 'geojson polygon',
isEnabled: true,
data: xhr2.response
}
addToMap(item);
}
}
}
xhr2.onerror = function(e) { throw e; };
xhr2.send();
function addToMap(item) {
window.addEventListener('message', function(e) {
var iframeWindow = document.getElementById('embedded-national-map').contentWindow;
if (e.source === iframeWindow && e.data === 'ready') {
iframeWindow.postMessage({
initSources: [{catalog: [{
type: "group",
name: "Additional Data",
items: [item]
}]}]
}, 'http://nationalmap.gov.au/');
}
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment