diff options
-rw-r--r-- | web/cobrands/bexley/assets.js | 25 | ||||
-rw-r--r-- | web/cobrands/buckinghamshire/assets.js | 32 | ||||
-rw-r--r-- | web/cobrands/cheshireeast/assets.js | 26 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 31 | ||||
-rw-r--r-- | web/cobrands/hounslow/assets.js | 32 | ||||
-rw-r--r-- | web/cobrands/isleofwight/assets.js | 36 |
6 files changed, 59 insertions, 123 deletions
diff --git a/web/cobrands/bexley/assets.js b/web/cobrands/bexley/assets.js index 541d47ea4..caf0e296d 100644 --- a/web/cobrands/bexley/assets.js +++ b/web/cobrands/bexley/assets.js @@ -21,18 +21,9 @@ var defaults = { strategy_class: OpenLayers.Strategy.FixMyStreet }; -var streetlight_select = $.extend({ - label: "${Unit_No}", - labelOutlineColor: "white", - labelOutlineWidth: 3, - labelYOffset: 65, - fontSize: '15px', - fontWeight: 'bold' -}, fixmystreet.assets.style_default_select.defaultStyle); - var streetlight_stylemap = new OpenLayers.StyleMap({ 'default': fixmystreet.assets.style_default, - 'select': new OpenLayers.Style(streetlight_select) + 'select': fixmystreet.assets.construct_named_select_style("${Unit_No}") }); var labeled_defaults = $.extend(true, {}, defaults, { @@ -45,18 +36,8 @@ var labeled_defaults = $.extend(true, {}, defaults, { UnitID: 'Unit_ID' }, actions: { - asset_found: function(asset) { - var id = asset.attributes[this.fixmystreet.feature_code] || ''; - if (id !== '') { - var asset_name = this.fixmystreet.asset_item; - $('.category_meta_message').html('You have selected ' + asset_name + ' <b>' + id + '</b>'); - } else { - $('.category_meta_message').html(this.fixmystreet.asset_item_message); - } - }, - asset_not_found: function() { - $('.category_meta_message').html(this.fixmystreet.asset_item_message); - } + asset_found: fixmystreet.assets.named_select_action_found, + asset_not_found: fixmystreet.assets.named_select_action_not_found } }); diff --git a/web/cobrands/buckinghamshire/assets.js b/web/cobrands/buckinghamshire/assets.js index e11bf1a28..1030d11db 100644 --- a/web/cobrands/buckinghamshire/assets.js +++ b/web/cobrands/buckinghamshire/assets.js @@ -40,18 +40,9 @@ fixmystreet.assets.add(defaults, { asset_item: 'grit bin' }); -var streetlight_select = $.extend({ - label: "${feature_id}", - labelOutlineColor: "white", - labelOutlineWidth: 3, - labelYOffset: 65, - fontSize: '15px', - fontWeight: 'bold' -}, fixmystreet.assets.style_default_select.defaultStyle); - var streetlight_stylemap = new OpenLayers.StyleMap({ 'default': fixmystreet.assets.style_default, - 'select': new OpenLayers.Style(streetlight_select) + 'select': fixmystreet.assets.construct_named_select_style("${feature_id}") }); var streetlight_code_to_type = { @@ -68,21 +59,16 @@ var streetlight_code_to_type = { var labeled_defaults = $.extend(true, {}, defaults, { select_action: true, + feature_code: 'feature_id', stylemap: streetlight_stylemap, + asset_item_message: 'You can pick a <b class="asset-spot">ITEM</b> from the map »', + construct_asset_name: function(id) { + var code = id.replace(/[0-9]/g, ''); + return {id: id, name: streetlight_code_to_type[code]}; + }, actions: { - asset_found: function(asset) { - var id = asset.attributes.feature_id || ''; - if (id !== '') { - var code = id.replace(/[0-9]/g, ''); - var asset_name = streetlight_code_to_type[code] || this.fixmystreet.asset_item; - $('.category_meta_message').html('You have selected ' + asset_name + ' <b>' + id + '</b>'); - } else { - $('.category_meta_message').html('You can pick a <b class="asset-spot">' + this.fixmystreet.asset_item + '</b> from the map »'); - } - }, - asset_not_found: function() { - $('.category_meta_message').html('You can pick a <b class="asset-spot">' + this.fixmystreet.asset_item + '</b> from the map »'); - } + asset_found: fixmystreet.assets.named_select_action_found, + asset_not_found: fixmystreet.assets.named_select_action_not_found } }); diff --git a/web/cobrands/cheshireeast/assets.js b/web/cobrands/cheshireeast/assets.js index bca654af7..d9eb25821 100644 --- a/web/cobrands/cheshireeast/assets.js +++ b/web/cobrands/cheshireeast/assets.js @@ -20,18 +20,9 @@ var defaults = { strategy_class: OpenLayers.Strategy.FixMyStreet }; -var streetlight_select = $.extend({ - label: "${feature_id}", - labelOutlineColor: "white", - labelOutlineWidth: 3, - labelYOffset: 65, - fontSize: '15px', - fontWeight: 'bold' -}, fixmystreet.assets.style_default_select.defaultStyle); - var streetlight_stylemap = new OpenLayers.StyleMap({ 'default': fixmystreet.assets.style_default, - 'select': new OpenLayers.Style(streetlight_select) + 'select': fixmystreet.assets.construct_named_select_style("${feature_id}") }); var labeled_defaults = $.extend(true, {}, defaults, { @@ -39,19 +30,10 @@ var labeled_defaults = $.extend(true, {}, defaults, { stylemap: streetlight_stylemap, asset_type: 'spot', asset_id_field: 'central_as', + feature_code: 'feature_id', actions: { - asset_found: function(asset) { - var id = asset.attributes.feature_id || ''; - if (id !== '') { - var asset_name = this.fixmystreet.asset_item; - $('.category_meta_message').html('You have selected ' + asset_name + ' <b>' + id + '</b>'); - } else { - $('.category_meta_message').html(this.fixmystreet.asset_item_message); - } - }, - asset_not_found: function() { - $('.category_meta_message').html(this.fixmystreet.asset_item_message); - } + asset_found: fixmystreet.assets.named_select_action_found, + asset_not_found: fixmystreet.assets.named_select_action_not_found } }); diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 204ceb85d..88a098398 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -805,6 +805,37 @@ fixmystreet.assets = { graphicOpacity: 1.0 }), + construct_named_select_style: function(label) { + var f = $.extend({ + label: label, + labelOutlineColor: "white", + labelOutlineWidth: 3, + labelYOffset: 65, + fontSize: '15px', + fontWeight: 'bold' + }, fixmystreet.assets.style_default_select.defaultStyle); + return new OpenLayers.Style(f); + }, + named_select_action_found: function(asset) { + var id = asset.attributes[this.fixmystreet.feature_code] || ''; + if (id !== '') { + var data = { id: id, name: this.fixmystreet.asset_item }; + if (this.fixmystreet.construct_asset_name) { + data = this.fixmystreet.construct_asset_name(id) || data; + } + $('.category_meta_message').html('You have selected ' + data.name + ' <b>' + data.id + '</b>'); + } else { + var message = this.fixmystreet.asset_item_message; + message = message.replace('ITEM', this.fixmystreet.asset_item); + $('.category_meta_message').html(message); + } + }, + named_select_action_not_found: function() { + var message = this.fixmystreet.asset_item_message; + message = message.replace('ITEM', this.fixmystreet.asset_item); + $('.category_meta_message').html(message); + }, + selectedFeature: function() { return selected_feature; }, diff --git a/web/cobrands/hounslow/assets.js b/web/cobrands/hounslow/assets.js index 603a56e85..375a74e3f 100644 --- a/web/cobrands/hounslow/assets.js +++ b/web/cobrands/hounslow/assets.js @@ -114,20 +114,11 @@ fixmystreet.assets.add($.extend(true, {}, defaults, { // asset_item: 'gulley' // })); -var streetlight_select = $.extend({ - label: "${FeatureId}", - labelOutlineColor: "white", - labelOutlineWidth: 3, - labelYOffset: 65, - fontSize: '15px', - fontWeight: 'bold' -}, fixmystreet.assets.style_default_select.defaultStyle); - // The label for street light markers should be everything after the final // '/' in the feature's FeatureId attribute. // This seems to be the easiest way to perform custom processing // on style attributes in OpenLayers... -var select_style = new OpenLayers.Style(streetlight_select); +var select_style = fixmystreet.assets.construct_named_select_style("${FeatureId}"); select_style.createLiterals = function() { var literals = Object.getPrototypeOf(this).createLiterals.apply(this, arguments); if (literals.label && literals.label.split) { @@ -145,19 +136,16 @@ var labeled_defaults = $.extend(true, {}, defaults, { select_action: true, stylemap: streetlight_stylemap, feature_code: 'FeatureId', - actions: { - asset_found: function(asset) { - var id = asset.attributes[this.fixmystreet.feature_code] || ''; - if (id !== '' && id.split) { - var code = id.split("/").slice(-1)[0]; - $('.category_meta_message').html('You have selected column <b>' + code + '</b>'); - } else { - $('.category_meta_message').html('You can pick a <b class="asset-spot">' + this.fixmystreet.asset_item + '</b> from the map »'); - } - }, - asset_not_found: function() { - $('.category_meta_message').html('You can pick a <b class="asset-spot">' + this.fixmystreet.asset_item + '</b> from the map »'); + asset_item_message: 'You can pick a <b class="asset-spot">ITEM</b> from the map »', + construct_asset_name: function(id) { + if (id.split) { + var code = id.split("/").slice(-1)[0]; + return {id: code, name: 'column'}; } + }, + actions: { + asset_found: fixmystreet.assets.named_select_action_found, + asset_not_found: fixmystreet.assets.named_select_action_not_found } }); diff --git a/web/cobrands/isleofwight/assets.js b/web/cobrands/isleofwight/assets.js index 2710a9de7..7b7fb7f00 100644 --- a/web/cobrands/isleofwight/assets.js +++ b/web/cobrands/isleofwight/assets.js @@ -31,41 +31,9 @@ var defaults = { var pin_prefix = fixmystreet.pin_prefix || document.getElementById('js-map-data').getAttribute('data-pin_prefix'); -var labeled_default = { - fillColor: "#FFFF00", - fillOpacity: 0.6, - strokeColor: "#000000", - strokeOpacity: 0.8, - strokeWidth: 2, - pointRadius: 6 -}; - -var labeled_select = { - externalGraphic: pin_prefix + "pin-spot.png", - fillColor: "#55BB00", - graphicWidth: 48, - graphicHeight: 64, - graphicXOffset: -24, - graphicYOffset: -56, - backgroundGraphic: pin_prefix + "pin-shadow.png", - backgroundWidth: 60, - backgroundHeight: 30, - backgroundXOffset: -7, - backgroundYOffset: -22, - popupYOffset: -40, - graphicOpacity: 1.0, - - label: "${asset_id}", - labelOutlineColor: "white", - labelOutlineWidth: 3, - labelYOffset: 65, - fontSize: '15px', - fontWeight: 'bold' -}; - var labeled_stylemap = new OpenLayers.StyleMap({ - 'default': new OpenLayers.Style(labeled_default), - 'select': new OpenLayers.Style(labeled_select) + 'default': fixmystreet.assets.style_default, + 'select': fixmystreet.assets.construct_named_select_style("${asset_id}") }); fixmystreet.assets.add($.extend(true, {}, defaults, { |