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
|
(function(){
if (!fixmystreet.maps) {
return;
}
var cleaning_categories = [
'Street cleaning',
'Street Cleaning',
'Accumulated Litter',
'Street Cleaning Enquiry',
'Street Cleansing'
];
var cleaning_groups = [
'Street cleaning'
];
var tfl_council_category = 'General Litter / Rubbish Collection';
var defaults = {
http_options: {
url: "https://tilma.mysociety.org/mapserver/tfl",
params: {
SERVICE: "WFS",
VERSION: "1.1.0",
REQUEST: "GetFeature",
SRSNAME: "urn:ogc:def:crs:EPSG::3857"
}
},
asset_type: 'spot',
max_resolution: 2.388657133579254,
min_resolution: 0.5971642833948135,
geometryName: 'msGeometry',
srsName: "EPSG:3857",
strategy_class: OpenLayers.Strategy.FixMyStreet
};
if (fixmystreet.cobrand === 'tfl') {
// On .com we change the categories depending on where is clicked; on the
// cobrand we use the standard 'Please click on a road' message which needs
// the body to be set so is_only_body passes.
defaults.body = 'TfL';
}
/* Red routes (TLRN) asset layer & handling for disabling form when red route
is not selected for specific categories. */
var tlrn_stylemap = new OpenLayers.StyleMap({
'default': new OpenLayers.Style({
fillColor: "#ff0000",
fillOpacity: 0.3,
strokeColor: "#ff0000",
strokeOpacity: 0.6,
strokeWidth: 2
})
});
/* Reports in these categories can only be made on a red route */
var tlrn_categories = [
"All out - three or more street lights in a row",
"Blocked drain",
"Damage - general (Trees)",
"Dead animal in the carriageway or footway",
"Debris in the carriageway",
"Fallen Tree",
"Flooding",
"Flytipping",
"Graffiti / Flyposting (non-offensive)",
"Graffiti / Flyposting (offensive)",
"Graffiti / Flyposting on street light (non-offensive)",
"Graffiti / Flyposting on street light (offensive)",
"Grass Cutting and Hedges",
"Hoardings blocking carriageway or footway",
"Light on during daylight hours",
"Lights out in Pedestrian Subway",
"Low hanging branches and general maintenance",
"Manhole Cover - Damaged (rocking or noisy)",
"Manhole Cover - Missing",
"Mobile Crane Operation",
"Pavement Defect (uneven surface / cracked paving slab)",
"Pothole",
"Roadworks",
"Scaffolding blocking carriageway or footway",
"Single Light out (street light)",
"Standing water",
"Unstable hoardings",
"Unstable scaffolding",
"Worn out road markings"
];
function is_tlrn_category_only(category, bodies) {
return OpenLayers.Util.indexOf(tlrn_categories, category) > -1 &&
OpenLayers.Util.indexOf(bodies, 'TfL') > -1 &&
bodies.length <= 1;
}
function regenerate_category_groups() {
var old_category_group = $('#category_group').val() || $('#filter_group').val();
$('#category_group').remove();
fixmystreet.set_up.category_groups(old_category_group, true);
}
var red_routes_layer = fixmystreet.assets.add(defaults, {
http_options: {
url: "https://tilma.mysociety.org/mapserver/tfl",
params: {
TYPENAME: "RedRoutes"
}
},
name: "Red Routes",
max_resolution: 9.554628534317017,
road: true,
non_interactive: true,
always_visible: true,
all_categories: true,
nearest_radius: 0.1,
stylemap: tlrn_stylemap,
no_asset_msg_id: '#js-not-tfl-road',
actions: {
found: function(layer, feature) {
fixmystreet.message_controller.road_found(layer, feature);
if (fixmystreet.cobrand === 'tfl' || !fixmystreet.reporting_data) {
return;
}
// On a TfL road, remove any council categories, except street cleaning
var changed = false;
$('#form_category').find('option').each(function(i, option) {
var val = option.value;
if (OpenLayers.Util.indexOf(cleaning_categories, val) > -1) {
return;
}
var optgroup = $(option).closest('optgroup').attr('label');
if (OpenLayers.Util.indexOf(cleaning_groups, optgroup) > -1) {
return;
}
if (val === tfl_council_category) {
changed = true;
$(option).remove();
}
var data = fixmystreet.reporting_data.by_category[val];
if (data && OpenLayers.Util.indexOf(data.bodies, 'TfL') === -1) {
changed = true;
$(option).remove();
}
});
if (changed) {
regenerate_category_groups();
}
},
not_found: function(layer) {
var category = $('#form_category').val();
if (is_tlrn_category_only(category, fixmystreet.bodies)) {
fixmystreet.message_controller.road_not_found(layer);
} else {
fixmystreet.message_controller.road_found(layer);
}
if (fixmystreet.cobrand === 'tfl' || !fixmystreet.reporting_data) {
return;
}
// On non-TfL, remove any TfL-road-only categories
var changed = false;
$('#form_category').find('option').each(function(i, option) {
if (option.value === tfl_council_category) {
$(option).remove();
}
var data = fixmystreet.reporting_data.by_category[option.value];
if (data && is_tlrn_category_only(option.value, data.bodies)) {
changed = true;
$(option).remove();
}
});
if (changed) {
regenerate_category_groups();
}
}
}
});
if (red_routes_layer) {
red_routes_layer.events.register( 'loadend', red_routes_layer, function(){
// The roadworks layer may have finished loading before this layer, so
// ensure the filters to only show markers that intersect with a red route
// are re-applied.
var roadworks = fixmystreet.map.getLayersByName("Roadworks");
if (roadworks.length) {
// .redraw() reapplies filters without issuing any new requests
roadworks[0].redraw();
}
});
}
/* Point asset layers, bus stops and traffic lights. This comes after the red
* route so its check for asset not clicked on happens after whether red route
* clicked on or not */
var asset_defaults = $.extend(true, {}, defaults, {
body: 'TfL',
select_action: true,
no_asset_msg_id: '#js-not-an-asset',
actions: {
asset_found: fixmystreet.message_controller.asset_found,
asset_not_found: fixmystreet.message_controller.asset_not_found
}
});
fixmystreet.assets.add(asset_defaults, {
http_options: {
params: {
TYPENAME: "trafficsignals"
}
},
asset_id_field: 'Site',
attributes: {
site: 'Site',
},
asset_group: "Traffic Lights",
asset_item: 'traffic signal'
});
fixmystreet.assets.add(asset_defaults, {
http_options: {
params: {
TYPENAME: "busstops"
}
},
asset_id_field: 'STOP_CODE',
attributes: {
stop_code: 'STOP_CODE',
},
asset_group: "Bus Stops and Shelters",
asset_item: 'bus stop'
});
/* Roadworks asset layer */
var rw_stylemap = new OpenLayers.StyleMap({
'default': new OpenLayers.Style({
fillOpacity: 1,
fillColor: "#FFFF00",
strokeColor: "#000000",
strokeOpacity: 0.8,
strokeWidth: 2,
pointRadius: 6,
graphicWidth: 39,
graphicHeight: 25,
graphicOpacity: 1,
externalGraphic: '/cobrands/tfl/warning@2x.png'
}),
'hover': new OpenLayers.Style({
fillColor: "#55BB00",
externalGraphic: '/cobrands/tfl/warning-green@2x.png'
}),
'select': new OpenLayers.Style({
fillColor: "#55BB00",
externalGraphic: '/cobrands/tfl/warning-green@2x.png'
})
});
fixmystreet.assets.add(asset_defaults, {
http_options: {
params: {
TYPENAME: "roadworks"
}
},
name: "Roadworks",
non_interactive: false,
always_visible: false,
road: false,
all_categories: false,
asset_category: "Roadworks",
stylemap: rw_stylemap,
asset_id_field: 'works_ref',
asset_item: 'roadworks',
attributes: {
promoter_works_ref: 'works_ref',
start: 'start',
end: 'end',
promoter: 'promoter',
works_desc: 'description',
works_state: 'status',
tooltip: 'location'
},
filter_key: true,
filter_value: function(feature) {
var red_routes = fixmystreet.map.getLayersByName("Red Routes");
if (!red_routes.length) {
return false;
}
red_routes = red_routes[0];
return red_routes.getFeaturesWithinDistance(feature.geometry, 10).length > 0;
},
select_action: true,
actions: {
asset_found: function(feature) {
this.fixmystreet.actions.asset_not_found.call(this);
feature.layer = this;
var attr = feature.attributes,
location = attr.location.replace(/\\n/g, '\n'),
desc = attr.description.replace(/\\n/g, '\n');
var $msg = $('<div class="js-roadworks-message js-roadworks-message-' + this.id + ' box-warning"></div>');
var $dl = $("<dl></dl>").appendTo($msg);
if (attr.promoter) {
$dl.append("<dt>Responsibility</dt>");
$dl.append($("<dd></dd>").text(attr.promoter));
}
$dl.append("<dt>Location</dt>");
var $summary = $("<dd></dd>").appendTo($dl);
location.split("\n").forEach(function(para) {
if (para.match(/^(\d{2}\s+\w{3}\s+(\d{2}:\d{2}\s+)?\d{4}( - )?){2}/)) {
// skip showing the date again
return;
}
if (para.match(/^delays/)) {
// skip showing traffic delay information
return;
}
$summary.append(para).append("<br />");
});
if (desc) {
$dl.append("<dt>Description</dt>");
$dl.append($("<dd></dd>").text(desc));
}
$dl.append("<dt>Dates</dt>");
var $dates = $("<dd></dd>").appendTo($dl);
$dates.text(attr.start + " until " + attr.end);
$msg.prependTo('#js-post-category-messages');
$('#js-post-category-messages .category_meta_message').hide();
},
asset_not_found: function() {
$(".js-roadworks-message-" + this.id).remove();
$('#js-post-category-messages .category_meta_message').show();
}
}
});
})();
|