Last active
August 17, 2016 07:13
-
-
Save stevage/20942517c8e45b973df6437eb83ea77e to your computer and use it in GitHub Desktop.
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
<!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