aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/cobrands/bromley/map.js138
-rw-r--r--web/cobrands/fixmystreet/assets.js199
2 files changed, 221 insertions, 116 deletions
diff --git a/web/cobrands/bromley/map.js b/web/cobrands/bromley/map.js
index 0753907cc..e2e8e0073 100644
--- a/web/cobrands/bromley/map.js
+++ b/web/cobrands/bromley/map.js
@@ -1 +1,139 @@
fixmystreet.maps.tile_base = [ [ "", "a-" ], "https://{S}fix.bromley.gov.uk/tilma" ];
+
+(function(){
+
+if (!fixmystreet.maps) {
+ return;
+}
+
+var defaults = {
+ http_options: {
+ url: "https://tilma.staging.mysociety.org/mapserver/bromley_wfs",
+ params: {
+ SERVICE: "WFS",
+ VERSION: "1.1.0",
+ REQUEST: "GetFeature",
+ SRSNAME: "urn:ogc:def:crs:EPSG::3857"
+ }
+ },
+ format_class: OpenLayers.Format.GML.v3.MultiCurveFix,
+ asset_type: 'spot',
+ max_resolution: 2.388657133579254,
+ min_resolution: 0.5971642833948135,
+ asset_id_field: 'CENTRAL_AS',
+ geometryName: 'msGeometry',
+ srsName: "EPSG:3857",
+ strategy_class: OpenLayers.Strategy.FixMyStreet
+};
+
+fixmystreet.assets.add($.extend(true, {}, defaults, {
+ http_options: {
+ params: {
+ TYPENAME: "Streetlights"
+ }
+ },
+ asset_id_field: 'FEATURE_ID',
+ attributes: {
+ feature_id: 'FEATURE_ID'
+ },
+ asset_category: ["Faulty street light"],
+ asset_item: 'street light'
+}));
+
+fixmystreet.assets.add($.extend(true, {}, defaults, {
+ http_options: {
+ params: {
+ TYPENAME: "Bins"
+ }
+ },
+ asset_category: ["Overflowing litter bin"],
+ asset_item: 'park bin',
+ asset_item_message: 'For our parks, pick a <b class="asset-spot">bin</b> from the map &raquo;'
+}));
+
+fixmystreet.assets.add($.extend(true, {}, defaults, {
+ http_options: {
+ params: {
+ TYPENAME: "Street_Trees"
+ }
+ },
+ asset_category: ["Public Tree related issue"],
+ asset_item: 'tree'
+}));
+
+var highways_stylemap = new OpenLayers.StyleMap({
+ 'default': new OpenLayers.Style({
+ fill: false,
+ stroke: false
+ })
+});
+
+fixmystreet.assets.add($.extend(true, {}, defaults, {
+ http_options: {
+ params: {
+ TYPENAME: "TFL_Red_Route"
+ }
+ },
+ stylemap: highways_stylemap,
+ always_visible: true,
+ asset_category: ["Blocked drains", "Faulty street light", 'Faulty street sign', 'Floral displays', 'Grass needs cutting', 'Obstructions (skips, A boards)', 'Overhanging vegetation from private land', 'Pavement defect', 'Public Tree related issue', "Road defect"],
+ non_interactive: true,
+ road: true,
+ actions: {
+ found: function(layer) {
+ if (fixmystreet.assets.selectedFeature()) {
+ $('#road-warning').remove();
+ return;
+ }
+ var msg = 'The location selected is a Transport for London Red Route. TfL are responsible for the reported category and can be alerted to issues via: <a href="https://tfl.gov.uk/help-and-contact/contact-us-about-streets-and-other-road-issues">Street issues</a>';
+ if ( $('#road-warning').length ) {
+ $('#road-warning').html(msg);
+ } else {
+ $('.change_location').after('<div class="box-warning" id="road-warning">' + msg + '</div>');
+ }
+ $('#single_body_only').val(layer.fixmystreet.body_found);
+ },
+
+ not_found: function(layer) {
+ if ( $('#road-warning').length ) {
+ $('#road-warning').remove();
+ }
+ $('#single_body_only').val(layer.fixmystreet.body_council);
+ }
+ },
+ body_found: 'TfL',
+ body_council: 'Bromley Council'
+}));
+
+var prow_stylemap = new OpenLayers.StyleMap({
+ 'default': new OpenLayers.Style({
+ fill: false,
+ fillOpacity: 0,
+ strokeColor: "#660099",
+ strokeOpacity: 0.5,
+ strokeWidth: 6
+ })
+});
+
+fixmystreet.assets.add($.extend(true, {}, defaults, {
+ http_options: {
+ params: {
+ TYPENAME: "PROW"
+ }
+ },
+ stylemap: prow_stylemap,
+ always_visible: true,
+ non_interactive: true,
+ road: true,
+ all_categories: true,
+ actions: {
+ found: function(layer, feature) {
+ $('#form_prow_reference').val(feature.attributes.PROW_REFER);
+ },
+ not_found: function(layer) {
+ $('#form_prow_reference').val('');
+ }
+ }
+}));
+
+})();
diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js
index 9a72590fd..5af8ef1cd 100644
--- a/web/cobrands/fixmystreet/assets.js
+++ b/web/cobrands/fixmystreet/assets.js
@@ -16,139 +16,90 @@ var fixmystreet = fixmystreet || {};
};
})();
-/* Special USRN handling */
-
-(function(){
-
-var selected_usrn = null;
-var usrn_field = null;
+// Handles layers such as USRN, TfL roads, and the like
+OpenLayers.Layer.VectorNearest = OpenLayers.Class(OpenLayers.Layer.Vector, {
+ selected_feature: null,
+
+ initialize: function(name, options) {
+ OpenLayers.Layer.Vector.prototype.initialize.apply(this, arguments);
+ $(fixmystreet).on('maps:update_pin', this.checkFeature.bind(this));
+ $(fixmystreet).on('assets:selected', this.checkFeature.bind(this));
+ // Might only be able to fill in fields once they've been returned from the server
+ $(fixmystreet).on('report_new:category_change:extras_received', this.changeCategory.bind(this));
+ // But also want to do it immediately in case it's hiding the form or something
+ $(fixmystreet).on('report_new:category_change', this.changeCategory.bind(this));
+ },
-fixmystreet.usrn = {
- select: function(evt, lonlat) {
- var usrn_providers = fixmystreet.map.getLayersBy('fixmystreet', {
- test: function(options) {
- return options && options.usrn;
- }
- });
- if (usrn_providers.length) {
- var usrn_layer = usrn_providers[0];
- usrn_field = usrn_layer.fixmystreet.usrn.field;
- var point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
- var feature = usrn_layer.getFeatureAtPoint(point);
- if (feature == null) {
- // The click wasn't directly over a road, try and find one
- // nearby
- feature = usrn_layer.getNearestFeature(point, 10);
- }
- if (feature !== null) {
- selected_usrn = feature.attributes[usrn_layer.fixmystreet.usrn.attribute];
+ checkFeature: function(evt, lonlat) {
+ this.getNearest(lonlat);
+ this.updateUSRNField();
+ if (this.fixmystreet.road) {
+ var valid_category = this.fixmystreet.all_categories || (this.fixmystreet.asset_category && this.fixmystreet.asset_category.indexOf($('select#form_category').val()) != -1);
+ if (!valid_category || !this.selected_feature) {
+ this.road_not_found();
} else {
- selected_usrn = null;
+ this.road_found();
}
- fixmystreet.usrn.update_field();
}
},
- update_field: function() {
- $("input[name="+usrn_field+"]").val(selected_usrn);
+ getNearest: function(lonlat) {
+ var point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
+ var feature = this.getFeatureAtPoint(point);
+ if (feature == null) {
+ // The click wasn't directly over a road, try and find one nearby
+ feature = this.getNearestFeature(point, 10);
+ }
+ this.selected_feature = feature;
},
- one_time_select: function() {
- // This function takes the current report lat/lon from hidden input
- // fields and uses that to look up a USRN from the USRN layer.
- // It's registered as an event handler by init_asset_layer below,
- // and is only intended to run the once (because if the user drags the
- // pin the usual USRN lookup event handler is run) so unregisters itself
- // immediately.
- this.events.unregister( 'loadend', this, fixmystreet.usrn.one_time_select );
- fixmystreet.usrn.select(null, fixmystreet.get_lonlat_from_dom());
- }
-};
-
-$(fixmystreet).on('maps:update_pin', fixmystreet.usrn.select);
-$(fixmystreet).on('assets:selected', fixmystreet.usrn.select);
-$(fixmystreet).on('report_new:category_change:extras_received', fixmystreet.usrn.update_field);
-
-})();
-
-(function(){
-
-var selected_road = null;
-
-fixmystreet.roads = {
- last_road: null,
+ updateUSRNField: function() {
+ if (this.fixmystreet.usrn) {
+ var usrn_field = this.fixmystreet.usrn.field;
+ var selected_usrn = this.selected_feature ? this.selected_feature.attributes[this.fixmystreet.usrn.attribute] : '';
+ $("input[name=" + usrn_field + "]").val(selected_usrn);
+ }
+ },
- change_category: function() {
+ changeCategory: function() {
if (!fixmystreet.map) {
// Sometimes the category change event is fired before the map has
// initialised, for example when visiting /report/new directly
// on a cobrand with category groups enabled.
return;
}
- fixmystreet.roads.check_for_road(fixmystreet.get_lonlat_from_dom());
+ this.checkFeature(null, fixmystreet.get_lonlat_from_dom());
},
- select: function(evt, lonlat) {
- fixmystreet.roads.check_for_road(lonlat);
- },
-
- check_for_road: function(lonlat) {
- var road_providers = fixmystreet.map.getLayersBy('fixmystreet', {
- test: function(options) {
- return options && options.road && (options.all_categories || options.asset_category.indexOf($('select#form_category').val()) != -1);
- }
- });
- if (road_providers.length) {
- var road_layer = road_providers[0];
- fixmystreet.roads.last_road = road_layer;
- var point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
- var feature = road_layer.getFeatureAtPoint(point);
- if (feature == null) {
- // The click wasn't directly over a road, try and find one
- // nearby
- feature = road_layer.getNearestFeature(point, 10);
- }
- if (feature !== null) {
- selected_road = feature; //.attributes[road_layer.fixmystreet.road.attribute];
- } else {
- selected_road = null;
- }
- if (selected_road) {
- fixmystreet.roads.found(road_layer, selected_road);
- } else {
- fixmystreet.roads.not_found(road_layer);
- }
- } else {
- fixmystreet.roads.not_found();
- }
+ one_time_select: function() {
+ // This function takes the current report lat/lon from hidden input
+ // fields and uses that to look up a USRN from the USRN layer.
+ // It's registered as an event handler by init_asset_layer below,
+ // and is only intended to run the once (because if the user drags the
+ // pin the usual USRN lookup event handler is run) so unregisters itself
+ // immediately.
+ this.events.unregister( 'loadend', this, this.one_time_select );
+ this.checkFeature(null, fixmystreet.get_lonlat_from_dom());
},
- found: function(layer, feature) {
- if (layer.fixmystreet.actions) {
- layer.fixmystreet.actions.found(layer, feature);
+ road_found: function() {
+ if (this.fixmystreet.actions) {
+ this.fixmystreet.actions.found(this, this.selected_feature);
} else {
- $('#single_body_only').val(layer.fixmystreet.body);
+ $('#single_body_only').val(this.fixmystreet.body);
}
},
- not_found: function(layer) {
- if (layer && layer.fixmystreet.actions) {
- layer.fixmystreet.actions.not_found(layer);
+ road_not_found: function() {
+ if (this.fixmystreet.actions) {
+ this.fixmystreet.actions.not_found(this);
} else {
- if ( fixmystreet.roads.last_road && fixmystreet.roads.last_road.fixmystreet.actions.unselected ) {
- fixmystreet.roads.last_road.fixmystreet.actions.unselected();
- fixmystreet.roads.last_road = null;
- }
$('#single_body_only').val('');
}
},
-};
-
-$(fixmystreet).on('maps:update_pin', fixmystreet.roads.select);
-$(fixmystreet).on('assets:selected', fixmystreet.roads.select);
-$(fixmystreet).on('report_new:category_change', fixmystreet.roads.change_category);
-})();
+ CLASS_NAME: 'OpenLayers.Layer.VectorNearest'
+});
(function(){
@@ -176,17 +127,17 @@ function init_asset_layer(layer, pins_layer) {
layer.fixmystreet.fault_layer.setZIndex(layer.getZIndex()-1);
}
- if (fixmystreet.page == 'new' && layer.fixmystreet.usrn) {
+ if (fixmystreet.page == 'new' && (layer.fixmystreet.usrn || layer.fixmystreet.road)) {
// If the user visits /report/new directly and doesn't change the pin
// location, then the assets:selected/maps:update_pin events are never
- // fired and fixmystreet.usrn.select is never called. This results in a
+ // fired and USRN's checkFeature is never called. This results in a
// report whose location was never looked up against the USRN layer,
// which can cause issues for Open311 endpoints that require a USRN
// value.
// To prevent this situation we register an event handler that looks up
// the new report's lat/lon against the USRN layer, calls usrn.select
// and then unregisters itself.
- layer.events.register( 'loadend', layer, fixmystreet.usrn.one_time_select );
+ layer.events.register( 'loadend', layer, layer.one_time_select );
}
if (!layer.fixmystreet.always_visible) {
@@ -238,6 +189,12 @@ function asset_selected(e) {
return;
}
+ var layer = e.feature.layer;
+ var feature = e.feature;
+
+ // Keep track of selection in case layer is reloaded or hidden etc.
+ selected_feature = feature.clone();
+
// Pick up the USRN for the location of this asset. NB we do this *before*
// handling the attributes on the selected feature in case the feature has
// its own USRN which should take precedence.
@@ -264,13 +221,8 @@ function asset_selected(e) {
fixmystreet.maps.update_pin(lonlat);
// Make sure the marker that was clicked is drawn on top of its neighbours
- var layer = e.feature.layer;
- var feature = e.feature;
layer.eraseFeatures([feature]);
layer.drawFeature(feature);
-
- // Keep track of selection in case layer is reloaded or hidden etc.
- selected_feature = feature.clone();
}
function asset_unselected(e) {
@@ -301,6 +253,9 @@ function find_matching_feature(feature, layer, asset_id_field) {
}
function check_zoom_message_visibility() {
+ if (this.fixmystreet.non_interactive) {
+ return;
+ }
var category = $("#problem_form select#form_category").val(),
prefix = category.replace(/[^a-z]/gi, ''),
id = "category_meta_message_" + prefix,
@@ -312,9 +267,13 @@ function check_zoom_message_visibility() {
}
if (this.getVisibility() && this.inRange) {
- $p.html('Or pick a <b class="asset-' + this.fixmystreet.asset_type + '">' + this.fixmystreet.asset_item + '</b> from the map &raquo;');
+ if (this.fixmystreet.asset_item_message) {
+ $p.html(this.fixmystreet.asset_item_message);
+ } else {
+ $p.html('You can pick a <b class="asset-' + this.fixmystreet.asset_type + '">' + this.fixmystreet.asset_item + '</b> from the map &raquo;');
+ }
} else {
- $p.html('Or zoom in and pick a ' + this.fixmystreet.asset_item + ' from the map');
+ $p.html('Zoom in to pick a ' + this.fixmystreet.asset_item + ' from the map');
}
} else {
@@ -455,6 +414,10 @@ fixmystreet.assets = {
layers: [],
controls: [],
+ selectedFeature: function() {
+ return selected_feature;
+ },
+
add: function(options) {
var asset_fault_layer = null;
@@ -533,7 +496,11 @@ fixmystreet.assets = {
}
}
- var asset_layer = new OpenLayers.Layer.Vector(options.name || "WFS", layer_options);
+ var layer_class = OpenLayers.Layer.Vector;
+ if (options.usrn || options.road) {
+ layer_class = OpenLayers.Layer.VectorNearest;
+ }
+ var asset_layer = new layer_class(options.name || "WFS", layer_options);
// A non-interactive layer to display existing asset faults
if (options.wfs_fault_feature) {