diff options
Diffstat (limited to 'web/cobrands')
-rw-r--r-- | web/cobrands/bathnes/js.js | 47 | ||||
-rw-r--r-- | web/cobrands/bathnes/staff.js | 40 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 52 |
3 files changed, 113 insertions, 26 deletions
diff --git a/web/cobrands/bathnes/js.js b/web/cobrands/bathnes/js.js index 84c9c56f5..71077ed43 100644 --- a/web/cobrands/bathnes/js.js +++ b/web/cobrands/bathnes/js.js @@ -45,6 +45,53 @@ fixmystreet.assets.add($.extend(true, {}, fixmystreet.maps.banes_defaults, { } })); +fixmystreet.assets.add($.extend(true, {}, fixmystreet.maps.banes_defaults, { + http_options: { + params: { + TYPENAME: "ParksOpenSpacesAssets" + } + }, + asset_category: [ + 'Abandoned vehicles', + 'Dead animals', + 'Dog fouling', + 'Fly-tipping', + 'Graffiti', + 'Excessive or dangerous littering', + 'Needles', + 'Play area safety issue', + 'Damage to bins, benches, and infrastructure', + 'Allotment issue', + 'Trees and woodland', + 'Obstructive vegetation' + ], + asset_item: "park", + disable_pin_snapping: true, + stylemap: new OpenLayers.StyleMap({ + 'default': new OpenLayers.Style({ + fill: false, + stroke: false + }) + }), + attributes: { + asset_details: function() { + var a = this.attributes; + return a.description + " " + a.assetid; + } + }, + filter_key: 'category', + filter_value: [ + 'Flower Beds', + 'Grass', + 'Hard', + 'Hedgerow', + 'Path', + 'Pitch', + 'Seats' + ], + name: "Parks and Grounds" +})); + /* diff --git a/web/cobrands/bathnes/staff.js b/web/cobrands/bathnes/staff.js index 763761929..c6a8a9560 100644 --- a/web/cobrands/bathnes/staff.js +++ b/web/cobrands/bathnes/staff.js @@ -35,22 +35,34 @@ fixmystreet.assets.add($.extend(true, {}, fixmystreet.maps.banes_defaults, { })); -// Staff can actually see the adopted highways layer, so replace the invisible -// stylemap of that layer. -var highways_stylemap = new OpenLayers.StyleMap({ - 'default': new OpenLayers.Style({ - fill: true, - fillOpacity: 0, - // strokeColor: "#55BB00", - strokeColor: "#FFFF00", - strokeOpacity: 0.5, - strokeWidth: 2, - title: '${description}\n${notes}' +// Some normally-invisible layers are visible to staff, so replace their +// stylemaps accordingly. +var replacement_stylemaps = { + "Adopted Highways": new OpenLayers.StyleMap({ + 'default': new OpenLayers.Style({ + fill: true, + fillOpacity: 0, + // strokeColor: "#55BB00", + strokeColor: "#FFFF00", + strokeOpacity: 0.5, + strokeWidth: 2, + title: '${description}\n${notes}' + }) + }), + "Parks and Grounds": new OpenLayers.StyleMap({ + 'default': new OpenLayers.Style({ + fill: false, + strokeColor: "#008800", + strokeOpacity: 0.5, + strokeWidth: 2, + title: '${site_name}' + }) }) -}); +}; + $.each(fixmystreet.assets.layers, function() { - if (this.name == "Adopted Highways") { - this.styleMap = highways_stylemap; + if (typeof replacement_stylemaps[this.name] !== 'undefined') { + this.styleMap = replacement_stylemaps[this.name]; } }); diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 7e79776cd..77522fc6c 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -200,16 +200,7 @@ function asset_selected(e) { // its own USRN which should take precedence. $(fixmystreet).trigger('assets:selected', [ lonlat ]); - // Set the extra field to the value of the selected feature - $.each(this.fixmystreet.attributes, function (field_name, attribute_name) { - var field_value; - if (typeof attribute_name === 'function') { - field_value = attribute_name.apply(e.feature); - } else { - field_value = e.feature.attributes[attribute_name]; - } - $("#form_" + field_name).val(field_value); - }); + set_fields_from_attributes(this.fixmystreet.attributes, feature); // Hide the normal markers layer to keep things simple, but // move the green marker to the point of the click to stop @@ -227,10 +218,26 @@ function asset_selected(e) { function asset_unselected(e) { fixmystreet.markers.setVisibility(true); - $.each(this.fixmystreet.attributes, function (field_name, attribute_name) { + selected_feature = null; + clear_fields_for_attributes(this.fixmystreet.attributes); +} + +function set_fields_from_attributes(attributes, feature) { + // Set the extra fields to the value of the selected feature + $.each(attributes, function (field_name, attribute_name) { + var $field = $("#form_" + field_name); + if (typeof attribute_name === 'function') { + $field.val(attribute_name.apply(feature)); + } else { + $field.val(feature.attributes[attribute_name]); + } + }); +} + +function clear_fields_for_attributes(attributes) { + $.each(attributes, function (field_name, attribute_name) { $("#form_" + field_name).val(""); }); - selected_feature = null; } function find_matching_feature(feature, layer, asset_id_field) { @@ -528,6 +535,27 @@ fixmystreet.assets = { select_feature_control = new OpenLayers.Control.SelectFeature( asset_layer ); asset_layer.events.register( 'featureselected', asset_layer, asset_selected); asset_layer.events.register( 'featureunselected', asset_layer, asset_unselected); + if (options.disable_pin_snapping) { + // The pin is snapped to the centre of a feature by the select + // handler. We can stop this handler from running, and the pin + // being snapped, by returning false from a beforefeatureselected + // event handler. This handler does need to make sure the + // attributes of the clicked feature are applied to the extra + // details form fields first though. + asset_layer.events.register( 'beforefeatureselected', asset_layer, function(e) { + var attributes = this.fixmystreet.attributes; + set_fields_from_attributes(attributes, e.feature); + + // The next click on the map may not be on an asset - so + // clear the fields for this layer when the pin is next + // updated. If it is on an asset then the fields will be + // set by whatever feature was selected. + $(fixmystreet).one('maps:update_pin', function() { + clear_fields_for_attributes(attributes); + }); + return false; + }); + } // When panning/zooming the map check that this layer is still correctly shown // and any selected marker is preserved asset_layer.events.register( 'loadend', asset_layer, layer_loadend); |