Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'collisions' into staging
- Loading branch information
Showing
9 changed files
with
1,572 additions
and
2,836 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* | ||
* Displaying collision information, with popups | ||
* | ||
*/ | ||
|
||
MapCollisions = { | ||
collisions_url: "<%= Geo::COLLISIONS_URL %>", | ||
collisions_key: "<%= Geo::COLLISIONS_API_KEY %>", | ||
map: null, | ||
layer: null, | ||
|
||
init: function(m) { | ||
this.map = m; | ||
l = new OpenLayers.Layer.Vector("Collisions", { | ||
projection: new OpenLayers.Projection("EPSG:4326"), | ||
strategies: [new OpenLayers.Strategy.BBOX({resFactor: 3, ratio: 1.5})], | ||
styleMap: MapStyle.collisionStyle(), | ||
protocol: new OpenLayers.Protocol.Script({ | ||
url: this.collisions_url, | ||
format: new OpenLayers.Format.FlatJSON({ | ||
getResultArray : function(obj){ return obj.collisions.collision}, | ||
getLat : function(obj) { return obj.latitude }, | ||
getLon : function(obj) { return obj.longitude } | ||
}), | ||
params: { | ||
key: this.collisions_key | ||
}, | ||
filterToParams: function(filter, params) { | ||
// serialise BBOX into n/s/e/w url parameters | ||
if (filter.type === OpenLayers.Filter.Spatial.BBOX) { | ||
params.w = filter.value.toArray()[0]; | ||
params.s = filter.value.toArray()[1]; | ||
params.e = filter.value.toArray()[2]; | ||
params.n = filter.value.toArray()[3]; | ||
} | ||
return params; | ||
} | ||
}) | ||
}); | ||
this.layer = l; | ||
l.setVisibility(false); | ||
m.addLayer(l); | ||
m.addControl(new OpenLayers.Control.SelectFeature(l, {id: 'collSelector', onSelect: MapCollisions.createPopup, onUnselect: MapCollisions.destroyPopup })); | ||
m.getControl('collSelector').activate(); | ||
m.getControl('collSelector').handlers.feature.stopDown = false; // Allow click-drag on polygons to move the map | ||
}, | ||
|
||
createPopup: function(feature) { | ||
feature.popup = new OpenLayers.Popup.FramedCloud("pop", | ||
feature.geometry.getBounds().getCenterLonLat(), | ||
null, | ||
'<h3><a href="' + feature.attributes.url + '">Collision ' + feature.attributes.accref + ' in ' + feature.attributes.accyr + '</a></h3>' + | ||
'<p>Date and time: ' + feature.attributes.datetime + '</p>' + | ||
'<p>Severity: ' + feature.attributes.severity + '</p>' + | ||
'<p><a href="' + feature.attributes.url + '">View full, detailed report at CycleStreets</a></p>', | ||
null, | ||
true, | ||
function() { MapCollisions.map.getControl('collSelector').unselectAll(); this.destroy(); } | ||
); | ||
map.addPopup(feature.popup); | ||
}, | ||
|
||
destroyPopup: function(feature) { | ||
feature.popup.destroy(); | ||
feature.popup = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for | ||
* full list of contributors). Published under the Clear BSD license. | ||
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the | ||
* full text of the license. */ | ||
|
||
/** | ||
* @requires OpenLayers/Format/JSON.js | ||
* @requires OpenLayers/Feature/Vector.js | ||
* @requires OpenLayers/Geometry/Point.js | ||
* @requires OpenLayers/Geometry/MultiPoint.js | ||
* @requires OpenLayers/Geometry/LineString.js | ||
* @requires OpenLayers/Geometry/MultiLineString.js | ||
* @requires OpenLayers/Geometry/Polygon.js | ||
* @requires OpenLayers/Geometry/MultiPolygon.js | ||
* @requires OpenLayers/Console.js | ||
*/ | ||
|
||
/** | ||
* Class: OpenLayers.Format.FlatJSON | ||
* Read JSON POI documents with no GeoJSON structure. | ||
* Create a new parser with the | ||
* <OpenLayers.Format.FlatJSON> constructor. | ||
* | ||
* Inherits from: | ||
* - <OpenLayers.Format> | ||
*/ | ||
OpenLayers.Format.FlatJSON = OpenLayers.Class(OpenLayers.Format, { | ||
|
||
/** | ||
* Method: getResultArray | ||
* Return the Array that cointains the items from | ||
* the obj. Method to be overriden | ||
* | ||
* Parameters: | ||
* obj - {Object} An object created from a JSON document | ||
* | ||
* Returns: | ||
* <Object> An array of items. | ||
*/ | ||
getResultArray: function(obj){ return obj.results}, | ||
|
||
/** | ||
* Method: getLat | ||
* Return the latitude value contained in the obj. | ||
* Method to be overriden | ||
* | ||
* Parameters: | ||
* obj - {Object} An object item from a JSON object | ||
* | ||
* Returns: | ||
* A number | ||
*/ | ||
getLat: function(obj){ return obj.lat }, | ||
/** | ||
* Method: getLon | ||
* Return the longitude value contained in the obj. | ||
* Method to be overriden | ||
* | ||
* Parameters: | ||
* obj - {Object} An object item from a JSON object | ||
* | ||
* Returns: | ||
* A number | ||
*/ | ||
getLon: function(obj){ return obj.lon }, | ||
|
||
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); | ||
return; | ||
} | ||
var res = this.getResultArray(obj); | ||
if (!res){ | ||
OpenLayers.Console.error("Can't find the results Array : "+ json); | ||
return; | ||
} | ||
results = this.parseFeatures(res,this); | ||
return results; | ||
}, | ||
|
||
parseFeatures: function(obj,format){ | ||
var features = []; | ||
for (var i = 0; i< obj.length; i++){ | ||
var feat = this.parseFeature(obj[i],format); | ||
if (feat) features.push(feat); | ||
} | ||
return features; | ||
}, | ||
|
||
|
||
/** | ||
* Method: parseFeature | ||
* Convert an object item from a JSON into an | ||
* <OpenLayers.Feature.Vector>. | ||
* | ||
* Parameters: | ||
* obj - {Object} An object created from a GeoJSON object | ||
* | ||
* Returns: | ||
* {<OpenLayers.Feature.Vector>} A feature. | ||
*/ | ||
parseFeature: function(obj,format) { | ||
var feature, geometry, attributes, bbox; | ||
attributes=new Object(); | ||
for (att in obj){ | ||
attributes[att]=obj[att]; | ||
} | ||
|
||
try { | ||
var lat, lon; | ||
lat = format.getLat(obj); | ||
lon = format.getLon(obj); | ||
if (isNaN(parseFloat(lat)) || !isFinite(lat)) return; | ||
if (isNaN(parseFloat(lon)) || !isFinite(lon)) return; | ||
geometry = new OpenLayers.Geometry.Point(lon,lat); | ||
} catch(err) { | ||
// deal with bad geometries | ||
//throw err; | ||
return; | ||
} | ||
|
||
bbox = (geometry && geometry.bbox) || obj.bbox; | ||
|
||
feature = new OpenLayers.Feature.Vector(geometry, attributes); | ||
if(bbox) { | ||
feature.bounds = OpenLayers.Bounds.fromArray(bbox); | ||
} | ||
if(obj.id) { | ||
feature.fid = obj.id; | ||
} | ||
return feature; | ||
}, | ||
|
||
|
||
CLASS_NAME: "OpenLayers.Format.FlatJSON" | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- m = display_map(issue, geometry_issue_path(issue, :json)) do |map, page| | ||
- add_collision_layer(map, page) | ||
%div#map | ||
!= m.to_html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
module MapLayers | ||
OPENCYCLEMAP = OpenLayers::Layer::OSM.new("OpenCycleMap", ["a", "b", "c"].map {|k| "http://#{k}.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"}, {opacity: 0.8}) | ||
OS_STREETVIEW = OpenLayers::Layer::OSM.new("OS StreetView", ["a", "b", "c"].map {|k| "http://#{k}.os.openstreetmap.org/sv/${z}/${x}/${y}.png"}, {opacity: 0.8}) | ||
OPENCYCLEMAP = OpenLayers::Layer::OSM.new("OpenCycleMap", ["a", "b", "c"].map {|k| "http://#{k}.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"}, | ||
{opacity: 0.8, tileOptions: {crossOriginKeyword: :null}}) | ||
OS_STREETVIEW = OpenLayers::Layer::OSM.new("OS StreetView", ["a", "b", "c"].map {|k| "http://#{k}.os.openstreetmap.org/sv/${z}/${x}/${y}.png"}, | ||
{opacity: 0.8, tileOptions: {crossOriginKeyword: :null}}) | ||
end |
Oops, something went wrong.