-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhackathonattempt2.html
217 lines (192 loc) · 7.2 KB
/
hackathonattempt2.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title></title>
<link rel="stylesheet" href="http://js.arcgis.com/3.8/js/dojo/dijit/themes/tundra/tundra.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
#map { height: 100%; margin: 0; overflow: hidden; padding: 0; position: relative; }
#footer {
height: 160px;
}
#info {
color: #666;
padding: 10px;
font-family: sans-serif;
width: 960px;
margin: 0 auto;
}
#info h3 {
color: #E4A54F;
margin: 0;
padding: 0 0 5px 0;
}
#info hr {
border: 1px solid #666;
}
#popWrapper {
float: right;
}
#totalPop {
font-weight: bold;
}
.ds { background: #000; overflow: hidden; position: absolute; z-index: 2; bottom: 0; }
#ds-h div { width: 100%; }
#ds .o1 { filter: alpha(opacity=10); opacity: .1; }
#ds .o2 { filter: alpha(opacity=8); opacity: .08; }
#ds .o3 { filter: alpha(opacity=6); opacity: .06; }
#ds .o4 { filter: alpha(opacity=4); opacity: .04; }
#ds .o5 { filter: alpha(opacity=2); opacity: .02; }
#ds .h1 { height: 1px; }
#ds .h2 { height: 2px; }
#ds .h3 { height: 3px; }
#ds .h4 { height: 4px; }
#ds .h5 { height: 5px; }
</style>
<script src="http://js.arcgis.com/3.8/"></script>
<script>
var map, kml, kmlGeoms, bufferGraphics, gp;
require([
"esri/map", "esri/layers/KMLLayer", "esri/layers/GraphicsLayer",
"esri/SpatialReference", "esri/graphic",
"esri/tasks/GeometryService", "esri/tasks/Geoprocessor",
"esri/tasks/BufferParameters", "esri/tasks/FeatureSet",//"esri/dijit/LocateButton",
"esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "esri/config",
"dojo/parser", "dojo/_base/array", "dojo/_base/Color", "dojo/_base/connect",
"dojo/number", "dojo/dom", "dojo/dom-style", "dojo/dom-attr",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function(
Map, KMLLayer, GraphicsLayer,
SpatialReference, Graphic,
GeometryService, Geoprocessor,
BufferParameters, FeatureSet,
SimpleFillSymbol, SimpleLineSymbol, esriConfig,
parser, arrayUtils, Color, connect,
number, dom, domStyle, domAttr
) {
//This sample requires a proxy page to handle communications with the ArcGIS Server services. You will need to replace the url below with the location of a proxy on your machine. See the 'Using the proxy page' help topic for details on setting up a proxy page.
esriConfig.defaults.io.proxyUrl = "/proxy";
esriConfig.defaults.io.alwaysUseProxy = false;
map = new Map("map", {
center: [-6.259810, 53.344403],
zoom: 20,
basemap: "streets"
});
/*geoLocate = new LocateButton({
map: map
}, "LocateButton");
geoLocate.startup();*/
parser.parse();
// Graphics layer for the buffer
bufferGraphics = new GraphicsLayer();
map.addLayer(bufferGraphics);
debugger;
var kmlUrl = "http://dublinked.ie/datastore/local/OSM/food-drink.kml";
kml = new KMLLayer(kmlUrl);
map.addLayer(kml);
kml.on("load", function(evt) {
// Collect the line features from the KML layer
kmlGeoms = arrayUtils.map(evt.layer.getLayers()[0].graphics, function(g) {
return g.geometry;
});
// Send to a function to do the buffer
bufferKML();
});
// Re-calculate the buffer and population when buffer distance changes
connect.connect(dom.byId("bufferDistance"), "onchange", bufferKML);
function bufferKML() {
bufferGraphics.clear();
dom.byId("totalPop").innerHTML = "";
domStyle.set("loading", "display", "inline-block");
domAttr.set("bufferDistance", "disabled", true);
var bufferDistance = dom.byId("bufferDistance").value;
var params = new BufferParameters();
params.geometries = kmlGeoms;
params.distances = [ bufferDistance ];
params.bufferSpatialReference = new SpatialReference({ "wkid": 102100 });
params.outSpatialReference = map.spatialReference;
params.unit = GeometryService.UNIT_STATUTE_MILE;
params.unionResults = true;
//This service is for development and testing purposes only. We recommend that you create your own geometry service for use within your applications.
var gsUrl = "http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer";
var gs = new GeometryService(gsUrl);
gs.buffer(params, showBuffer);
}
function showBuffer(buffer) {
// Add the buffer graphic to the map
var polySym = new SimpleFillSymbol()
.setColor(new Color([56, 102, 164, 0.4]))
.setOutline(
new SimpleLineSymbol()
.setColor(new Color([56, 102, 164, 0.8]))
);
var bufferGraphic = new Graphic(buffer[0], polySym);
bufferGraphics.add(bufferGraphic);
// Send buffer to runction to calculate population
calcPop(bufferGraphic);
}
function calcPop(aoi) {
// Create a feature set for the population zonal stats GP service
var fset = new FeatureSet();
fset.features = [aoi];
var params = { "inputPoly": fset };
gp.execute(params, handlePop);
}
function handlePop(result) {
if ( result[0] && result[0].value.features[0].attributes.hasOwnProperty('SUM') ) {
var pop = number.format((result[0].value.features[0].attributes.SUM).toFixed() + '');
dom.byId('totalPop').innerHTML = pop;
} else {
alert("Unable to get population summary. Please try again.");
}
domStyle.set("loading", "display", "none");
domAttr.set("bufferDistance", "disabled", false);
}
});
</script>
</head>
<body class="tundra">
<div data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline',gutters:false"
style="width: 100%; height: 100%; margin: 0;">
<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'">
<div id="ds"> <!-- drop shadow divs -->
<div id="ds-h">
<div class="ds h1 o1"></div>
<div class="ds h2 o2"></div>
<div class="ds h3 o3"></div>
<div class="ds h4 o4"></div>
<div class="ds h5 o5"></div>
</div>
</div> <!-- end drop shadow divs -->
</div>
<div id="footer"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'bottom'">
<div id="info">
<h3>Hello there</h3>
<hr />
<div id="feedback">
Buffer Distance (miles):
<select id="bufferDistance">
<option selected>1</option>
<option>3</option>
<option>5</option>
</select>
<div id="popWrapper">
Approximately
<span id="loading"><img src="images/loading_orange.gif" /> </span>
<span id="totalPop"></span>
people within buffer.
</div>
</div>
</div>
</div>
</div>
</body>
</html>