diff options
Diffstat (limited to 'web/js')
-rw-r--r-- | web/js/dashboard.js | 36 | ||||
-rw-r--r-- | web/js/front.js | 7 | ||||
-rw-r--r-- | web/js/geolocation.js | 2 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 65 | ||||
-rw-r--r-- | web/js/map-OpenStreetMap.js | 1 | ||||
-rw-r--r-- | web/js/map-wmts-zurich.js | 107 |
6 files changed, 124 insertions, 94 deletions
diff --git a/web/js/dashboard.js b/web/js/dashboard.js index b35af2996..82b5e6188 100644 --- a/web/js/dashboard.js +++ b/web/js/dashboard.js @@ -1,7 +1,10 @@ $(function(){ + if ($('html').is('.ie9')) { + return; + } Chart.defaults.global.defaultFontSize = 16; - Chart.defaults.global.defaultFontFamily = $('body').css('font-family'); + // Chart.defaults.global.defaultFontFamily = $('body').css('font-family'); var colours = [ '#FF4343', // red @@ -24,7 +27,6 @@ $(function(){ var setUpLabelsForChart = function(chart){ var $parent = $(chart.chart.canvas).parent(); - var xGutterInPixels = 30; var lasty = 0; $.each(chart.config.data.datasets, function(datasetIndex, dataset){ @@ -35,8 +37,7 @@ $(function(){ y = lasty; } $label.css({ - top: y, - left: latestPoint._model.x + xGutterInPixels + top: y }); lasty = y + $label.height() + 8; }); @@ -53,6 +54,26 @@ $(function(){ return pointRadius; }; + // Wraps a row label onto two equal equal lines, + // if it is longer than 4 words. + var linewrapLabel = function(text) { + if ( text.split(' ').length < 5 ) { + return text; + } + + var middle = Math.floor(text.length / 2); + var before = text.lastIndexOf(' ', middle); + var after = text.indexOf(' ', middle + 1); + + if (before < after) { + middle = after; + } else { + middle = before; + } + + return [ text.substr(0, middle), text.substr(middle + 1) ]; + }; + var makeSparkline = function makeSparkline($el, valuesStr, color, title){ var values = []; var labels = []; @@ -180,7 +201,7 @@ $(function(){ var rowValues = []; $trs.each(function(){ - rowLabels.push( $(this).find('th').text() ); + rowLabels.push( linewrapLabel($(this).find('th').text()) ); rowValues.push( parseInt($(this).find('td').text(), 10) ); }); @@ -206,7 +227,6 @@ $(function(){ ctx = chartInstance.ctx; ctx.font = Chart.helpers.fontString( Chart.defaults.global.defaultFontSize * 0.8, 'bold', Chart.defaults.global.defaultFontFamily); - ctx.textAlign = 'right'; ctx.textBaseline = 'middle'; this.data.datasets.forEach(function (dataset, i) { @@ -218,10 +238,12 @@ $(function(){ var gutter = (bar._model.height - (Chart.defaults.global.defaultFontSize * 0.8)) / 2; var textX; if (width_text + 2 * gutter > width_bar) { - textX = bar._model.x + 2 * gutter; + textX = bar._model.x + gutter; + ctx.textAlign = 'left'; ctx.fillStyle = bar._model.backgroundColor; } else { textX = bar._model.x - gutter; + ctx.textAlign = 'right'; ctx.fillStyle = '#fff'; } ctx.fillText( dataValue, textX, bar._model.y ); diff --git a/web/js/front.js b/web/js/front.js index 8471972d4..67486888b 100644 --- a/web/js/front.js +++ b/web/js/front.js @@ -15,4 +15,11 @@ document.getElementById('pc').focus(); var link = around_links[i]; link.href = link.href + (link.href.indexOf('?') > -1 ? '&js=1' : '?js=1'); } + + var lk = document.querySelector('span.report-a-problem-btn'); + if (lk.addEventListener) { + lk.addEventListener('click', function(){ + scrollTo(0,0); + }); + } })(); diff --git a/web/js/geolocation.js b/web/js/geolocation.js index 3c2cf04df..fbef4d7ea 100644 --- a/web/js/geolocation.js +++ b/web/js/geolocation.js @@ -30,7 +30,7 @@ fixmystreet.geolocate = function(element, success_callback) { var link = document.getElementById('geolocate_link'); if (!link) { return; } var https = window.location.protocol.toLowerCase() === 'https:'; - if ('geolocation' in navigator && https) { + if ('geolocation' in navigator && https && window.addEventListener) { fixmystreet.geolocate(link, function(pos) { var latitude = pos.coords.latitude.toFixed(6); var longitude = pos.coords.longitude.toFixed(6); diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 0f6cca2b5..868e2333e 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -1,3 +1,15 @@ +if (!Object.keys) { + Object.keys = function(obj) { + var result = []; + for (var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + result.push(prop); + } + } + return result; + }; +} + var fixmystreet = fixmystreet || {}; fixmystreet.utils = fixmystreet.utils || {}; @@ -8,7 +20,7 @@ $.extend(fixmystreet.utils, { if (!location.search) { return qs; } - location.search.substring(1).split(/[;&]/).forEach(function(i) { + $.each(location.search.substring(1).split(/[;&]/), function(n, i) { var s = i.split('='), k = s[0], v = s[1] && decodeURIComponent(s[1].replace(/\+/g, ' ')); @@ -40,19 +52,27 @@ $.extend(fixmystreet.utils, { }; $.extend(fixmystreet.maps, { - // This function might be passed either an OpenLayers.LonLat (so has - // lon and lat), or an OpenLayers.Geometry.Point (so has x and y). update_pin: function(lonlat) { + // This function might be passed either an OpenLayers.LonLat (so has + // lon and lat), or an OpenLayers.Geometry.Point (so has x and y). + if (lonlat.x !== undefined && lonlat.y !== undefined) { + // It's a Point, convert to a LatLon + lonlat = new OpenLayers.LonLat(lonlat.x, lonlat.y); + } + var transformedLonlat = lonlat.clone().transform( fixmystreet.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326") ); - var lat = transformedLonlat.lat || transformedLonlat.y; - var lon = transformedLonlat.lon || transformedLonlat.x; + var lat = transformedLonlat.lat; + var lon = transformedLonlat.lon; document.getElementById('fixmystreet.latitude').value = lat; document.getElementById('fixmystreet.longitude').value = lon; + + $(fixmystreet).trigger('maps:update_pin', [ lonlat ]); + return { 'url': { 'lon': lon, 'lat': lat }, 'state': { 'lon': lonlat.lon, 'lat': lonlat.lat } @@ -88,6 +108,7 @@ $.extend(fixmystreet.utils, { fixmystreet.markers.features[0].move(lonlat); } else { var markers = fixmystreet.maps.markers_list( [ [ lonlat.lat, lonlat.lon, fixmystreet.pin_new_report_colour ] ], false ); + fixmystreet.bbox_strategy.layer.protocol.abort(fixmystreet.bbox_strategy.response); fixmystreet.bbox_strategy.deactivate(); fixmystreet.markers.removeAllFeatures(); fixmystreet.markers.addFeatures( markers ); @@ -117,7 +138,7 @@ $.extend(fixmystreet.utils, { fixmystreet.map.getProjectionObject() ); } - var id = +pin[3]; + var id = pin[3] === undefined ? pin[3] : +pin[3]; var marker_size = (id === window.selected_problem_id) ? selected_size : size; var marker = new OpenLayers.Feature.Vector(loc, { colour: pin[2], @@ -238,18 +259,18 @@ $.extend(fixmystreet.utils, { * the spinner in the DOM. */ loading_spinner: { - count: 0, + count: {}, show: function() { - fixmystreet.maps.loading_spinner.count++; - if (fixmystreet.maps.loading_spinner.count > 0) { + fixmystreet.maps.loading_spinner.count[this.id] = 1; + if (Object.keys(fixmystreet.maps.loading_spinner.count).length) { // Show the loading indicator over the map $('#loading-indicator').removeClass('hidden'); $('#loading-indicator').attr('aria-hidden', false); } }, hide: function() { - fixmystreet.maps.loading_spinner.count--; - if (fixmystreet.maps.loading_spinner.count <= 0) { + delete fixmystreet.maps.loading_spinner.count[this.id]; + if (!Object.keys(fixmystreet.maps.loading_spinner.count).length) { // Remove loading indicator $('#loading-indicator').addClass('hidden'); $('#loading-indicator').attr('aria-hidden', true); @@ -290,6 +311,9 @@ $.extend(fixmystreet.utils, { return; } + // clickFeature operates on touchstart, we do not want the map click taking place on touchend! + fixmystreet.maps.click_control.deactivate(); + // All of this, just so that ctrl/cmd-click on a pin works?! var event; if (typeof window.MouseEvent === 'function') { @@ -321,20 +345,6 @@ $.extend(fixmystreet.utils, { fixmystreet.markers.refresh({force: true}); } - function parse_query_string() { - var qs = {}; - if (!location.search) { - return qs; - } - location.search.substring(1).split(/[&;]/).forEach(function(i) { - var s = i.split('='), - k = s[0], - v = s[1] && decodeURIComponent(s[1].replace(/\+/g, ' ')); - qs[k] = v; - }); - return qs; - } - function replace_query_parameter(qs, id, key) { var value = $('#' + id).val(); if (value) { @@ -570,6 +580,9 @@ $.extend(fixmystreet.utils, { }); fixmystreet.markers.events.register( 'loadstart', null, fixmystreet.maps.loading_spinner.show); fixmystreet.markers.events.register( 'loadend', null, fixmystreet.maps.loading_spinner.hide); + OpenLayers.Request.XMLHttpRequest.onabort = function() { + fixmystreet.markers.events.triggerEvent("loadend", {response: null}); + }; var markers = fixmystreet.maps.markers_list( fixmystreet.pins, true ); fixmystreet.markers.addFeatures( markers ); @@ -710,7 +723,7 @@ $.extend(fixmystreet.utils, { } if (document.getElementById('mapForm')) { - var click = new OpenLayers.Control.Click(); + var click = fixmystreet.maps.click_control = new OpenLayers.Control.Click(); fixmystreet.map.addControl(click); click.activate(); } diff --git a/web/js/map-OpenStreetMap.js b/web/js/map-OpenStreetMap.js index a742e61ba..4165f8ee4 100644 --- a/web/js/map-OpenStreetMap.js +++ b/web/js/map-OpenStreetMap.js @@ -5,6 +5,7 @@ fixmystreet.maps.config = function() { } fixmystreet.controls = [ new OpenLayers.Control.ArgParser(), + new OpenLayers.Control.Attribution(), //new OpenLayers.Control.LayerSwitcher(), new OpenLayers.Control.Navigation(), new OpenLayers.Control.PermalinkFMS(permalink_id), diff --git a/web/js/map-wmts-zurich.js b/web/js/map-wmts-zurich.js index 0a753e831..eda0fbf44 100644 --- a/web/js/map-wmts-zurich.js +++ b/web/js/map-wmts-zurich.js @@ -4,112 +4,99 @@ // From 'fullExtent' from http://www.gis.stadt-zuerich.ch/maps/rest/services/tiled95/LuftbildHybrid/MapServer?f=pjson fixmystreet.maps.layer_bounds = new OpenLayers.Bounds( - 2674687.5, // W - 1240500, // S - 2690000, // E - 1255500); // N + 2672499, // W + 1238999, // S + 2689999, // E + 1256999); // N fixmystreet.maps.matrix_ids = [ - // The two highest zoom levels are pretty much useless so they're disabled. - // { - // "matrixHeight": 882, - // "scaleDenominator": 241905.24571522293, - // "identifier": "0", - // "tileWidth": 512, - // "supportedCRS": "urn:ogc:def:crs:EPSG::2056", - // "tileHeight": 512, - // "matrixWidth": 868 - // }, - // { - // "matrixHeight": 1764, - // "scaleDenominator": 120952.62285761147, - // "identifier": "1", - // "tileWidth": 512, - // "supportedCRS": "urn:ogc:def:crs:EPSG::2056", - // "tileHeight": 512, - // "matrixWidth": 1735 - // }, - { - "matrixHeight": 3527, - "scaleDenominator": 60476.31142880573, + "matrixHeight": 7, + "scaleDenominator": 241904.761905, + "identifier": "0", + "tileWidth": 512, + "tileHeight": 512, + "matrixWidth": 13 + }, + { + "matrixHeight": 14, + "scaleDenominator": 120952.380952, + "identifier": "1", + "tileWidth": 512, + "tileHeight": 512, + "matrixWidth": 25 + }, + { + "matrixHeight": 28, + "scaleDenominator": 60476.1904761, "identifier": "2", "tileWidth": 512, - "supportedCRS": "urn:ogc:def:crs:EPSG::2056", "tileHeight": 512, - "matrixWidth": 3470 + "matrixWidth": 49 }, { - "matrixHeight": 7053, - "scaleDenominator": 30238.155714402867, + "matrixHeight": 56, + "scaleDenominator": 30238.0952382, "identifier": "3", "tileWidth": 512, - "supportedCRS": "urn:ogc:def:crs:EPSG::2056", "tileHeight": 512, - "matrixWidth": 6939 + "matrixWidth": 97 }, { - "matrixHeight": 14106, - "scaleDenominator": 15119.077857201433, + "matrixHeight": 111, + "scaleDenominator": 15119.0476189, "identifier": "4", "tileWidth": 512, - "supportedCRS": "urn:ogc:def:crs:EPSG::2056", "tileHeight": 512, - "matrixWidth": 13877 + "matrixWidth": 194 }, { - "matrixHeight": 28211, - "scaleDenominator": 7559.538928600717, + "matrixHeight": 222, + "scaleDenominator": 7559.52380964, "identifier": "5", "tileWidth": 512, - "supportedCRS": "urn:ogc:def:crs:EPSG::2056", "tileHeight": 512, - "matrixWidth": 27753 + "matrixWidth": 388 }, { - "matrixHeight": 56422, - "scaleDenominator": 3779.7694643003583, + "matrixHeight": 443, + "scaleDenominator": 3779.76190464, "identifier": "6", "tileWidth": 512, - "supportedCRS": "urn:ogc:def:crs:EPSG::2056", "tileHeight": 512, - "matrixWidth": 55505 + "matrixWidth": 776 }, { - "matrixHeight": 112844, - "scaleDenominator": 1889.8847321501792, + "matrixHeight": 886, + "scaleDenominator": 1889.8809525, "identifier": "7", "tileWidth": 512, - "supportedCRS": "urn:ogc:def:crs:EPSG::2056", "tileHeight": 512, - "matrixWidth": 111010 + "matrixWidth": 1551 }, { - "matrixHeight": 225687, - "scaleDenominator": 944.9423660750896, + "matrixHeight": 1772, + "scaleDenominator": 944.940476071, "identifier": "8", "tileWidth": 512, - "supportedCRS": "urn:ogc:def:crs:EPSG::2056", "tileHeight": 512, - "matrixWidth": 222020 + "matrixWidth": 3101 }, { - "matrixHeight": 451374, - "scaleDenominator": 472.4711830375448, + "matrixHeight": 3544, + "scaleDenominator": 472.470238214, "identifier": "9", "tileWidth": 512, - "supportedCRS": "urn:ogc:def:crs:EPSG::2056", "tileHeight": 512, - "matrixWidth": 444039 + "matrixWidth": 6201 }, { - "matrixHeight": 902748, - "scaleDenominator": 236.2355915187724, + "matrixHeight": 7087, + "scaleDenominator": 236.235118929, "identifier": "10", "tileWidth": 512, - "supportedCRS": "urn:ogc:def:crs:EPSG::2056", "tileHeight": 512, - "matrixWidth": 888078 + "matrixWidth": 12402 } ]; |