-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
394 lines (335 loc) · 16.2 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Best Restaurants in Belize</title>
<meta name="description" content="Web GIS application,map,restaurants,Belize">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<!-- Place favicon.ico in the root directory -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="http://192.168.58.170/arcgis_js_api/library/3.20/3.20/esri/css/esri.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<!--[if lte IE 9]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
<![endif]-->
<div id="mapDiv">
<div id="homeButtonDiv"></div>
<div id="locateButtonDiv"></div>
<div id="legendDiv"></div>
<div id="serachDiv">
<!--AVOID when enter key ,don't reload the page-->
<form class="form-horizontal" onkeypress="return event.keyCode != 13">
<div class="form-group">
<label class="col-md-2 control-label" for="txtRestaurantName">Restaurant Name:</label>
<div class="col-md-6">
<input type="text" class="form-control" id="txtRestaurantName" placeholder="enter restaurant name">
</div>
<div class="col-md-4">
<input class="btn btn-primary" id="btnSearch" type='button' value='Query' onclick='executeQuery()'>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="selectCategories">Category:</label>
<div class="col-md-10">
<select class="form-control" id='selectCategories' onchange="onCategoryChange()">
<option value="99" selected>All</option>
<option value="0">Diner</option>
<option value="1">Restaurant</option>
<option value="2">Cafe</option>
<option value="4">Lounge</option>
<option value="3">Bar</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="selectRating">Rating:</label>
<div class="col-md-10">
<select class="form-control" id='selectRating' onchange='onRatingChange()'>
<option value="99" selected>All</option>
<option value="1">Poor</option>
<option value="2">Fair</option>
<option value="3">Average</option>
<option value="4">Good</option>
<option value="5">Excellent</option>
</select>
</div>
</div>
<div class="form-group">
<input class="btn btn-primary center-block" type='button' value='GPS Locate' onclick='showGPSLocation()'>
</div>
</form>
<div id="searchResultDiv"></div>
</div>
</div>
<script src="js/vendor/modernizr-3.5.0.min.js"></script>
<script src="js/vendor/jquery-3.2.0.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
<script src="http://192.168.58.170/arcgis_js_api/library/3.20/3.20/init.js"></script>
<script>
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
dojo.require("esri.dijit.Legend");
dojo.require("esri.dijit.HomeButton");
dojo.require("esri.dijit.LocateButton");
dojo.require("esri.dijit.Scalebar");
var global = {}; //global objects
global.map = null;
//feature service url;map service don't support web edit,won't use enterprise database
global.urls = {
restaurant: "http://192.168.58.170:6080/arcgis/rest/services//BelizeEdit/FeatureServer/0",
belizeCountry: "http://192.168.58.170:6080/arcgis/rest/services//BelizeEdit/FeatureServer/1",
reviewTable: "http://192.168.58.170:6080/arcgis/rest/services//BelizeEdit/FeatureServer/2"
}
//the POI layer
global.POILayer = null;
// category and rating default value
global.selectedCategories = 99;
global.selectedRating = 99;
//query
global.queryResults = null;
global.queryTask = null;
global.queryResults = null;
function startUp() {
//create a map with an extent
//create the spatial reference object and extent object.
var sr = new esri.SpatialReference({
wkid: 4326
});
var startExtent = new esri.geometry.Extent(-88.27, 17.47, -88.16, 17.54, sr);
global.map = new esri.Map("mapDiv", {
logo: false,
extent: startExtent
});
//add layers; NOTICE: outfields should be declared,默认只显示几个重要字段;
var layerRestaurants = new esri.layers.FeatureLayer(global.urls.restaurant, {
outFields: ["*"]
});
var layerBelizeCountry = new esri.layers.FeatureLayer(global.urls.belizeCountry, {
outFields: ["*"]
});
if (!global.POILayer) {
global.POILayer = layerRestaurants;
}
global.map.addLayers([layerBelizeCountry, layerRestaurants]); //polygon layer then point layer
//add the legend
var esriDijitLegend = new esri.dijit.Legend({
map: global.map
}, "legendDiv");
esriDijitLegend.startup();
//add the home button
var esriDijitHomeButton = new esri.dijit.HomeButton({
map: global.map
}, "homeButtonDiv");
esriDijitHomeButton.startup();
//add the locate button
esriDijitLocateButton = new esri.dijit.LocateButton({
map: global.map
}, "locateButtonDiv");
esriDijitLocateButton.startup();
//add scalebar
var scalebar = new esri.dijit.Scalebar({
map: global.map,
attachTo: "bottom-right",
// "dual" displays both miles and kilometers
// "english" is the default, which displays miles
// use "metric" for kilometers
scalebarUnit: "dual"
});
//define and add infotemplate to POI layer
/*
*1. make sure that all the to-be-showed fields should be included in featurelayer's outfields;
*2. field name is case sensitive,use the featurelayer's exact field name;
*/
var template = "<b>Name:<b>${name}<br>" +
"<b>Rating:<b>[${rating}/5]<br>" +
"<b>Offcial Website:<b><a href='${website}'>${website}</a><br>" +
"<b>Description:<b>${description}";
var infoTemplate = new esri.InfoTemplate("Attribute", template);
layerRestaurants.setInfoTemplate(infoTemplate);
//query
//Create query task
if (!global.queryTask) {
global.queryTask = new esri.tasks.QueryTask(global.urls.restaurant);
}
}
dojo.addOnLoad(startUp);
function onCategoryChange() {
var value = document.getElementById('selectCategories').value;
global.selectedCategories = value;
//call the filter
filterlayer();
}
function onRatingChange() {
var value = document.getElementById('selectRating').value;
global.selectedRating = value;
//call the filter
filterlayer();
}
function filterlayer() {
var expression = "1 = 1"; //fetch all features
if (global.selectedCategories != 99) {
expression = expression + " AND category = " + global.selectedCategories;
}
if (global.selectedRating != 99) {
expression = expression + " AND rating = " + global.selectedRating;
}
global.POILayer.setDefinitionExpression(expression);
}
function executeQuery() {
var restaurantName = document.getElementById('txtRestaurantName').value;
var query = new esri.tasks.Query();
query.outFields = ["objectid", "name", "rating"]; //feature service layer field name ,case sensitive
query.returnGeometry = true;
//support search ignoring case,arcgis desktop query sql syntax:UPPER(NAME) LIKE '%M%'
query.where = "UPPER(NAME) like '%" + restaurantName.toUpperCase() + "%'";
// query.text = restaurantName;
global.queryTask.execute(query, showResults);
}
function showResults(results) {
global.queryResults = results;
//we are going to build our result html string
var resultHtml = "";
for (var i = 0; i < results.features.length; i++) {
//for each single feature or record in the result
var feature = results.features[i];
//display the name()
resultHtml = resultHtml +
"<b>Name:</b> <a href='#' onclick='showRestaurant(" +
i +
")'>" +
feature.attributes["name"] +
"</a><Br>";
//display the rating
resultHtml = resultHtml + "<b>Rating:</b> " + feature.attributes["rating"];
//create a place holder for each review to be populated later
resultHtml = resultHtml +
"<div id = 'review" +
feature.attributes["objectid"] +
"'></div>";
//create a place holder for each attachment picture to be populated later
resultHtml = resultHtml +
"<div id = 'picture" +
feature.attributes["objectid"] +
"'></div>";
//create text box for the review marked with the objectid
resultHtml = resultHtml + "<br>Review: <input type = 'text' id = 'txtReview" + feature.attributes["objectid"] + "' > ";
//another one for the rating.
resultHtml = resultHtml + "<br>Rating: <input type = 'text' id = 'txtRating" + feature.attributes["objectid"] + "' > ";
resultHtml = resultHtml + "<form id = 'frm" +
feature.attributes["objectid"] + "'><input type = 'file' name = 'attachment'/ > </form>";
//and a button to call the function addnewreview
resultHtml = resultHtml + "<br><input type = 'button' value = 'Add' onclick ='AddNewReview(" + feature.attributes["objectid"] + ")'>";
//new line
resultHtml = resultHtml + "<br><br>";
}
//add the results to myresults element.
document.getElementById("searchResultDiv").innerHTML = resultHtml;
AddReviews(results);
AddPictures(results);
}
function showRestaurant(i) {
//get the clicked feature
if (!global.queryResults) {
console.log("no searching results");
return;
}
var feature = global.queryResults.features[i];
//mark up symbol are for points.
var symbol = new esri.symbol.SimpleMarkerSymbol();
//set the size
symbol.setSize(50);
//and the color (yellow) and transparency of 50% (0.5)
symbol.setColor(new dojo.Color([255, 255, 0, 0.5]));
//finally set the symbol to the record
feature.setSymbol(symbol);
//clear any graphics on the map
global.map.graphics.clear();
//so we only add this one
global.map.graphics.add(feature);
}
function AddReviews(results) {
for (var i = 0; i < results.features.length; i++) {
//for each single feature or record in the result
var record = results.features[i];
//Create relationship query object
var relatedReviews = new esri.tasks.RelationshipQuery();
//return all fields in the related table.
relatedReviews.outFields = ["*"];
//The relationship id is zero based on the url
relatedReviews.relationshipId = 0;
//get the object id
relatedReviews.objectIds = [record.attributes["objectid"]];
//execute the query and then call the RelationQueryCompelete
global.POILayer.queryRelatedFeatures(relatedReviews, RelationQueryCompelete);
}
}
function RelationQueryCompelete(relatedRecords) {
for (var oid in relatedRecords) {
var fset = relatedRecords[oid];
//get the first related record
var firstrecord = fset.features[0];
var review = firstrecord.attributes["review"];
var user = firstrecord.attributes["user_"]; //use the map service exact field name
//update the div id with the review and the user
document.getElementById("review" + oid).innerHTML = "<i>" + user + " comment: <br>" + review + "</i>";
}
}
function AddPictures(results) {
for (var i = 0; i < results.features.length; i++) {
//for each single feature or record in the result
var record = results.features[i];
// Attachment code goes here
global.POILayer.queryAttachmentInfos([record.attributes["objectid"]], PicturesQueryComplete);
}
}
function PicturesQueryComplete(pictures) {
//in case of no pictures quit.
if (pictures.length == 0) {
return;
}
//TODO:add all pictures; now only get the first picture
var p = pictures[0];
//set it to its place holder
document.getElementById("picture" + p.objectId).innerHTML =
"<img src = '" +
p.url +
"' width = '200px' height ='130px'>";
}
function AddNewReview(oid) {
var objectid = oid;
var review = document.getElementById('txtReview' + oid).value;
var rating = document.getElementById('txtRating' + oid).value;
var newReview = {
attributes: {
venue_objectid: objectid,
review: review,
rating: rating,
user_: "YIN Chao" // specific user
}
};
//open the review table,as we seen in chapter 4 it has an id of 2
var reviewtable = new esri.layers.FeatureLayer(global.urls.reviewTable);
//apply edits and pass the review record
reviewtable.applyEdits([newReview], null, null, null, null);
//add POI's attachment a picture
global.POILayer.addAttachment(oid,document.getElementById("frm"+oid), null, null);
alert("review has been added successfully!")
}
</script>
<!-- Google Analytics: change UA-XXXXX-Y to be your site's ID. -->
<!--
<script>
window.ga=function(){ga.q.push(arguments)};ga.q=[];ga.l=+new Date;
ga('create','UA-XXXXX-Y','auto');ga('send','pageview')
</script>
<script src="https://www.google-analytics.com/analytics.js" async defer></script>
-->
</body>
</html>