aboutsummaryrefslogtreecommitdiffstats
path: root/web/cobrands/fixmystreet-uk-councils
diff options
context:
space:
mode:
Diffstat (limited to 'web/cobrands/fixmystreet-uk-councils')
-rw-r--r--web/cobrands/fixmystreet-uk-councils/alloy.js104
-rw-r--r--web/cobrands/fixmystreet-uk-councils/council_validation_rules.js2
-rw-r--r--web/cobrands/fixmystreet-uk-councils/roadworks.js82
3 files changed, 180 insertions, 8 deletions
diff --git a/web/cobrands/fixmystreet-uk-councils/alloy.js b/web/cobrands/fixmystreet-uk-councils/alloy.js
index ace0062de..a06c197fe 100644
--- a/web/cobrands/fixmystreet-uk-councils/alloy.js
+++ b/web/cobrands/fixmystreet-uk-councils/alloy.js
@@ -3,6 +3,8 @@
OpenLayers.Protocol.Alloy = OpenLayers.Class(OpenLayers.Protocol.HTTP, {
currentRequests: [],
+ tileSize: 512,
+ resolution: 2.388657133579254,
abort: function() {
if (this.currentRequests.length) {
for (var j = 0; j < this.currentRequests.length; j++) {
@@ -55,16 +57,13 @@ OpenLayers.Protocol.Alloy = OpenLayers.Class(OpenLayers.Protocol.HTTP, {
getTileCoord: function(bounds, maxExtent, map, reverse) {
var origin = new OpenLayers.LonLat(maxExtent.left, maxExtent.top);
- // hard code this number as we want to avoid fetching asset groups
- // which happens at more zoomed out levels
- var resolution = 2.388657133579254;
var adjustX = reverse ? 0.5 : 0;
var adjustY = reverse ? 0 : 0.5;
- var xFromOrigin = Math.floor((bounds[0] - origin.lon) / resolution + adjustX);
- var yFromOrigin = Math.floor((bounds[1] - origin.lat) / resolution + adjustY);
- var tileCoordX = Math.floor(xFromOrigin / 512);
- var tileCoordY = Math.floor(yFromOrigin / 512) * -1;
+ var xFromOrigin = Math.floor((bounds[0] - origin.lon) / this.resolution + adjustX);
+ var yFromOrigin = Math.floor((bounds[1] - origin.lat) / this.resolution + adjustY);
+ var tileCoordX = Math.floor(xFromOrigin / this.tileSize);
+ var tileCoordY = Math.floor(yFromOrigin / this.tileSize) * -1;
if (reverse) {
tileCoordX -= 1;
@@ -88,13 +87,18 @@ OpenLayers.Strategy.Alloy = OpenLayers.Class(OpenLayers.Strategy.FixMyStreet, {
this.failCount = 0;
this.layer.destroyFeatures();
},
+ // allow sub classes to override the remote projection for converting the geometry
+ // of the features
+ getRemoteProjection: function() {
+ return this.layer.projection;
+ },
merge: function(resp) {
this.count++;
// This if/else clause lifted from OpenLayers.Strategy.BBOX
if (resp.success()) {
var features = resp.features;
if(features && features.length > 0) {
- var remote = this.layer.projection;
+ var remote = this.getRemoteProjection();
var local = this.layer.map.getProjectionObject();
if(!local.equals(remote)) {
var geom;
@@ -133,4 +137,88 @@ fixmystreet.alloy_defaults = {
strategy_class: OpenLayers.Strategy.Alloy
};
+/* for Alloy V2 */
+OpenLayers.Format.AlloyV2 = OpenLayers.Class(OpenLayers.Format.GeoJSON, {
+ read: function(json, type, filter) {
+ var results = null;
+ var obj = null;
+ if (typeof json == "string") {
+ obj = OpenLayers.Format.JSON.prototype.read.apply(this, [json, filter]);
+ } else {
+ obj = json;
+ }
+
+ if(!obj) {
+ OpenLayers.Console.error("Bad JSON: " + json);
+ } else {
+ results = [];
+ for(var i=0, len=obj.results.length; i<len; ++i) {
+ try {
+ results.push(this.parseFeature(obj.results[i]));
+ } catch(err) {
+ results = null;
+ OpenLayers.Console.error(err);
+ }
+ }
+ }
+ return results;
+ }
+});
+
+OpenLayers.Protocol.AlloyV2 = OpenLayers.Class(OpenLayers.Protocol.Alloy, {
+ tileSize: 128,
+ resolution: 4.777314267158508,
+ getURL: function(coords, options) {
+ return OpenLayers.String.format(options.base, {'layerid': options.layerid, 'styleid': options.styleid, 'z': 16, 'x': coords[0], 'y': coords[1]});
+ }
+});
+
+OpenLayers.Strategy.AlloyV2 = OpenLayers.Class(OpenLayers.Strategy.Alloy, {
+ initialize: function(name, options) {
+ this.remote = new OpenLayers.Projection("EPSG:4326");
+ OpenLayers.Strategy.Alloy.prototype.initialize.apply(this, arguments);
+ },
+ // the layer uses EPSG:3857 for generating the tile location but the features
+ // use EPSG:4326
+ getRemoteProjection: function() {
+ return this.remote;
+ }
+});
+
+fixmystreet.alloyv2_defaults = {
+ format_class: OpenLayers.Format.AlloyV2,
+ srsName: "EPSG:3857",
+ strategy_class: OpenLayers.Strategy.AlloyV2
+};
+
+fixmystreet.alloy_add_layers = function(defaults, layers) {
+ $.each(layers, function(index, layer) {
+ if ( layer.categories ) {
+ var options = {
+ http_options: {
+ layerid: layer.layerid || layer.layer
+ },
+ asset_type: layer.asset_type || "spot",
+ asset_category: layer.categories,
+ asset_item: layer.item_name || layer.layer_name.toLowerCase()
+ };
+ // Alloy v2
+ if (layer.styleid) {
+ options.http_options.styleid = layer.styleid;
+ }
+ // Alloy v1
+ if (layer.version) {
+ options.http_options.layerVersion = layer.version;
+ }
+ if (layer.max_resolution) {
+ options.max_resolution = layer.max_resolution;
+ }
+ if (layer.snap_threshold || layer.snap_threshold === 0) {
+ options.snap_threshold = layer.snap_threshold;
+ }
+ fixmystreet.assets.add(defaults, options);
+ }
+ });
+};
+
})();
diff --git a/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js b/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js
index 171f200ff..98a3a68a5 100644
--- a/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js
+++ b/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js
@@ -23,6 +23,8 @@ body_validation_rules = {
'Buckinghamshire Council': confirm_validation_rules,
'Cheshire East Council': confirm_validation_rules,
'Hounslow Borough Council': confirm_validation_rules,
+ 'Isle of Wight Council': confirm_validation_rules,
+ 'Island Roads': confirm_validation_rules,
'Lincolnshire County Council': confirm_validation_rules,
'Northamptonshire County Council': {
title: {
diff --git a/web/cobrands/fixmystreet-uk-councils/roadworks.js b/web/cobrands/fixmystreet-uk-councils/roadworks.js
new file mode 100644
index 000000000..a3eec7b1f
--- /dev/null
+++ b/web/cobrands/fixmystreet-uk-councils/roadworks.js
@@ -0,0 +1,82 @@
+/* Using this file, you also need to include the JavaScript file
+ * OpenLayers.Projection.OrdnanceSurvey.js for the 27700 conversion, and an
+ * OpenLayers build that includes OpenLayers.Layer.SphericalMercator and
+ * OpenLayers.Format.GeoJSON.
+ */
+
+(function(){
+
+var roadworks_defaults = {
+ http_options: {
+ url: "https://tilma.mysociety.org/streetmanager.php"
+ },
+ srsName: "EPSG:27700",
+ format_class: OpenLayers.Format.GeoJSON,
+ strategy_class: OpenLayers.Strategy.FixMyStreet,
+ stylemap: fixmystreet.assets.stylemap_invisible,
+ non_interactive: true,
+ always_visible: true,
+ nearest_radius: 100,
+ road: true,
+ all_categories: true,
+ actions: {
+ found: function(layer, feature) {
+ $(".js-roadworks-message-" + layer.id).remove();
+ if (!fixmystreet.roadworks.filter || fixmystreet.roadworks.filter(feature)) {
+ fixmystreet.roadworks.display_message(feature);
+ return true;
+ }
+ },
+ not_found: function(layer) {
+ $(".js-roadworks-message-" + layer.id).remove();
+ }
+ }
+};
+
+fixmystreet.roadworks = {};
+
+// fixmystreet.map.layers[5].getNearestFeature(new OpenLayers.Geometry.Point(-0.835614, 51.816562).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:3857")), 10)
+
+fixmystreet.roadworks.config = {};
+
+fixmystreet.roadworks.display_message = function(feature) {
+ var attr = feature.attributes,
+ start = new Date(attr.start_date).toDateString(),
+ end = new Date(attr.end_date).toDateString(),
+ summary = attr.summary,
+ desc = attr.description;
+
+ var config = this.config,
+ summary_heading_text = config.summary_heading_text || 'Summary',
+ tag_top = config.tag_top || 'p',
+ colon = config.colon ? ':' : '';
+
+ var $msg = $('<div class="js-roadworks-message js-roadworks-message-' + feature.layer.id + ' box-warning"><' + tag_top + '>Roadworks are scheduled near this location, so you may not need to report your issue.</' + tag_top + '></div>');
+ var $dl = $("<dl></dl>").appendTo($msg);
+ $dl.append("<dt>Dates" + colon + "</dt>");
+ var $dates = $("<dd></dd>").appendTo($dl);
+ $dates.text(start + " until " + end);
+ if (config.extra_dates_text) {
+ $dates.append('<br>' + config.extra_dates_text);
+ }
+ $dl.append("<dt>" + summary_heading_text + colon + "</dt>");
+ $dl.append($("<dd></dd>").text(summary));
+ if (desc) {
+ $dl.append("<dt>Description" + colon + "</dt>");
+ $dl.append($("<dd></dd>").text(desc));
+ }
+ if (attr.promoter) {
+ $dl.append("<dt>Responsibility</dt>");
+ $dl.append($("<dd></dd>").text(attr.promoter));
+ }
+
+ if (config.text_after) {
+ $dl.append(config.text_after);
+ }
+
+ $msg.prependTo('#js-post-category-messages');
+};
+
+fixmystreet.assets.add(roadworks_defaults);
+
+})();