Skip to content

Commit a495514

Browse files
committed
allow click attribution on slider layers
1 parent 1bacfcb commit a495514

1 file changed

Lines changed: 134 additions & 126 deletions

File tree

visualize/static/js/events.js

Lines changed: 134 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -5,154 +5,162 @@
55
*/
66
if (!app.wrapper.events.hasOwnProperty('clickOnArcRESTLayerEvent')) {
77
app.wrapper.events.clickOnArcRESTLayerEvent = function(layer, evt){
8-
if (app.wrapper.map.getLayerParameter(layer, 'url')){
8+
if (layer.get('opacity') != 0 && layer.get('visible') == true) {
99

10-
var identifyUrl = app.wrapper.map.getLayerParameter(layer, 'url');
10+
11+
if (app.wrapper.map.getLayerParameter(layer, 'url')){
1112

12-
if (identifyUrl.indexOf('export') >= 0) {
13-
identifyUrl = identifyUrl.replace('export', app.wrapper.map.getLayerParameter(layer, 'arcgislayers') + '/query');
14-
} else {
15-
if (identifyUrl[identifyUrl.length-1] != "/") {
16-
identifyUrl += '/'
13+
var identifyUrl = app.wrapper.map.getLayerParameter(layer, 'url');
14+
15+
if (identifyUrl.indexOf('export') >= 0) {
16+
identifyUrl = identifyUrl.replace('export', app.wrapper.map.getLayerParameter(layer, 'arcgislayers') + '/query');
17+
} else {
18+
if (identifyUrl[identifyUrl.length-1] != "/") {
19+
identifyUrl += '/'
20+
}
21+
identifyUrl += app.wrapper.map.getLayerParameter(layer, 'arcgislayers') + '/query';
1722
}
18-
identifyUrl += app.wrapper.map.getLayerParameter(layer, 'arcgislayers') + '/query';
23+
} else {
24+
var identifyUrl = '';
1925
}
20-
} else {
21-
var identifyUrl = '';
22-
}
2326

24-
var qs = []
27+
var qs = []
2528

26-
var mp_layer = app.wrapper.map.getLayerParameter(layer, 'mp_layer');
27-
// If layer is 'select by point' geom should be a point, not envelope.
28-
if (mp_layer.query_by_point || layer.get('query_by_point')) {
29-
var geometry = app.map.getCoordinateFromPixel([evt.pixel[0], evt.pixel[1]]);
30-
var geometryType = 'esriGeometryPoint';
31-
} else {
32-
// buffer click by two pixels each direction and use that for selection envelope
33-
var geometry_raw = {
34-
UL: app.map.getCoordinateFromPixel([evt.pixel[0]-2, evt.pixel[1]-2]),
35-
LR: app.map.getCoordinateFromPixel([evt.pixel[0]+2, evt.pixel[1]+2])
36-
}
37-
var geometry = [geometry_raw.UL, geometry_raw.LR].join(',');
38-
var geometryType = 'esriGeometryEnvelope';
29+
var mp_layer = app.wrapper.map.getLayerParameter(layer, 'mp_layer');
30+
// If layer is 'select by point' geom should be a point, not envelope.
31+
if (mp_layer.query_by_point || layer.get('query_by_point')) {
32+
var geometry = app.map.getCoordinateFromPixel([evt.pixel[0], evt.pixel[1]]);
33+
var geometryType = 'esriGeometryPoint';
34+
} else {
35+
// buffer click by two pixels each direction and use that for selection envelope
36+
var geometry_raw = {
37+
UL: app.map.getCoordinateFromPixel([evt.pixel[0]-2, evt.pixel[1]-2]),
38+
LR: app.map.getCoordinateFromPixel([evt.pixel[0]+2, evt.pixel[1]+2])
39+
}
40+
var geometry = [geometry_raw.UL, geometry_raw.LR].join(',');
41+
var geometryType = 'esriGeometryEnvelope';
3942

40-
}
43+
}
4144

42-
qs.push('geometry=' + geometry);
43-
qs.push('geometryType=' + geometryType);
44-
var inSR = 3857;
45-
qs.push('inSR=' + inSR);
46-
var outSR = 3857;
47-
qs.push('outSR=' + outSR);
48-
var spatialRel = 'esriSpatialRelIntersects';
49-
qs.push('spatialRel=' + spatialRel);
50-
var format = 'json';
51-
qs.push('f=' + format);
52-
var returnGeometry = true;
53-
qs.push('returnGeometry=' + returnGeometry);
45+
qs.push('geometry=' + geometry);
46+
qs.push('geometryType=' + geometryType);
47+
var inSR = 3857;
48+
qs.push('inSR=' + inSR);
49+
var outSR = 3857;
50+
qs.push('outSR=' + outSR);
51+
var spatialRel = 'esriSpatialRelIntersects';
52+
qs.push('spatialRel=' + spatialRel);
53+
var format = 'json';
54+
qs.push('f=' + format);
55+
var returnGeometry = true;
56+
qs.push('returnGeometry=' + returnGeometry);
5457

55-
if (mp_layer.attributes.length > 0) {
56-
var outFieldList = [];
57-
for (var i = 0; i < mp_layer.attributes.length; i++) {
58-
attr = mp_layer.attributes[i];
59-
outFieldList.push(attr.field);
58+
if (mp_layer.attributes.length > 0) {
59+
var outFieldList = [];
60+
for (var i = 0; i < mp_layer.attributes.length; i++) {
61+
attr = mp_layer.attributes[i];
62+
outFieldList.push(attr.field);
63+
}
64+
var outFields = outFieldList.join(',');
65+
} else {
66+
var outFields = '*';
6067
}
61-
var outFields = outFieldList.join(',');
62-
} else {
63-
var outFields = '*';
64-
}
65-
qs.push('outFields=' + outFields);
68+
qs.push('outFields=' + outFields);
6669

67-
if (mp_layer.password_protected() && mp_layer.token() && mp_layer.token() != null) {
68-
qs.push('token=' + mp_layer.token());
69-
}
70+
if (mp_layer.password_protected() && mp_layer.token() && mp_layer.token() != null) {
71+
qs.push('token=' + mp_layer.token());
72+
}
7073

71-
$.ajax({
72-
accepts: {
73-
mycustomtype: 'application/json',
74-
},
75-
dataType: 'json',
76-
url: identifyUrl + '?' + qs.join('&')
77-
})
78-
.done(function(responseText) {
79-
var clickAttributes = {},
80-
returnJSON = responseText;
81-
var mp_layer = app.wrapper.map.getLayerParameter(layer, 'mp_layer');
74+
$.ajax({
75+
accepts: {
76+
mycustomtype: 'application/json',
77+
},
78+
dataType: 'json',
79+
url: identifyUrl + '?' + qs.join('&')
80+
})
81+
.done(function(responseText) {
82+
var clickAttributes = {},
83+
returnJSON = responseText;
84+
var mp_layer = app.wrapper.map.getLayerParameter(layer, 'mp_layer');
8285

83-
//data manager opted to disable via DAI
84-
if (mp_layer.disable_click) {
85-
return false;
86-
}
86+
//data manager opted to disable via DAI
87+
if (mp_layer.disable_click) {
88+
return false;
89+
}
8790

88-
if(returnJSON['features'] && returnJSON['features'].length) {
91+
if(returnJSON['features'] && returnJSON['features'].length) {
8992

90-
var report_features = []
91-
$.each(returnJSON['features'], function(index, feature) {
92-
var attributeObjs = [];
93-
var attributeList = feature['attributes'];
93+
var report_features = []
94+
$.each(returnJSON['features'], function(index, feature) {
95+
var attributeObjs = [];
96+
var attributeList = feature['attributes'];
9497

95-
if('fields' in returnJSON) {
96-
$.each(returnJSON['fields'], function(fieldNdx, field) {
97-
if (field.name.indexOf('OBJECTID') === -1 && field.name.indexOf('CFR_id') === -1) {
98-
var data = attributeList[field.name]
99-
var attribute_rules = mp_layer.attributes.find(o => o.field === field.name);
100-
if (mp_layer.preserved_format_attributes.indexOf(field.name) < 0) {
101-
if (field.type === 'esriFieldTypeDate') {
102-
data = new Date(data).toDateString();
103-
} else if (app.utils.isNumber(data)) {
104-
var precision = false;
105-
if (attribute_rules && attribute_rules.hasOwnProperty('precision')) {
106-
precision = attribute_rules.precision;
107-
}
108-
data = app.utils.formatNumber(data, precision);
109-
} else if (typeof(data) == 'string' && (data.indexOf('http') >= 0 || field.name.toLowerCase() == 'link' )) {
110-
// Make link attributes live!
111-
str_list = data.split('; ');
112-
if (str_list.length == 1) {
113-
str_list = data.split(' ');
114-
}
115-
for (var i=0; i < str_list.length; i++) {
116-
if (str_list[i].indexOf('http') < 0) {
117-
var list_addr = 'http://' + str_list[i];
118-
} else {
119-
var list_addr = str_list[i];
98+
if('fields' in returnJSON) {
99+
$.each(returnJSON['fields'], function(fieldNdx, field) {
100+
if (field.name.indexOf('OBJECTID') === -1 && field.name.indexOf('CFR_id') === -1) {
101+
var data = attributeList[field.name]
102+
var attribute_rules = mp_layer.attributes.find(o => o.field === field.name);
103+
if (mp_layer.preserved_format_attributes.indexOf(field.name) < 0) {
104+
if (field.type === 'esriFieldTypeDate') {
105+
data = new Date(data).toDateString();
106+
} else if (app.utils.isNumber(data)) {
107+
var precision = false;
108+
if (attribute_rules && attribute_rules.hasOwnProperty('precision')) {
109+
precision = attribute_rules.precision;
110+
}
111+
data = app.utils.formatNumber(data, precision);
112+
} else if (typeof(data) == 'string' && (data.indexOf('http') >= 0 || field.name.toLowerCase() == 'link' )) {
113+
// Make link attributes live!
114+
str_list = data.split('; ');
115+
if (str_list.length == 1) {
116+
str_list = data.split(' ');
120117
}
121-
link_string = '<a href="' + list_addr + '" target="_blank">' + str_list[i] + '</a>';
122-
str_list[i] = link_string;
118+
for (var i=0; i < str_list.length; i++) {
119+
if (str_list[i].indexOf('http') < 0) {
120+
var list_addr = 'http://' + str_list[i];
121+
} else {
122+
var list_addr = str_list[i];
123+
}
124+
link_string = '<a href="' + list_addr + '" target="_blank">' + str_list[i] + '</a>';
125+
str_list[i] = link_string;
126+
}
127+
data = str_list.join(' ');
123128
}
124-
data = str_list.join(' ');
129+
}
130+
if (data && app.utils.trim(data) !== "") {
131+
attributeObjs.push({
132+
'display': field.alias,
133+
'data': data
134+
});
125135
}
126136
}
127-
if (data && app.utils.trim(data) !== "") {
128-
attributeObjs.push({
129-
'display': field.alias,
130-
'data': data
131-
});
132-
}
133-
}
134-
});
137+
});
138+
}
139+
report_features.push({
140+
'name': 'Feature ' + (index+1),
141+
'id': mp_layer.featureAttributionName + '-' + index,
142+
'attributes': attributeObjs
143+
})
144+
return;
145+
});
146+
if (report_features && report_features.length) {
147+
let attribName = mp_layer.featureAttributionName;
148+
if (mp_layer.is_multilayer()) {
149+
attribName = mp_layer.parent.featureAttributionName;
150+
}
151+
clickAttributes[attribName] = report_features;
152+
$.extend(app.wrapper.map.clickOutput.attributes, clickAttributes);
153+
app.viewModel.aggregatedAttributes(app.wrapper.map.clickOutput.attributes);
154+
//app.viewModel.updateMarker(app.map.getLonLatFromViewPortPx(responseText.xy));
155+
//the following ensures that the location of the marker has not been displaced while waiting for web services
156+
app.viewModel.updateMarker(app.wrapper.map.clickLocation);
135157
}
136-
report_features.push({
137-
'name': 'Feature ' + (index+1),
138-
'id': mp_layer.featureAttributionName + '-' + index,
139-
'attributes': attributeObjs
140-
})
141-
return;
142-
});
143-
if (report_features && report_features.length) {
144-
clickAttributes[mp_layer.featureAttributionName] = report_features;
145-
$.extend(app.wrapper.map.clickOutput.attributes, clickAttributes);
146-
app.viewModel.aggregatedAttributes(app.wrapper.map.clickOutput.attributes);
147-
//app.viewModel.updateMarker(app.map.getLonLatFromViewPortPx(responseText.xy));
148-
//the following ensures that the location of the marker has not been displaced while waiting for web services
149-
app.viewModel.updateMarker(app.wrapper.map.clickLocation);
150158
}
151-
}
152-
})
153-
.fail(function(response){
154-
console.log(response);
155-
});
159+
})
160+
.fail(function(response){
161+
console.log(response);
162+
});
163+
}
156164
};
157165
} //ArcREST Click Event
158166

0 commit comments

Comments
 (0)