-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
139 lines (123 loc) · 3.95 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
<!DOCTYPE html>
<html>
<head>
<title>DEQ Spills Widget</title>
</head>
<body>
<!-- styling demo -->
<style type="text/css">
.agrc-app,
body,
html {
height: 700px;
width: 620px;
}
</style>
<!-- required widget div and .js file -->
<div id="AGRCMap"></div>
<!-- build:template:prod
<script>var apiKey = 'AGRC-67369981957692'; // deqspills.ugrc.utah.gov </script>
/build -->
<!-- build:template:stage
<script>var apiKey = 'AGRC-95AC5682168353'; // *.dev.utah.gov </script>
/build -->
<!-- build:template:dev
<script>var apiKey = 'AGRC-63E1FF17767822'; // localhost </script>
/build -->
<!-- build:remove -->
<script>
var apiKey = "AGRC-E5B94F99865799"; // localhost
</script>
<!-- /build -->
<script>
const eventName = "widget-loaded";
const widgetLoadedEvent = new Event(eventName);
let iframeId;
function processMessage(event) {
// don't really care about origin check because there's not much that can be done on this side
console.log("iframe: message received:", event);
if (!Object.hasOwn(event.data, 'iframeId')) {
// ignore messages from other sources
return;
}
if (!iframeId && event.data.iframeId) {
iframeId = event.data.iframeId;
} else if (iframeId && event.data.iframeId !== iframeId) {
// ignore messages from other sources
return;
}
if (window.widgetIsLoaded) {
initializeWidget(event.data);
} else {
window.addEventListener(eventName, function () {
initializeWidget(event.data);
});
}
}
window.addEventListener("message", processMessage);
window.agrcOnLoad = function () {
window.dispatchEvent(widgetLoadedEvent);
window.widgetIsLoaded = true;
if (window.location === window.parent.location) {
// this is not an iframe
initializeWidget({
UTM_X: '424000',
UTM_Y: '4510000',
targetOrigin: '*'
});
window.removeEventListener("message", processMessage)
}
};
function initializeWidget(props) {
console.log("iframe: initializeWidget:", props);
var app = new AGRCMap(
{
UTM_X: props?.UTM_X,
UTM_Y: props?.UTM_Y,
apiKey: apiKey,
// this prevents the widget from re-defining a location on load
skipDefine: props?.UTM_X ? true : false
},
document.getElementById("AGRCMap")
);
// must always call startup
app.startup();
app.on("location-defined", function (result) {
console.log("location-defined:", result);
const data = {
ADDRESS: result.ADDRESS,
CITY: result.CITY,
COUNTY: result.COUNTY,
DD_LAT: result.DD_LAT,
DD_LONG: result.DD_LONG,
HIGHWAY: result.HIGHWAY,
INDIAN: result.INDIAN,
MILEMARKER: result.MILEMARKER,
OWNER_AGENCY: result.OWNER_AGENCY,
UTM_X: result.UTM_X,
UTM_Y: result.UTM_Y,
ZIP: result.ZIP,
iframeId
};
console.log('data', JSON.stringify(data, null, 2));
window.parent.postMessage(data, props?.targetOrigin);
});
}
</script>
<script type="text/javascript" src="EmbeddedMapLoader.js"></script>
<!-- <script type='text/javascript' src='https://deqspills.dev.utah.gov/EmbeddedMapLoader.js'></script> -->
<!-- Google tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-PECSFZVT9S"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "G-PECSFZVT9S");
</script>
</body>
</html>