-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
224 lines (213 loc) · 9.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<!-- Use Chrome Frame in IE -->
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Example of how to embed NationalMap in an iframe on your website">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- <link rel="apple-touch-icon" sizes="57x57" href="favicons/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="favicons/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="favicons/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="favicons/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="favicons/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="favicons/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="favicons/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="favicons/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="favicons/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="favicons/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicons/favicon-16x16.png">
<link rel="manifest" href="favicons/manifest.json">
<meta name="msapplication-TileColor" content="#282D32">
<meta name="msapplication-TileImage" content="favicons/ms-icon-144x144.png">
<meta name="theme-color" content="#282D32"> -->
<title>Example of embedded National Map</title>
<!-- <link rel="stylesheet" type="text/css" href="style.css"> -->
<style>
#embedded-national-map {
width: 100%;
height: 100%;
border: none;
}
h1 {
font-family: sans-serif;
color: rgb(0,139,169);
}
footer {
text-align: center;
font-family: sans-serif;
color: gray;
font-size: 85%;
}
</style>
</head>
<body>
<div id="pre-national-map">
<h1>National Map is embedded in this page</h1>
<p>
You can even show it zoomed to your desired location, with relevant data already selected, and custom data added.
See the code <a href="https://github.com/terriajs/embedded-natmap">here</a>.
</p>
</div>
<div id="national-map">
<iframe id="embedded-national-map" frameBorder="0" src="http://nationalmap.gov.au/"></iframe>
</div>
<div id="post-national-map">
<footer>
<p>You might have your own footer here</p>
</footer>
</div>
<script>
// Start the map at a particular location, with particular data showing,
// just by passing the parameters in through the URL.
// 'initJson' below is derived from a "share" URL, converted back to JSON.
// You could instead directly place the share URL in the iframe's "src" attribute.
var initJson = {
"version": "0.0.05",
"initSources": ["init/nm.json", {
"sharedCatalogMembers": {
"Root Group/National Data Sets": {
"isOpen": true,
"type": "group",
"parents": []
},
"Root Group/National Data Sets/Surface Water": {
"isOpen": true,
"type": "group",
"parents": ["Root Group/National Data Sets"]
},
"Root Group/National Data Sets/Surface Water/Bores": {
"nowViewingIndex": 0,
"isEnabled": true,
"isShown": true,
"isLegendVisible": true,
"opacity": "0.94",
"keepOnTop": false,
"type": "esri-mapServer",
"parents": ["Root Group/National Data Sets", "Root Group/National Data Sets/Surface Water"]
},
"Root Group/National Data Sets/Surface Water/Catchment": {
"nowViewingIndex": 1,
"isEnabled": true,
"isShown": true,
"isLegendVisible": true,
"opacity": "0.49",
"keepOnTop": false,
"type": "wms",
"parents": ["Root Group/National Data Sets", "Root Group/National Data Sets/Surface Water"]
},
"Root Group/National Data Sets/Surface Water/Rivers": {
"nowViewingIndex": 4,
"isEnabled": true,
"isShown": true,
"isLegendVisible": true,
"opacity": "0.62",
"keepOnTop": false,
"type": "esri-mapServer",
"parents": ["Root Group/National Data Sets", "Root Group/National Data Sets/Surface Water"]
},
"Root Group/National Data Sets/Surface Water/Water Pipelines": {
"nowViewingIndex": 3,
"isEnabled": true,
"isShown": true,
"isLegendVisible": true,
"opacity": "1",
"keepOnTop": false,
"type": "esri-mapServer",
"parents": ["Root Group/National Data Sets", "Root Group/National Data Sets/Surface Water"]
},
"Root Group/National Data Sets/Surface Water/Water Storage": {
"nowViewingIndex": 2,
"isEnabled": true,
"isShown": true,
"isLegendVisible": true,
"opacity": "0.43",
"keepOnTop": false,
"type": "wms",
"parents": ["Root Group/National Data Sets", "Root Group/National Data Sets/Surface Water"]
}
}
}, {
"initialCamera": {
"west": 141.93,
"south": -38.46,
"east": 146.20,
"north": -35.94
},
"homeCamera": {
"west": 109,
"south": -45,
"east": 158,
"north": -8
},
"baseMapName": "Australian Topography",
"viewerMode": "2d"
}]
};
var activeTabId = 'NowViewing';
var iFrame = document.getElementById('embedded-national-map');
iFrame.src = iFrame.src + '#start=' + encodeURIComponent(JSON.stringify(initJson)) + '&activeTabId=' + activeTabId;
// Add our own data to the map using an iframe message.
// See https://github.com/TerriaJS/terriajs/wiki/Controlling-TerriaJS-in-an-iframe-by-posting-it-messages for details.
window.addEventListener('message', function(e) {
var iframeWindow = document.getElementById('embedded-national-map').contentWindow;
if (e.source === iframeWindow && e.data === 'ready') {
// NationalMap is ready to receive messages!
iframeWindow.postMessage({
initSources: [
{
catalog: [
{
type: "group",
name: "Nice Areas",
isPromoted: true,
isOpen: true,
items: [
{
type: "csv",
name: "Nice areas",
data: "POA,Description\n3429,Sunbury\n3550,Bendigo\n3350,Ballarat",
isEnabled: true
}
]
}
]
}
]
}, 'http://nationalmap.gov.au');
}
});
function recursiveMarginTop(element) {
return parseInt(getComputedStyle(element).marginTop) + (element.children.length > 0 ? recursiveMarginTop(element.children[0]) : 0);
}
function recursiveMarginBottom(element) {
return parseInt(getComputedStyle(element).marginBottom) + (element.children.length > 0 ? recursiveMarginBottom(element.children[element.children.length - 1]) : 0);
}
function fullOuterHeight(element) {
var height = element.offsetHeight;
var style = getComputedStyle(element);
height += parseInt(style.marginTop) + parseInt(style.marginBottom);
// Add the margin-top of the first child, and margin-bottom of the last, recursing all the way down.
if (element.children.length > 0) {
height += recursiveMarginTop(element.children[0]);
height += recursiveMarginBottom(element.children[element.children.length - 1]);
}
return height;
}
function resizeIFrame() {
var windowHeight = window.innerHeight;
var preHeight = document.getElementById('national-map').offsetTop;
var postHeight = fullOuterHeight(document.getElementById('post-national-map'));
var bodyMarginBottom = parseInt(getComputedStyle(document.body).marginBottom);
var iFrameHeight = windowHeight - preHeight - postHeight - bodyMarginBottom;
document.getElementById('national-map').setAttribute('style', 'height:' + iFrameHeight + 'px');
document.getElementById('national-map').style.height = iFrameHeight + 'px';
}
window.addEventListener('resize', resizeIFrame, false);
resizeIFrame();
</script>
</body>
</html>