-
Notifications
You must be signed in to change notification settings - Fork 0
/
city.js
558 lines (531 loc) · 14.4 KB
/
city.js
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
/*
* Copyright (c) 2014
*
* File: map.js
* Description: Java script that zooms to City extent and show statistical information.
*/
Ext.require([
'Ext.container.Viewport',
'Ext.window.MessageBox',
'GeoExt.panel.Map',
'GeoExt.container.WmsLegend',
'GeoExt.container.UrlLegend',
'GeoExt.container.VectorLegend',
'GeoExt.panel.Legend'
]);
Ext.application({
name: 'UrbanInformationSystem',
launch: function(){
var map;
var mappanel;
var google_var;
var google_hybrid;
var google_physical;
var google_streets;
var google_satellite;
var google_terrain;
var osm;
var context;
var template;
var selTemplate;
var style;
var selStyle;
var jsonURL;
var vecLayer;
var code0;
var code1;
var code2;
var cityname;
var city_ext_wfs;
var layname;
var r2010;
var r2005;
var r2000;
var vecpol;
var rpop2010;
var rpop2015;
var r2000;
var records = [];
var store;
var cnt90=0, cnt100=0, cnt105=0, cnt110=0;
var area90=0, area100=0, area105=0, area110=0;
var ChartArea, ChartGrowth, ChartCluster;
var viewport;
var chartWidth = 250, chartHeight=140;
var opa = 0.75;
//Get paramater values
code0 = getParameterByName('id_0');
code1 = getParameterByName('id_1');
code2 = getParameterByName('id_2');
cityname = getParameterByName('name');
//Get City Extent
city_ext_wfs = new OpenLayers.Layer.Vector(
"City Extent",
{
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.WFS({
url: "/geoserver/adburbaninfo/ows",
version: "1.1.0",
featureType: "gadm2",
featureNS: "http://www.adburbaninfo.org",
srsName: "EPSG:4326"
}),
filter: new OpenLayers.Filter.Logical({
type: OpenLayers.Filter.Logical.AND,
filters: [
new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "id_2", //city
value: code2
}),
new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "id_1", //province or region
value: code1
}),
new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "id_0", //country
value: code0
}),
]
}),
eventListeners: {
'loadend': function (evt) {
map.zoomToExtent(city_ext_wfs.getDataExtent().transform(
new OpenLayers.Projection("EPSG:4326"),
new OpenLayers.Projection("EPSG:900913")
));
}
}
}
);
map = new OpenLayers.Map(
"map-id",
{projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG: 4326"),
units: 'degrees'}
);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.ScaleLine());
map.addControl(new OpenLayers.Control.MousePosition());
//GoogleMap Base Layers
google_var = new OpenLayers.Layer.Google(
"Google LayerName",
{type: google.maps.MapTypeId.BaseLayer}
);
google_hybrid = new OpenLayers.Layer.Google(
"Google Hybrid",
{type: google.maps.MapTypeId.HYBRID}
);
google_physical = new OpenLayers.Layer.Google(
"Google Physical",
{type: google.maps.MapTypeId.PHYSICAL}
);
google_satellite = new OpenLayers.Layer.Google(
"Google Satellite",
{type: google.maps.MapTypeId.SATELLITE}
);
google_streets = new OpenLayers.Layer.Google(
"Google Streets",
{type: google.maps.MapTypeId.STREETS}
);
google_terrain = new OpenLayers.Layer.Google(
"Google Terrain",
{type: google.maps.MapTypeId.TERRAIN}
);
//needs projection(wgs84:4326 to mercator:3857), offset by > 11km vs wgs84
osm = new OpenLayers.Layer.OSM();
context = {
getColor: function(feature) {
return 'blue';
},
getName: function(feature) {
return feature.attributes.name;
}
};
template = {
"title": "City",
"cursor": "pointer",
"fillOpacity": 0.5,
"fillColor": "${getColor}",
"pointRadius": 5,
"strokeWidth": 1,
"strokeOpacity": 1,
"strokeColor": "${getColor}",
"graphicName": "triangle",
"graphicTitle": "${getName}"
};
selTemplate = {
"cursor": "pointer",
"fillOpacity": 1,
"fillColor": "${getColor}",
"pointRadius": 5,
"strokeWidth": 1,
"strokeOpacity": 1,
"strokeColor": "${getColor}",
"graphicName": "triangle",
"graphicTitle": "${getName}"
};
style = new OpenLayers.Style(template, {context: context});
selStyle = new OpenLayers.Style(selTemplate, {context: context});
jsonURL = "../../../geoserver/adburbaninfo/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=adburbaninfo:city&maxFeatures=50&outputFormat=json";
cityVec = new OpenLayers.Layer.Vector("City", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: jsonURL,
format: new OpenLayers.Format.GeoJSON()
}),
styleMap: new OpenLayers.StyleMap({
'default': style,
'select': selStyle
}),
projection: new OpenLayers.Projection("EPSG:4326")
});
//Overlays Layer
//Landsat Layers
layname = 'adburbaninfo:' + 'r_' + code0
+ '_' + code1
+ '_' + code2 + '_2010';
r2010 = new OpenLayers.Layer.WMS(
"Landsat 2010",
"http://localhost:8080/geoserver/adburbaninfo/wms",
{layers: layname, transparent: "true", format: "image/png"},
{opacity: opa, isBaseLayer: false}
);
layname = 'adburbaninfo:' + 'r_' + code0
+ '_' + code1
+ '_' + code2 + '_2005';
r2005 = new OpenLayers.Layer.WMS(
"Landsat 2005",
"http://localhost:8080/geoserver/adburbaninfo/wms",
{layers: layname, transparent: "true", format: "image/png"},
{opacity: opa, isBaseLayer: false}
);
layname = 'adburbaninfo:' + 'r_' + code0
+ '_pop10';
rpop2010 = new OpenLayers.Layer.WMS(
"Population 2010",
"http://localhost:8080/geoserver/adburbaninfo/wms",
{layers: layname, transparent: "true", format: "image/png"},
{opacity: opa, isBaseLayer: false}
);
layname = 'adburbaninfo:' + 'r_' + code0
+ '_pop15';
rpop2015 = new OpenLayers.Layer.WMS(
"Population 2015",
"http://localhost:8080/geoserver/adburbaninfo/wms",
{layers: layname, transparent: "true", format: "image/png"},
{opacity: opa, isBaseLayer: false}
);
layname = 'adburbaninfo:' + 'r_' + code0
+ '_pop20';
rpop2020 = new OpenLayers.Layer.WMS(
"Population 2020",
"http://localhost:8080/geoserver/adburbaninfo/wms",
{layers: layname, transparent: "true", format: "image/png"},
{opacity: opa, isBaseLayer: false}
);
layname = 'adburbaninfo:' + 'r_' + code0
+ '_' + code1
+ '_' + code2 + '_2000';
r2000 = new OpenLayers.Layer.WMS(
"Landsat 2000",
"http://localhost:8080/geoserver/adburbaninfo/wms",
{layers: layname, transparent: "true", format: "image/png"},
{opacity: opa, isBaseLayer: false}
);
layname = 'adburbaninfo:' + 'r_' + code0
+ '_' + code1
+ '_' + code2;
vecpol = new OpenLayers.Layer.WMS(
"Classification",
"http://localhost:8080/geoserver/adburbaninfo/wms",
//{layers: layname, style: "adburbaninfo:polygon_year_color3", transparent: "true", format: "image/png"},
{layers: layname, transparent: "true", format: "image/png"},
{opacity: opa, isBaseLayer: false}
);
r2000.setVisibility(false);
r2005.setVisibility(false);
r2010.setVisibility(false);
rpop2015.setVisibility(false);
rpop2010.setVisibility(false);
rpop2020.setVisibility(false);
map.addLayers([r2000, r2005, r2010, rpop2010, rpop2015, rpop2020, vecpol, cityVec, city_ext_wfs, osm, google_hybrid, google_physical, google_satellite, google_streets, google_terrain]);
//URL for Ajax request
layname = 'adburbaninfo:' + 'v_' + code0
+ '_' + code1
+ '_' + code2;
jsonURL = "../../../geoserver/adburbaninfo/ows?service=WFS&version=1.0.0&request=GetFeature&typeName="+layname+"&outputFormat=json";
//create extjs store with empty data
store = Ext.create('Ext.data.Store',{
fields : ['name','data1', 'data2', 'data3'],
data: records,
paging : false
});
Ext.Ajax.request({
loadMask: true,
url: jsonURL,
params: {id: "1"},
success: function(response, callOptions) {
var obj, i, gridcode, area;
obj = Ext.decode(response.responseText);
//console.dir(obj);
//console.log(obj);
//console.log("Polygon Count = " +obj.features.length);
for(i=0;i < obj.features.length; i++)
{
gridcode = obj.features[i].properties.gridcode;
area = obj.features[i].properties.AREA;
switch (gridcode) {
case 90:
cnt90++;
area90+=area;
break;
case 100:
cnt100++;
area100+=area;
break;
case 105:
cnt105++;
area105+=area;
break;
case 110:
cnt110++;
area110+=area;
break;
}
}
//Convert the AREA unit from sqm to sqkm
area90/=1000000;
area100/=1000000;
area105/=1000000;
area110/=1000000;
//console.log("1990, clusters = "+cnt90+", area = " +area90+", growth = 0");
//console.log("2000, clusters = "+cnt100+", area = " +area100+", growth = " +area100/(area90+area100)*100);
//console.log("2005, clusters = "+cnt105+", area = " +area105+", growth = " +area105/(area90+area100+area105)*100);
//console.log("2010, clusters = "+cnt110+", area = " +area110+", growth = " +area110/(area90+area100+area105+area110)*100);
records.push({
name: '1990',
data1: area90,
data2: 0,
data3: cnt90
});
records.push({
name: '2000',
data1: area90+area100,
data2: area100/(area90+area100)*100,
data3: cnt90+cnt100
});
records.push({
name: '2005',
data1: area90+area100+area105,
data2: area105/(area90+area100+area105)*100,
data3: cnt90+cnt100+cnt105
});
records.push({
name: '2010',
data1: area90+area100+area105+area110,
data2: area110/(area90+area100+area105+area110)*100,
data3: cnt90+cnt100+cnt105+cnt110
});
store.loadData(records);
},
failure: function(response, callOptions) {
console.log('server-side failure with status code ' + response.status);
}
});
mappanel = Ext.create('GeoExt.panel.Map', {
title: 'Urban Information Sytem',
map: map
});
ChartArea = Ext.create('Ext.chart.Chart', {
renderTo: Ext.getBody(),
width: chartWidth,
height: chartHeight,
animate: true,
store: store,
axes: [
{
type: 'Numeric',
position: 'left',
fields: 'data1',
label: {
renderer: Ext.util.Format.numberRenderer('0,0')
},
title: 'Area',
grid: true
//minimum: 0
},
{
type: 'Category',
position: 'bottom',
fields: ['name'],
title: 'Year'
}
],
series: [
{
type: 'line',
highlight: {
size: 7,
radius: 7
},
axis: 'left',
fill: true,
xField: 'name',
yField: 'data1',
markerConfig: {
type: 'circle',
size: 4,
radius: 4,
'stroke-width': 0
}
}
]
});
ChartGrowth = Ext.create('Ext.chart.Chart', {
renderTo: Ext.getBody(),
width: chartWidth,
height: chartHeight,
animate: true,
store: store,
axes: [
{
type: 'Numeric',
position: 'left',
fields: 'data2',
label: {
renderer: Ext.util.Format.numberRenderer('0,0')
},
title: 'Growth',
grid: true,
minimum: 0
},
{
type: 'Category',
position: 'bottom',
fields: ['name'],
title: 'Year'
}
],
series: [
{
type: 'line',
highlight: {
size: 7,
radius: 7
},
axis: 'left',
fill: true,
xField: 'name',
yField: 'data2',
markerConfig: {
type: 'circle',
size: 4,
radius: 4,
'stroke-width': 0
}
}
]
});
ChartCluster = Ext.create('Ext.chart.Chart', {
renderTo: Ext.getBody(),
width: chartWidth,
height: chartHeight,
animate: true,
store: store,
axes: [
{
type: 'Numeric',
position: 'left',
fields: 'data3',
label: {
renderer: Ext.util.Format.numberRenderer('0,0')
},
title: 'Cluster',
grid: true
//minimum: 0
},
{
type: 'Category',
position: 'bottom',
fields: ['name'],
title: 'Year'
}
],
series: [
{
type: 'line',
highlight: {
size: 7,
radius: 7
},
axis: 'left',
fill: true,
xField: 'name',
yField: 'data3',
markerConfig: {
type: 'circle',
size: 4,
radius: 4,
'stroke-width': 0
}
}
]
});
//Container that holds collapsable panels
viewport = Ext.create('Ext.container.Viewport', {
layout: 'border',
items: [
{
region: "center",
id: "mappanel",
xtype: "gx_mappanel",
map: map,
stateful: true,
stateId: 'mappanel',
},
{
region: 'north',
//xtype: "container",
//height: 20,
title: 'Urban Information System: ' + cityname,
//html: '<h1 class="x-panel-header">Bangalore, India</h1>',
autoHeight: true,
border: true,
margins: '0 0 3 0',
//height:30,
//width:200,
//items: [{xtype: 'combobox', width: 180, border: true,}]
},
{
region: 'east',
title: 'Statistical Information',
collapsible: true,
//collapsed: true,
//split: true,
width: 300,
autoScroll: true,
padding: 5,
items: [ChartArea, ChartGrowth, ChartCluster]
},
{
xtype: "gx_legendpanel",
region: "west",
title: 'Legend',
width: 200,
autoScroll: true,
padding: 5,
collapsible: true,
}]
});
//Function that parse id_0, id_1 and id_2 values
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
}
});