forked from ERS-Long/LayerDefinitionExample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindStation.js
172 lines (143 loc) · 6 KB
/
WindStation.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
define([
'dojo/_base/declare',
'dijit/_WidgetBase',
'dijit/_TemplatedMixin',
'dijit/_WidgetsInTemplateMixin',
'dijit/form/Button',
'dojo/_base/lang',
'dojo/_base/array',
'dojo/dom',
'dojo/domReady!',
'dojo/on',
'dojo/text!./WindStation/templates/WindStation.html',
'dojo/topic',
'xstyle/css!./WindStation/css/WindStation.css',
'dojo/dom-construct',
'dojo/_base/Color',
'esri/graphic',
'esri/IdentityManager',
'esri/layers/GraphicsLayer',
'esri/layers/ArcGISDynamicMapServiceLayer',
'esri/layers/ImageParameters',
'esri/tasks/IdentifyTask',
'esri/tasks/IdentifyParameters',
'esri/InfoTemplate',
'esri/dijit/Legend'
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, Button, lang, arrayUtils, dom, ready, on, template, topic, css, domConstruct, Color, Graphic,
IdentityManager, GraphicsLayer, ArcGISDynamicMapServiceLayer, ImageParameters, IdentifyTask, IdentifyParameters, InfoTemplate, Legend
) {
var dynamicMapServiceLayer;
var map;
var identifyTask, identifyParams;
var legend;
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
name: 'WindStation',
map: true,
widgetsInTemplate: true,
templateString: template,
mapClickMode: null,
postCreate: function(){
this.inherited(arguments);
map = this.map;
// this.initTrace();
},
AddStation: function () {
//alert(this.map.extent.xmin);
var imageParameters = new ImageParameters();
imageParameters.format = "png32";
// here to get the layer defination setting from thh user input
var layerDefs = [];
var state = document.getElementById('State').value;
var minPopulation = document.getElementById('minPopulation').value;
var maxPopulation = document.getElementById('maxPopulation').value;
layerDefs[5] = "STATE_NAME='" + state + "'";
layerDefs[4] = layerDefs[5] + "and POP2007>" + minPopulation + "and POP2007<" + maxPopulation; //STATE_NAME='Kansas' and POP2007>25000";
layerDefs[3] = layerDefs[4] ;//"STATE_NAME='Kansas' and POP2007>25000";
imageParameters.layerDefinitions = layerDefs;
//I want layers 5,4, and 3 to be visible
imageParameters.layerIds = [5, 4, 3];
imageParameters.layerOption = ImageParameters.LAYER_OPTION_SHOW;
imageParameters.transparent = true;
var legendLayers = [];
// var url = "http://maps1.arcgisonline.com/ArcGIS/rest/services/NWS_Weather_Stations/MapServer";
var url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer";
if (dynamicMapServiceLayer)
{
console.log(dynamicMapServiceLayer.id);
dynamicMapServiceLayer = this.map.getLayer(dynamicMapServiceLayer.id);
dynamicMapServiceLayer.setLayerDefinitions(layerDefs);
}
else
{
dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(url, {
"opacity" : 1.0,
"imageParameters" : imageParameters
});
legendLayers.push({ layer: dynamicMapServiceLayer, title: 'ESRI_Census_USA' });
// this.map.on('layers-add-result', function () {
if (!legend)
{
legend = new Legend({
map: this.map,
layerInfos: legendLayers
}, "legendDiv");
legend.startup();
}
// });
this.map.addLayer(dynamicMapServiceLayer);
}
this.map.on('click', mapReady);
function mapReady (event) {
console.log(url);
//map.on("click", executeIdentifyTask);
//create identify tasks and setup parameters
identifyTask = new IdentifyTask(url);
identifyParams = new IdentifyParameters();
identifyParams.tolerance = 3;
identifyParams.returnGeometry = true;
identifyParams.layerIds = [3,4, 5];
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;
identifyParams.width = map.width;
identifyParams.height = map.height;
identifyParams.geometry = event.mapPoint;
identifyParams.mapExtent = map.extent;
//console.log(identifyParams.geometry);
var deferred = identifyTask
.execute(identifyParams)
.addCallback(function (response) {
// response is an array of identify result objects
// Let's return an array of features.
console.log(response);
return arrayUtils.map(response, function (result) {
var feature = result.feature;
var layerName = result.layerName;
console.log(layerName);
feature.attributes.layerName = layerName;
var popupInofTemplate = new InfoTemplate("", '${*}');
feature.setInfoTemplate(popupInofTemplate);
return feature;
});
});
// InfoWindow expects an array of features from each deferred
// object that you pass. If the response from the task execution
// above is not an array of features, then you need to add a callback
// like the one above to post-process the response and return an
// array of features.
map.infoWindow.setFeatures([deferred]);
map.infoWindow.show(event.mapPoint);
}
},
onAddStation: function()
{
this.AddStation();
},
onClear: function()
{
//needs to remove the service
if (dynamicMapServiceLayer){
this.map.removeLayer(dynamicMapServiceLayer)
dynamicMapServiceLayer = null;
}
}
});
});