diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-07-11 16:40:22 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-07-11 16:40:22 +0100 |
commit | 74ce84b43c0e714849d7ad021fb0400356ce2fa8 (patch) | |
tree | d96ad51f8cd6f14a6526ec282ad7e70d3eec25c6 /web/js | |
parent | 0c5549a60ef3d86d672926d6e71c00cafff8326b (diff) | |
parent | 03ad5de783ac71695b1ce0d377dde549fc7311cb (diff) |
Merge branch '1351-report-list-ajax'
Diffstat (limited to 'web/js')
-rw-r--r-- | web/js/fixmystreet.js | 210 | ||||
-rw-r--r-- | web/js/history.polyfill.min.js | 35 | ||||
-rw-r--r-- | web/js/jquery.ba-hashchange.min.js | 9 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 1014 | ||||
-rw-r--r-- | web/js/map-OpenStreetMap.js | 4 | ||||
-rw-r--r-- | web/js/map-bing-ol.js | 8 | ||||
-rw-r--r-- | web/js/map-fms.js | 23 | ||||
-rw-r--r-- | web/js/map-google-ol.js | 5 | ||||
-rw-r--r-- | web/js/map-google.js | 494 | ||||
-rw-r--r-- | web/js/map-streetview.js | 4 | ||||
-rw-r--r-- | web/js/map-toner-lite.js | 4 | ||||
-rw-r--r-- | web/js/map-wmts-bristol.js | 10 | ||||
-rw-r--r-- | web/js/map-wmts-zurich.js | 96 |
13 files changed, 810 insertions, 1106 deletions
diff --git a/web/js/fixmystreet.js b/web/js/fixmystreet.js deleted file mode 100644 index 0a15982f5..000000000 --- a/web/js/fixmystreet.js +++ /dev/null @@ -1,210 +0,0 @@ -/* - * fixmystreet.js - * FixMyStreet JavaScript used by all cobrands. - * With the JavaScript written more proper like. - */ - -(function($){ - -/* - Deal with changes to category by asking for details from the server. - */ -$(function(){ - - var $html = $('html'); - - // Add a class to the whole page saying JavaScript is enabled (for CSS and so on) - $html.removeClass('no-js').addClass('js'); - - // Preload the new report pin - if ( typeof fixmystreet !== 'undefined' && typeof fixmystreet.pin_prefix !== 'undefined' ) { - document.createElement('img').src = fixmystreet.pin_prefix + 'pin-green.png'; - } else { - document.createElement('img').src = '/i/pin-green.png'; - } - - // Focus on postcode box on front page - $('#pc').focus(); - - // In case we've come here by clicking back to a form that disabled a submit button - $('input[type=submit]').removeAttr('disabled'); - - // Questionnaire hide/showings - if (!$('#been_fixed_no').prop('checked') && !$('#been_fixed_unknown').prop('checked')) { - $('.js-another-questionnaire').hide(); - } - $('#been_fixed_no').on('click', function() { - $('.js-another-questionnaire').show('fast'); - }); - $('#been_fixed_unknown').on('click', function() { - $('.js-another-questionnaire').show('fast'); - }); - $('#been_fixed_yes').on('click', function() { - $('.js-another-questionnaire').hide('fast'); - }); - - // Form validation - - // FIXME - needs to use translated string - jQuery.validator.addMethod('validCategory', function(value, element) { - return this.optional(element) || value != '-- Pick a category --'; }, translation_strings.category ); - - var form_submitted = 0; - var submitted = false; - - $("form.validate").each(function(){ - $(this).validate({ - rules: validation_rules, - messages: translation_strings, - onkeyup: false, - onfocusout: false, - errorElement: 'div', - errorClass: 'form-error', - // we do this to stop things jumping around on blur - success: function (err) { if ( form_submitted ) { err.addClass('label-valid').removeClass('label-valid-hidden').html( ' ' ); } else { err.addClass('label-valid-hidden'); } }, - errorPlacement: function( error, element ) { - // Different for old/new style design - if ($('.form-field').length) { - element.parent('div.form-field').before( error ); - } else { - element.before( error ); - } - }, - submitHandler: function(form) { - if (form.submit_problem) { - $('input[type=submit]', form).prop("disabled", true); - } - - form.submit(); - }, - // make sure we can see the error message when we focus on invalid elements - showErrors: function( errorMap, errorList ) { - if ( submitted && errorList.length ) { - $(window).scrollTop( $(errorList[0].element).offset().top - 120 ); - } - this.defaultShowErrors(); - submitted = false; - }, - invalidHandler: function(form, validator) { submitted = true; } - }); - }); - - $('input[type=submit]').click( function(e) { form_submitted = 1; } ); - - /* set correct required status depending on what we submit - * NB: need to add things to form_category as the JS updating - * of this we do after a map click removes them */ - $('#submit_sign_in').click( function(e) { - $('#form_category').addClass('required validCategory').removeClass('valid'); - $('#form_name').removeClass(); - $('#form_first_name').removeClass(); - $('#form_last_name').removeClass(); - $('#form_fms_extra_title').removeClass(); - } ); - - $('#submit_register').click( function(e) { - $('#form_category').addClass('required validCategory').removeClass('valid'); - $('#form_name').addClass('required'); - if ( $('#mapForm').length ) { - $('#form_name').addClass('validName'); - } - $('#form_first_name').addClass('required'); - $('#form_last_name').addClass('required'); - $('#form_fms_extra_title').addClass('required'); - } ); - - $('#problem_submit > input[type="submit"]').click( function(e) { - $('#form_category').addClass('required validCategory').removeClass('valid'); - $('#form_name').addClass('required'); - if ( $('#mapForm').length ) { - $('#form_name').addClass('validName'); - } - $('#form_first_name').addClass('required'); - $('#form_last_name').addClass('required'); - $('#form_fms_extra_title').addClass('required'); - } ); - - $('#update_post').click( function(e) { - $('#form_name').addClass('required').removeClass('valid'); - } ); - - $('#facebook_sign_in, #twitter_sign_in').click(function(e){ - $('#form_email').removeClass(); - $('#form_rznvy').removeClass(); - $('#email').removeClass(); - }); - - // Geolocation - if (geo_position_js.init()) { - var link = '<a href="LINK" id="geolocate_link">… ' + translation_strings.geolocate + '</a>'; - $('form[action="/alert/list"]').append(link.replace('LINK','/alert/list')); - if ($('body.frontpage').length) { - $('#postcodeForm').after(link.replace('LINK','/around')); - } else{ - $('#postcodeForm').append(link.replace('LINK','/around')); - } - $('#geolocate_link').click(function(e) { - var $link = $(this); - e.preventDefault(); - // Spinny thing! - if($('.mobile').length){ - $link.append(' <img src="/cobrands/fixmystreet/images/spinner-black.gif" alt="" align="bottom">'); - }else{ - var spincolor = $('<span>').css("color","white").css("color") === $('#front-main').css("background-color")? 'white' : 'yellow'; - $link.append(' <img src="/cobrands/fixmystreet/images/spinner-' + spincolor + '.gif" alt="" align="bottom">'); - } - geo_position_js.getCurrentPosition(function(pos) { - $link.find('img').remove(); - var latitude = pos.coords.latitude; - var longitude = pos.coords.longitude; - var page = $link.attr('href'); - location.href = page + '?latitude=' + latitude + ';longitude=' + longitude; - }, function(err) { - $link.find('img').remove(); - if (err.code == 1) { // User said no - $link.html(translation_strings.geolocation_declined); - } else if (err.code == 2) { // No position - $link.html(translation_strings.geolocation_no_position); - } else if (err.code == 3) { // Too long - $link.html(translation_strings.geolocation_no_result); - } else { // Unknown - $link.html(translation_strings.geolocation_unknown); - } - }, { - enableHighAccuracy: true, - timeout: 10000 - }); - }); - } - - // Delegation is necessary because #form_category may be replaced during the lifetime of the page - $("#problem_form").on("change.category", "select#form_category", function(){ - var args = { - category: $(this).val() - }; - - args.latitude = $('input[name="latitude"]').val(); - args.longitude = $('input[name="longitude"]').val(); - - $.getJSON('/report/new/category_extras', args, function(data) { - var $category_meta = $('#category_meta'); - if ( data.category_extra ) { - if ( $category_meta.length ) { - $category_meta.html( data.category_extra ); - } else { - $('#form_category_row').after( data.category_extra ); - } - } else { - $category_meta.empty(); - } - }); - }); - - // Map form doesn't work in some browsers with HTML5 validation and hidden form, so - // we disable validation by default, and add it in the JS case. - // For some reason, the removeAttr doesn't work if we place it at beginning. - $('#mapForm').removeAttr('novalidate'); -}); - -})(jQuery); - diff --git a/web/js/history.polyfill.min.js b/web/js/history.polyfill.min.js new file mode 100644 index 000000000..f773e6bef --- /dev/null +++ b/web/js/history.polyfill.min.js @@ -0,0 +1,35 @@ +/*! + * History API JavaScript Library v4.2.7 + * + * Support: IE6+, FF3+, Opera 9+, Safari, Chrome and other + * + * Copyright 2011-2015, Dmitrii Pakhtinov ( spb.piksel@gmail.com ) + * + * http://spb-piksel.ru/ + * + * MIT license: + * http://www.opensource.org/licenses/mit-license.php + * + * Update: 2016-03-08 16:57 + */ +(function(q){if("function"===typeof define&&define.amd){if("undefined"!==typeof requirejs){var w="[history"+(new Date).getTime()+"]",l=requirejs.onError;q.toString=function(){return w};requirejs.onError=function(q){-1===q.message.indexOf(w)&&l.call(requirejs,q)}}define([],q)}if("object"===typeof exports&&"undefined"!==typeof module)module.exports=q();else return q()})(function(){var i=!0,k=null,p=!1;function q(a,b){var c=e.history!==r;c&&(e.history=r);a.apply(r,b);c&&(e.history=m)}function w(){}function l(a,b,c){if(a!=k&&""!==a&&!b){var b=l(),g=f.getElementsByTagName("base")[0]; +!c&&(g&&g.getAttribute("href"))&&(g.href=g.href,b=l(g.href,k,i));c=b.e;g=b.h;a=""+a;a=/^(?:\w+\:)?\/\//.test(a)?0===a.indexOf("/")?g+a:a:g+"//"+b.g+(0===a.indexOf("/")?a:0===a.indexOf("?")?c+a:0===a.indexOf("#")?c+b.f+a:c.replace(/[^\/]+$/g,"")+a)}else if(a=b?a:d.href,!j||c)a=a.replace(/^[^#]*/,"")||"#",a=d.protocol.replace(/:.*$|$/,":")+"//"+d.host+h.basepath+a.replace(RegExp("^#[/]?(?:"+h.type+")?"),"");R.href=a;var a=/(?:([a-zA-Z0-9\-]+\:))?(?:\/\/(?:[^@]*@)?([^\/:\?#]+)(?::([0-9]+))?)?([^\?#]*)(?:(\?[^#]+)|\?)?(?:(#.*))?/.exec(R.href), +b=a[2]+(a[3]?":"+a[3]:""),c=a[4]||"/",g=a[5]||"",e="#"===a[6]?"":a[6]||"",S=c+g+e,x=c.replace(RegExp("^"+h.basepath,"i"),h.type)+g;return{a:a[1]+"//"+b+S,h:a[1],g:b,i:a[2],k:a[3]||"",e:c,f:g,b:e,c:S,j:x,d:x+e}}function ba(){var a;try{a=e.sessionStorage,a.setItem(F+"t","1"),a.removeItem(F+"t")}catch(b){a={getItem:function(a){a=f.cookie.split(a+"=");return 1<a.length&&a.pop().split(";").shift()||"null"},setItem:function(a){var b={};if(b[d.href]=m.state)f.cookie=a+"="+s.stringify(b)}}}try{n=s.parse(a.getItem(F))|| +{}}catch(c){n={}}v(y+"unload",function(){a.setItem(F,s.stringify(n))},p)}function z(a,b,c,g){var d=0;c||(c={set:w},d=1);var f=!c.set,x=!c.get,K={configurable:i,set:function(){f=1},get:function(){x=1}};try{D(a,b,K),a[b]=a[b],D(a,b,c)}catch(ka){}if(!f||!x)if(a.__defineGetter__&&(a.__defineGetter__(b,K.get),a.__defineSetter__(b,K.set),a[b]=a[b],c.get&&a.__defineGetter__(b,c.get),c.set&&a.__defineSetter__(b,c.set)),!f||!x){if(d)return p;if(a===e){try{var ca=a[b];a[b]=k}catch(l){}if("execScript"in e)e.execScript("Public "+ +b,"VBScript"),e.execScript("var "+b+";","JavaScript");else try{D(a,b,{value:w})}catch(m){"onpopstate"===b&&(v("popstate",c=function(){L("popstate",c,p);var b=a.onpopstate;a.onpopstate=k;setTimeout(function(){a.onpopstate=b},1)},p),T=0)}a[b]=ca}else try{try{var h=G.create(a);D(G.getPrototypeOf(h)===a?h:a,b,c);for(var j in a)"function"===typeof a[j]&&(h[j]=a[j].bind(a));try{g.call(h,h,a)}catch(n){}a=h}catch(o){D(a.constructor.prototype,b,c)}}catch(q){return p}}return a}function da(a,b,c){c=c||{};a= +a===M?d:a;c.set=c.set||function(c){a[b]=c};c.get=c.get||function(){return a[b]};return c}function ea(a,b,c){a in A?A[a].push(b):3<arguments.length?v(a,b,c,arguments[3]):v(a,b,c)}function fa(a,b,c){var e=A[a];if(e)for(a=e.length;a--;){if(e[a]===b){e.splice(a,1);break}}else L(a,b,c)}function H(a,b){var c=(""+("string"===typeof a?a:a.type)).replace(/^on/,""),g=A[c];if(g){b="string"===typeof a?b:a;if(b.target==k)for(var d=["target","currentTarget","srcElement","type"];a=d.pop();)b=z(b,a,{get:"type"=== +a?function(){return c}:function(){return e}});T&&(("popstate"===c?e.onpopstate:e.onhashchange)||w).call(e,b);for(var d=0,f=g.length;d<f;d++)g[d].call(e,b);return i}return ga(a,b)}function U(){var a=f.createEvent?f.createEvent("Event"):f.createEventObject();a.initEvent?a.initEvent("popstate",p,p):a.type="popstate";a.state=m.state;H(a)}function u(a,b,c,e){j?B=d.href:(0===o&&(o=2),b=l(b,2===o&&-1!==(""+b).indexOf("#")),b.c!==l().c&&(B=e,c?d.replace("#"+b.d):d.hash=b.d));!I&&a&&(n[d.href]=a);E=p}function N(a){var b= +B;B=d.href;if(b){V!==d.href&&U();var a=a||e.event,b=l(b,i),c=l();a.oldURL||(a.oldURL=b.a,a.newURL=c.a);b.b!==c.b&&H(a)}}function W(a){setTimeout(function(){v("popstate",function(a){V=d.href;I||(a=z(a,"state",{get:function(){return m.state}}));H(a)},p)},0);!j&&(a!==i&&"location"in m)&&(X(t.hash),E&&(E=p,U()))}function ha(a){var a=a||e.event,b;a:{for(b=a.target||a.srcElement;b;){if("A"===b.nodeName)break a;b=b.parentNode}b=void 0}var c="defaultPrevented"in a?a.defaultPrevented:a.returnValue===p;b&& +("A"===b.nodeName&&!c)&&(c=l(),b=l(b.getAttribute("href",2)),c.a.split("#").shift()===b.a.split("#").shift()&&b.b&&(c.b!==b.b&&(t.hash=b.b),X(b.b),a.preventDefault?a.preventDefault():a.returnValue=p))}function X(a){var b=f.getElementById(a=(a||"").replace(/^#/,""));b&&(b.id===a&&"A"===b.nodeName)&&(a=b.getBoundingClientRect(),e.scrollTo(J.scrollLeft||0,a.top+(J.scrollTop||0)-(J.clientTop||0)))}function ia(){function a(a){var b=[],d="VBHistoryClass"+(new Date).getTime()+c++,g=["Class "+d],f;for(f in a)if(a.hasOwnProperty(f)){var h= +a[f];h&&(h.get||h.set)?(h.get&&g.push("Public "+("_"===f?"Default ":"")+"Property Get ["+f+"]","Call VBCVal([(accessors)].["+f+"].get.call(me),["+f+"])","End Property"),h.set&&g.push("Public Property Let ["+f+"](val)",h="Call [(accessors)].["+f+"].set.call(me,val)\nEnd Property","Public Property Set ["+f+"](val)",h)):(b.push(f),g.push("Public ["+f+"]"))}g.push("Private [(accessors)]","Private Sub Class_Initialize()","Set [(accessors)]="+d+"FactoryJS()","End Sub","End Class","Function "+d+"Factory()", +"Set "+d+"Factory=New "+d,"End Function");e.execScript(g.join("\n"),"VBScript");e[d+"FactoryJS"]=function(){return a};d=e[d+"Factory"]();for(g=0;g<b.length;g++)d[b[g]]=a[b[g]];return d}function b(a){var b=/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,c={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};return b.test(a)?'"'+a.replace(b,function(a){return a in c?c[a]:"\\u"+("0000"+ +a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}var c=e.execScript&&(e.execScript("var documentMsie/*@cc_on =1@*/;","JavaScript"),e.documentMsie);if(c&&!(f.documentMode&&7<f.documentMode)){var g=z,h=l().a,j=f.createElement("iframe");j.src="javascript:true;";j=J.firstChild.appendChild(j).contentWindow;e.execScript("Public history\nFunction VBCVal(o,r) If IsObject(o) Then Set r=o Else r=o End If End Function","VBScript");t={_:{get:M.toString}};m={back:r.back,forward:r.forward,go:r.go,emulate:k, +_:{get:function(){return"[object History]"}}};s={parse:function(a){try{return(new Function("","return "+a))()}catch(b){return k}},stringify:function(a){var c=(typeof a).charCodeAt(2);if(114===c)a=b(a);else if(109===c)a=isFinite(a)?""+a:"null";else if(111===c||108===c)a=""+a;else if(106===c)if(a){var e=(c="[object Array]"===G.prototype.toString.call(a))?"[":"{";if(c)for(var d=0;d<a.length;d++)e+=(0==d?"":",")+s.stringify(a[d]);else for(d in a)a.hasOwnProperty(d)&&(e+=(1==e.length?"":",")+b(d)+":"+ +s.stringify(a[d]));a=e+(c?"]":"}")}else a="null";else a="void 0";return a}};u=function(a,b,c,e,g){var f=j.document;0===o&&(o=2);b=l(b,2===o&&-1!==(""+b).indexOf("#"));E=p;if(b.c===l().c&&!g)a&&(n[d.href]=a);else{B=e;if(c)j.lfirst?(history.back(),u(a,b.a,0,e,1)):d.replace("#"+b.d);else if(b.a!=h||g)j.lfirst?g&&(g=0,a=n[d.href]):(j.lfirst=1,u(a,h,0,e,1)),f.open(),f.write('<script>lfirst=1;parent.location.hash="'+b.d.replace(/"/g,'\\"')+'";<\/script>'),f.close();!g&&a&&(n[d.href]=a)}};z=function(b,c, +d,f){g.apply(this,arguments)||(b===t?t[c]=d:b===m?(m[c]=d,"state"===c&&(t=a(t),e.history=m=a(m),e.execScript("var history = window.history;","JavaScript"))):b[c]=d.get&&d.get());return b};setInterval(function(){var a=l().a;if(a!=h){var b=f.createEventObject();b.oldURL=h;b.newURL=h=a;b.type="hashchange";N(b)}},100);e.JSON=s}}var e=("object"===typeof window?window:this)||{};if(!e.history||"emulate"in e.history)return e.history;var f=e.document,J=f.documentElement,G=e.Object,s=e.JSON,d=e.location,r= +e.history,m=r,O=r.pushState,Y=r.replaceState,j=function(){var a=e.navigator.userAgent;return(-1!==a.indexOf("Android 2.")||-1!==a.indexOf("Android 4.0"))&&-1!==a.indexOf("Mobile Safari")&&-1===a.indexOf("Chrome")&&-1===a.indexOf("Windows Phone")?p:!!O}(),I="state"in r,D=G.defineProperty,t=z({},"t")?{}:f.createElement("a"),y="",P=e.addEventListener?"addEventListener":(y="on")&&"attachEvent",Z=e.removeEventListener?"removeEventListener":"detachEvent",$=e.dispatchEvent?"dispatchEvent":"fireEvent",v= +e[P],L=e[Z],ga=e[$],h={basepath:"/",redirect:0,type:"/",init:0},F="__historyAPI__",R=f.createElement("a"),B=d.href,V="",T=1,E=p,o=0,n={},A={},C=f.title,Q,ja={onhashchange:k,onpopstate:k},aa={setup:function(a,b,c){h.basepath=(""+(a==k?h.basepath:a)).replace(/(?:^|\/)[^\/]*$/,"/");h.type=b==k?h.type:b;h.redirect=c==k?h.redirect:!!c},redirect:function(a,b){m.setup(b,a);b=h.basepath;if(e.top==e.self){var c=l(k,p,i).c,g=d.pathname+d.search;j?(g=g.replace(/([^\/])$/,"$1/"),c!=b&&RegExp("^"+b+"$","i").test(g)&& +d.replace(c)):g!=b&&(g=g.replace(/([^\/])\?/,"$1/?"),RegExp("^"+b,"i").test(g)&&d.replace(b+"#"+g.replace(RegExp("^"+b,"i"),h.type)+d.hash))}},pushState:function(a,b,c){var e=f.title;C!=k&&(f.title=C);O&&q(O,arguments);u(a,c);f.title=e;C=b},replaceState:function(a,b,c){var e=f.title;C!=k&&(f.title=C);delete n[d.href];Y&&q(Y,arguments);u(a,c,i);f.title=e;C=b},location:{set:function(a){0===o&&(o=1);e.location=a},get:function(){0===o&&(o=1);return t}},state:{get:function(){return"object"===typeof n[d.href]? +s.parse(s.stringify(n[d.href])):"undefined"!==typeof n[d.href]?n[d.href]:k}}},M={assign:function(a){!j&&0===(""+a).indexOf("#")?u(k,a):d.assign(a)},reload:function(a){d.reload(a)},replace:function(a){!j&&0===(""+a).indexOf("#")?u(k,a,i):d.replace(a)},toString:function(){return this.href},origin:{get:function(){return void 0!==Q?Q:!d.origin?d.protocol+"//"+d.hostname+(d.port?":"+d.port:""):d.origin},set:function(a){Q=a}},href:j?k:{get:function(){return l().a}},protocol:k,host:k,hostname:k,port:k,pathname:j? +k:{get:function(){return l().e}},search:j?k:{get:function(){return l().f}},hash:j?k:{set:function(a){u(k,(""+a).replace(/^(#|)/,"#"),p,B)},get:function(){return l().b}}};if(function(){var a=f.getElementsByTagName("script"),a=(a[a.length-1]||{}).src||"";(-1!==a.indexOf("?")?a.split("?").pop():"").replace(/(\w+)(?:=([^&]*))?/g,function(a,b,c){h[b]=(c||"").replace(/^(0|false)$/,"")});ia();v(y+"hashchange",N,p);var b=[M,t,ja,e,aa,m];I&&delete aa.state;for(var c=0;c<b.length;c+=2)for(var d in b[c])if(b[c].hasOwnProperty(d))if("object"!== +typeof b[c][d])b[c+1][d]=b[c][d];else{a=da(b[c],d,b[c][d]);if(!z(b[c+1],d,a,function(a,d){if(d===m)e.history=m=b[c+1]=a}))return L(y+"hashchange",N,p),p;b[c+1]===e&&(A[d]=A[d.substr(2)]=[])}m.setup();h.redirect&&m.redirect();h.init&&(o=1);!I&&s&&ba();if(!j)f[P](y+"click",ha,p);"complete"===f.readyState?W(i):(!j&&l().c!==h.basepath&&(E=i),v(y+"load",W,p));return i}())return m.emulate=!j,e[P]=ea,e[Z]=fa,e[$]=H,m}); diff --git a/web/js/jquery.ba-hashchange.min.js b/web/js/jquery.ba-hashchange.min.js deleted file mode 100644 index 3c607bae3..000000000 --- a/web/js/jquery.ba-hashchange.min.js +++ /dev/null @@ -1,9 +0,0 @@ -/* - * jQuery hashchange event - v1.3 - 7/21/2010 - * http://benalman.com/projects/jquery-hashchange-plugin/ - * - * Copyright (c) 2010 "Cowboy" Ben Alman - * Dual licensed under the MIT and GPL licenses. - * http://benalman.com/about/license/ - */ -(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);
\ No newline at end of file diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 1379d0fa5..f6e7e8a62 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -1,504 +1,514 @@ -// This function might be passed either an OpenLayers.LonLat (so has -// lon and lat) or an OpenLayers.Geometry.Point (so has x and y) -function fixmystreet_update_pin(lonlat) { - lonlat = lonlat.clone().transform( - fixmystreet.map.getProjectionObject(), - new OpenLayers.Projection("EPSG:4326") - ); - document.getElementById('fixmystreet.latitude').value = lonlat.lat || lonlat.y; - document.getElementById('fixmystreet.longitude').value = lonlat.lon || lonlat.x; - - $.getJSON('/report/new/ajax', { - latitude: $('#fixmystreet\\.latitude').val(), - longitude: $('#fixmystreet\\.longitude').val() - }, function(data) { - if (data.error) { - if (!$('#side-form-error').length) { - $('<div id="side-form-error"/>').insertAfter($('#side-form')); - } - $('#side-form-error').html('<h1>' + translation_strings.reporting_a_problem + '</h1><p>' + data.error + '</p>').show(); - $('#side-form').hide(); - $('body').removeClass('with-notes'); - return; - } - $('#side-form, #site-logo').show(); - var old_category = $("select#form_category").val(); - $('#councils_text').html(data.councils_text); - $('#form_category_row').html(data.category); - if ($("select#form_category option[value=\""+old_category+"\"]").length) { - $("select#form_category").val(old_category); +var fixmystreet = fixmystreet || {}; + +(function() { + + 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) { + 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; + + document.getElementById('fixmystreet.latitude').value = lat; + document.getElementById('fixmystreet.longitude').value = lon; + return { + 'url': { 'lon': lon, 'lat': lat }, + 'state': { 'lon': lonlat.lon, 'lat': lonlat.lat } + }; + }, + + display_around: function() { + // Required after changing the size of the map element + fixmystreet.map.updateSize(); + + // Dragging the map should fetch new local reports from server + fixmystreet.bbox_strategy.activate(); + + // Should not be able to drag normal pins!! + drag.deactivate(); + + // Force a redraw to return (de)selected marker to normal size + fixmystreet.markers.refresh({force: true}); + }, + + begin_report: function(lonlat) { + if (typeof lonlat.clone !== 'function') { + lonlat = new OpenLayers.LonLat(lonlat.lon, lonlat.lat); } - if ( data.extra_name_info && !$('#form_fms_extra_title').length ) { - // there might be a first name field on some cobrands - var lb = $('#form_first_name').prev(); - if ( lb.length === 0 ) { lb = $('#form_name').prev(); } - lb.before(data.extra_name_info); + + if (fixmystreet.page == 'new') { + /* Already have a pin */ + fixmystreet.markers.features[0].move(lonlat); + } else { + var markers = fixmystreet.maps.markers_list( [ [ lonlat.lat, lonlat.lon, 'green' ] ], false ); + fixmystreet.bbox_strategy.deactivate(); + fixmystreet.markers.removeAllFeatures(); + fixmystreet.markers.addFeatures( markers ); + drag.activate(); } - // If the category filter appears on the map and the user has selected - // something from it, then pre-fill the category field in the report, - // if it's a value already present in the drop-down. - var category = $("#filter_categories").val(); - if (category !== undefined && $("#form_category option[value="+category+"]").length) { - $("#form_category").val(category); + // check to see if markers are visible. We click the + // link so that it updates the text in case they go + // back + if ( ! fixmystreet.markers.getVisibility() ) { + $('#hide_pins_link').click(); } + return lonlat; + }, - var category_select = $("select#form_category"); - if (category_select.val() != '-- Pick a category --') { - category_select.change(); + markers_list: function(pins, transform) { + var markers = []; + var size = fixmystreet.maps.marker_size_for_zoom( + fixmystreet.map.getZoom() + fixmystreet.zoomOffset + ); + var selected_size = fixmystreet.maps.selected_marker_size_for_zoom( + fixmystreet.map.getZoom() + fixmystreet.zoomOffset + ); + for (var i=0; i<pins.length; i++) { + var pin = pins[i]; + var loc = new OpenLayers.Geometry.Point(pin[1], pin[0]); + if (transform) { + // The Strategy does this for us, so don't do it in that case. + loc.transform( + new OpenLayers.Projection("EPSG:4326"), + fixmystreet.map.getProjectionObject() + ); + } + var marker_size = (pin[3] === window.selected_problem_id) ? selected_size : size; + var marker = new OpenLayers.Feature.Vector(loc, { + colour: pin[2], + size: pin[5] || marker_size, + faded: 0, + id: pin[3], + title: pin[4] || '' + }); + markers.push( marker ); } - }); + return markers; + }, - if (!$('#side-form-error').is(':visible')) { - $('#side-form, #site-logo').show(); - window.scrollTo(0, 0); - } -} - -function fixmystreet_activate_drag() { - fixmystreet.drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, { - onComplete: function(feature, e) { - fixmystreet_update_pin( feature.geometry ); - } - } ); - fixmystreet.map.addControl( fixmystreet.drag ); - fixmystreet.drag.activate(); -} - -function fixmystreet_zoomToBounds(bounds) { - if (!bounds) { return; } - var center = bounds.getCenterLonLat(); - var z = fixmystreet.map.getZoomForExtent(bounds); - if ( z < 13 && $('html').hasClass('mobile') ) { - z = 13; - } - fixmystreet.map.setCenter(center, z); -} - -function fms_markers_list(pins, transform) { - var markers = []; - var size = fms_marker_size_for_zoom(fixmystreet.map.getZoom() + fixmystreet.zoomOffset); - for (var i=0; i<pins.length; i++) { - var pin = pins[i]; - var loc = new OpenLayers.Geometry.Point(pin[1], pin[0]); - if (transform) { - // The Strategy does this for us, so don't do it in that case. - loc.transform( - new OpenLayers.Projection("EPSG:4326"), - fixmystreet.map.getProjectionObject() - ); + markers_resize: function() { + var size = fixmystreet.maps.marker_size_for_zoom( + fixmystreet.map.getZoom() + fixmystreet.zoomOffset + ); + var selected_size = fixmystreet.maps.selected_marker_size_for_zoom( + fixmystreet.map.getZoom() + fixmystreet.zoomOffset + ); + for (var i = 0; i < fixmystreet.markers.features.length; i++) { + if (fixmystreet.markers.features[i].attributes.id == window.selected_problem_id) { + fixmystreet.markers.features[i].attributes.size = selected_size; + } else { + fixmystreet.markers.features[i].attributes.size = size; + } } - var marker = new OpenLayers.Feature.Vector(loc, { - colour: pin[2], - size: pin[5] || size, - faded: 0, - id: pin[3], - title: pin[4] || '' - }); - markers.push( marker ); - } - return markers; -} - -function fms_marker_size_for_zoom(zoom) { - if (zoom >= 15) { - return 'normal'; - } else if (zoom >= 13) { - return 'small'; - } else { - return 'mini'; - } -} + fixmystreet.markers.redraw(); + }, -function fms_markers_resize() { - var size = fms_marker_size_for_zoom(fixmystreet.map.getZoom() + fixmystreet.zoomOffset); - for (var i = 0; i < fixmystreet.markers.features.length; i++) { - fixmystreet.markers.features[i].attributes.size = size; - } - fixmystreet.markers.redraw(); -} - -// `markers.redraw()` in fms_markers_highlight will trigger an -// `overFeature` event if the mouse cursor is still over the same -// marker on the map, which would then run fms_markers_highlight -// again, causing an infinite flicker while the cursor remains over -// the same marker. We really only want to redraw the markers when -// the cursor moves from one marker to another (ie: when there is an -// overFeature followed by an outFeature followed by an overFeature). -// Therefore, we keep track of the previous event in -// fixmystreet.latest_map_hover_event and only call fms_markers_highlight -// if we know the previous event was different to the current one. -// (See the `overFeature` and `outFeature` callbacks inside of -// fixmystreet.select_feature). - -function fms_markers_highlight(problem_id) { - for (var i = 0; i < fixmystreet.markers.features.length; i++) { - if (typeof problem_id == 'undefined') { - // There is no highlighted marker, so unfade this marker - fixmystreet.markers.features[i].attributes.faded = 0; - } else if (problem_id == fixmystreet.markers.features[i].attributes.id) { - // This is the highlighted marker, unfade it - fixmystreet.markers.features[i].attributes.faded = 0; + get_marker_by_id: function(problem_id) { + return fixmystreet.markers.getFeaturesByAttribute('id', problem_id)[0]; + }, + + marker_size_for_zoom: function(zoom) { + if (zoom >= 15) { + return window.selected_problem_id ? 'small' : 'normal'; + } else if (zoom >= 13) { + return window.selected_problem_id ? 'mini' : 'small'; } else { - // This is not the hightlighted marker, fade it - fixmystreet.markers.features[i].attributes.faded = 1; + return 'mini'; } - } - fixmystreet.markers.redraw(); -} - -function fms_sidebar_highlight(problem_id) { - if (typeof problem_id !== 'undefined') { - var $a = $('.item-list--reports a[href$="' + problem_id + '"]'); - $a.parent().addClass('hovered'); - } else { - $('.item-list--reports .hovered').removeClass('hovered'); - } -} - -function fms_marker_click(problem_id) { - var $a = $('.item-list--reports a[href$="' + problem_id + '"]'); - $a[0] && $a[0].click(); -} - -function fms_categories_or_status_changed() { - // If the category or status has changed we need to re-fetch map markers - fixmystreet.markers.refresh({force: true}); -} - -function fixmystreet_onload() { - if ( fixmystreet.area.length ) { - for (var i=0; i<fixmystreet.area.length; i++) { - var area = new OpenLayers.Layer.Vector("KML", { - strategies: [ new OpenLayers.Strategy.Fixed() ], - protocol: new OpenLayers.Protocol.HTTP({ - url: "/mapit/area/" + fixmystreet.area[i] + ".kml?simplify_tolerance=0.0001", - format: new OpenLayers.Format.KML() - }) - }); - fixmystreet.map.addLayer(area); - if ( fixmystreet.area.length == 1 ) { - area.events.register('loadend', null, function(a,b,c) { - if ( fixmystreet.area_format ) { - area.styleMap.styles['default'].defaultStyle = fixmystreet.area_format; - } - fixmystreet_zoomToBounds( area.getDataExtent() ); - }); - } - } - } + }, - var pin_layer_style_map = new OpenLayers.StyleMap({ - 'default': new OpenLayers.Style({ - graphicTitle: "${title}", - graphicOpacity: 1, - graphicZIndex: 11, - backgroundGraphicZIndex: 10 - }) - }); - pin_layer_style_map.addUniqueValueRules('default', 'size', { - 'normal': { - externalGraphic: fixmystreet.pin_prefix + "pin-${colour}.png", - graphicWidth: 48, - graphicHeight: 64, - graphicXOffset: -24, - graphicYOffset: -64, - backgroundGraphic: fixmystreet.pin_prefix + "pin-shadow.png", - backgroundWidth: 60, - backgroundHeight: 30, - backgroundXOffset: -7, - backgroundYOffset: -30, - popupYOffset: -40 - }, - 'big': { - externalGraphic: fixmystreet.pin_prefix + "pin-${colour}-big.png", - graphicWidth: 78, - graphicHeight: 105, - graphicXOffset: -39, - graphicYOffset: -105, - backgroundGraphic: fixmystreet.pin_prefix + "pin-shadow-big.png", - backgroundWidth: 88, - backgroundHeight: 40, - backgroundXOffset: -10, - backgroundYOffset: -35 - }, - 'small': { - externalGraphic: fixmystreet.pin_prefix + "pin-${colour}-small.png", - graphicWidth: 24, - graphicHeight: 32, - graphicXOffset: -12, - graphicYOffset: -32, - backgroundGraphic: fixmystreet.pin_prefix + "pin-shadow-small.png", - backgroundWidth: 30, - backgroundHeight: 15, - backgroundXOffset: -4, - backgroundYOffset: -15, - popupYOffset: -20 - }, - 'mini': { - externalGraphic: fixmystreet.pin_prefix + "pin-${colour}-mini.png", - graphicWidth: 16, - graphicHeight: 20, - graphicXOffset: -8, - graphicYOffset: -20, - popupYOffset: -10 + selected_marker_size_for_zoom: function(zoom) { + if (zoom >= 15) { + return 'big'; + } else if (zoom >= 13) { + return 'normal'; + } else { + return 'small'; } - }); - pin_layer_style_map.addUniqueValueRules('default', 'faded', { - 0: { - graphicOpacity: 1 + } + }; + + var drag = { + activate: function() { + this._drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, { + onComplete: function(feature, e) { + fixmystreet.update_pin( feature.geometry ); + } + } ); + fixmystreet.map.addControl( this._drag ); + this._drag.activate(); }, - 1: { - graphicOpacity: 0.15 + deactivate: function() { + this._drag && this._drag.deactivate(); } - }); - var pin_layer_options = { - rendererOptions: { - yOrdering: true - }, - styleMap: pin_layer_style_map }; - if (fixmystreet.page == 'around') { - fixmystreet.bbox_strategy = fixmystreet.bbox_strategy || new OpenLayers.Strategy.FixMyStreet(); - pin_layer_options.strategies = [ fixmystreet.bbox_strategy ]; - pin_layer_options.protocol = new OpenLayers.Protocol.FixMyStreet({ - url: '/ajax', - params: fixmystreet.all_pins ? { all_pins: 1 } : { }, - format: new OpenLayers.Format.FixMyStreet() - }); - } - fixmystreet.markers = new OpenLayers.Layer.Vector("Pins", pin_layer_options); - fixmystreet.markers.events.register( 'loadend', fixmystreet.markers, function(evt) { - if (fixmystreet.map.popups.length) { - fixmystreet.map.removePopup(fixmystreet.map.popups[0]); + + function zoomToBounds(bounds) { + if (!bounds) { return; } + var center = bounds.getCenterLonLat(); + var z = fixmystreet.map.getZoomForExtent(bounds); + if ( z < 13 && $('html').hasClass('mobile') ) { + z = 13; } - }); + fixmystreet.map.setCenter(center, z); + } - var markers = fms_markers_list( fixmystreet.pins, true ); - fixmystreet.markers.addFeatures( markers ); - - if (fixmystreet.page == 'around' || fixmystreet.page == 'reports' || fixmystreet.page == 'my') { - fixmystreet.select_feature = new OpenLayers.Control.SelectFeature( - fixmystreet.markers, - { - hover: true, - // Override clickFeature so that we can use it even though - // hover is true. http://gis.stackexchange.com/a/155675 - clickFeature: function (feature) { - fms_marker_click(feature.attributes.id); - }, - overFeature: function (feature) { - if (fixmystreet.latest_map_hover_event != 'overFeature') { - document.getElementById('map').style.cursor = 'pointer'; - fms_markers_highlight(feature.attributes.id); - fms_sidebar_highlight(feature.attributes.id); - fixmystreet.latest_map_hover_event = 'overFeature'; - } - }, - outFeature: function (feature) { - if (fixmystreet.latest_map_hover_event != 'outFeature') { - document.getElementById('map').style.cursor = ''; - fms_markers_highlight(); - fms_sidebar_highlight(); - fixmystreet.latest_map_hover_event = 'outFeature'; - } - } + // `markers.redraw()` in markers_highlight will trigger an + // `overFeature` event if the mouse cursor is still over the same + // marker on the map, which would then run markers_highlight + // again, causing an infinite flicker while the cursor remains over + // the same marker. We really only want to redraw the markers when + // the cursor moves from one marker to another (ie: when there is an + // overFeature followed by an outFeature followed by an overFeature). + // Therefore, we keep track of the previous event in + // fixmystreet.latest_map_hover_event and only call markers_highlight + // if we know the previous event was different to the current one. + // (See the `overFeature` and `outFeature` callbacks inside of + // fixmystreet.select_feature). + + function markers_highlight(problem_id) { + for (var i = 0; i < fixmystreet.markers.features.length; i++) { + if (typeof problem_id == 'undefined') { + // There is no highlighted marker, so unfade this marker + fixmystreet.markers.features[i].attributes.faded = 0; + } else if (problem_id == fixmystreet.markers.features[i].attributes.id) { + // This is the highlighted marker, unfade it + fixmystreet.markers.features[i].attributes.faded = 0; + } else { + // This is not the hightlighted marker, fade it + fixmystreet.markers.features[i].attributes.faded = 1; } - ); - fixmystreet.map.addControl( fixmystreet.select_feature ); - fixmystreet.select_feature.activate(); - fixmystreet.map.events.register( 'zoomend', null, fms_markers_resize ); - - // If the category filter dropdown exists on the page set up the - // event handlers to populate it and react to it changing - if ($("select#filter_categories").length) { - $("body").on("change", "#filter_categories", fms_categories_or_status_changed); } - // Do the same for the status dropdown - if ($("select#statuses").length) { - $("body").on("change", "#statuses", fms_categories_or_status_changed); + fixmystreet.markers.redraw(); + } + + function sidebar_highlight(problem_id) { + if (typeof problem_id !== 'undefined') { + var $a = $('.item-list--reports a[href$="/' + problem_id + '"]'); + $a.parent().addClass('hovered'); + } else { + $('.item-list--reports .hovered').removeClass('hovered'); } - } else if (fixmystreet.page == 'new') { - fixmystreet_activate_drag(); } - fixmystreet.map.addLayer(fixmystreet.markers); - if ( fixmystreet.zoomToBounds ) { - fixmystreet_zoomToBounds( fixmystreet.markers.getDataExtent() ); + function marker_click(problem_id) { + var $a = $('.item-list--reports a[href$="/' + problem_id + '"]'); + $a[0] && $a[0].click(); } - $('#hide_pins_link').click(function(e) { - e.preventDefault(); - var showhide = [ - 'Show pins', 'Hide pins', - 'Dangos pinnau', 'Cuddio pinnau', - "Vis nåler", "Skjul nåler", - "Zeige Stecknadeln", "Stecknadeln ausblenden" - ]; - for (var i=0; i<showhide.length; i+=2) { - if (this.innerHTML == showhide[i]) { - fixmystreet.markers.setVisibility(true); - fixmystreet.select_feature.activate(); - this.innerHTML = showhide[i+1]; - } else if (this.innerHTML == showhide[i+1]) { - fixmystreet.markers.setVisibility(false); - fixmystreet.select_feature.deactivate(); - this.innerHTML = showhide[i]; + function categories_or_status_changed() { + // If the category or status has changed we need to re-fetch map markers + fixmystreet.markers.refresh({force: true}); + } + + function onload() { + if ( fixmystreet.area.length ) { + for (var i=0; i<fixmystreet.area.length; i++) { + var area = new OpenLayers.Layer.Vector("KML", { + strategies: [ new OpenLayers.Strategy.Fixed() ], + protocol: new OpenLayers.Protocol.HTTP({ + url: "/mapit/area/" + fixmystreet.area[i] + ".kml?simplify_tolerance=0.0001", + format: new OpenLayers.Format.KML() + }) + }); + fixmystreet.map.addLayer(area); + if ( fixmystreet.area.length == 1 ) { + area.events.register('loadend', null, function(a,b,c) { + if ( fixmystreet.area_format ) { + area.styleMap.styles['default'].defaultStyle = fixmystreet.area_format; + } + zoomToBounds( area.getDataExtent() ); + }); + } } } - }); - $('#all_pins_link').click(function(e) { - e.preventDefault(); - fixmystreet.markers.setVisibility(true); - var texts = [ - 'en', 'Show old', 'Hide old', - 'nb', 'Vis gamle', 'Skjul gamle', - 'cy', 'Cynnwys hen adroddiadau', 'Cuddio hen adroddiadau' - ]; - for (var i=0; i<texts.length; i+=3) { - if (this.innerHTML == texts[i+1]) { - this.innerHTML = texts[i+2]; - fixmystreet.markers.protocol.options.params = { all_pins: 1 }; - fixmystreet.markers.refresh( { force: true } ); - lang = texts[i]; - } else if (this.innerHTML == texts[i+2]) { - this.innerHTML = texts[i+1]; - fixmystreet.markers.protocol.options.params = { }; - fixmystreet.markers.refresh( { force: true } ); - lang = texts[i]; + var pin_layer_style_map = new OpenLayers.StyleMap({ + 'default': new OpenLayers.Style({ + graphicTitle: "${title}", + graphicOpacity: 1, + graphicZIndex: 11, + backgroundGraphicZIndex: 10 + }) + }); + pin_layer_style_map.addUniqueValueRules('default', 'size', { + 'normal': { + externalGraphic: fixmystreet.pin_prefix + "pin-${colour}.png", + graphicWidth: 48, + graphicHeight: 64, + graphicXOffset: -24, + graphicYOffset: -64, + backgroundGraphic: fixmystreet.pin_prefix + "pin-shadow.png", + backgroundWidth: 60, + backgroundHeight: 30, + backgroundXOffset: -7, + backgroundYOffset: -30, + popupYOffset: -40 + }, + 'big': { + externalGraphic: fixmystreet.pin_prefix + "pin-${colour}-big.png", + graphicWidth: 78, + graphicHeight: 105, + graphicXOffset: -39, + graphicYOffset: -105, + backgroundGraphic: fixmystreet.pin_prefix + "pin-shadow-big.png", + backgroundWidth: 88, + backgroundHeight: 40, + backgroundXOffset: -10, + backgroundYOffset: -35 + }, + 'small': { + externalGraphic: fixmystreet.pin_prefix + "pin-${colour}-small.png", + graphicWidth: 24, + graphicHeight: 32, + graphicXOffset: -12, + graphicYOffset: -32, + backgroundGraphic: fixmystreet.pin_prefix + "pin-shadow-small.png", + backgroundWidth: 30, + backgroundHeight: 15, + backgroundXOffset: -4, + backgroundYOffset: -15, + popupYOffset: -20 + }, + 'mini': { + externalGraphic: fixmystreet.pin_prefix + "pin-${colour}-mini.png", + graphicWidth: 16, + graphicHeight: 20, + graphicXOffset: -8, + graphicYOffset: -20, + popupYOffset: -10 } + }); + pin_layer_style_map.addUniqueValueRules('default', 'faded', { + 0: { + graphicOpacity: 1 + }, + 1: { + graphicOpacity: 0.4 + } + }); + var pin_layer_options = { + rendererOptions: { + yOrdering: true + }, + styleMap: pin_layer_style_map + }; + if (fixmystreet.page == 'around') { + fixmystreet.bbox_strategy = fixmystreet.bbox_strategy || new OpenLayers.Strategy.FixMyStreet(); + pin_layer_options.strategies = [ fixmystreet.bbox_strategy ]; + pin_layer_options.protocol = new OpenLayers.Protocol.FixMyStreet({ + url: '/ajax', + params: fixmystreet.all_pins ? { all_pins: 1 } : { }, + format: new OpenLayers.Format.FixMyStreet() + }); } - if (lang == 'cy') { - document.getElementById('hide_pins_link').innerHTML = 'Cuddio pinnau'; - } else if (lang == 'nb') { - document.getElementById('hide_pins_link').innerHTML = 'Skjul nåler'; - } else { - document.getElementById('hide_pins_link').innerHTML = 'Hide pins'; - } - }); - -} - -$(function(){ + fixmystreet.markers = new OpenLayers.Layer.Vector("Pins", pin_layer_options); + fixmystreet.markers.events.register( 'loadend', fixmystreet.markers, function(evt) { + if (fixmystreet.map.popups.length) { + fixmystreet.map.removePopup(fixmystreet.map.popups[0]); + } + }); - // Set specific map config - some other JS included in the - // template should define this - set_map_config(); + var markers = fixmystreet.maps.markers_list( fixmystreet.pins, true ); + fixmystreet.markers.addFeatures( markers ); + + if (fixmystreet.page == 'around' || fixmystreet.page == 'reports' || fixmystreet.page == 'my') { + fixmystreet.select_feature = new OpenLayers.Control.SelectFeature( + fixmystreet.markers, + { + hover: true, + // Override clickFeature so that we can use it even though + // hover is true. http://gis.stackexchange.com/a/155675 + clickFeature: function (feature) { + marker_click(feature.attributes.id); + }, + overFeature: function (feature) { + if (fixmystreet.latest_map_hover_event != 'overFeature') { + document.getElementById('map').style.cursor = 'pointer'; + markers_highlight(feature.attributes.id); + sidebar_highlight(feature.attributes.id); + fixmystreet.latest_map_hover_event = 'overFeature'; + } + }, + outFeature: function (feature) { + if (fixmystreet.latest_map_hover_event != 'outFeature') { + document.getElementById('map').style.cursor = ''; + markers_highlight(); + sidebar_highlight(); + fixmystreet.latest_map_hover_event = 'outFeature'; + } + } + } + ); + fixmystreet.map.addControl( fixmystreet.select_feature ); + fixmystreet.select_feature.activate(); + fixmystreet.map.events.register( 'zoomend', null, fixmystreet.maps.markers_resize ); + + // If the category filter dropdown exists on the page set up the + // event handlers to populate it and react to it changing + if ($("select#filter_categories").length) { + $("body").on("change", "#filter_categories", categories_or_status_changed); + } + // Do the same for the status dropdown + if ($("select#statuses").length) { + $("body").on("change", "#statuses", categories_or_status_changed); + } + } else if (fixmystreet.page == 'new') { + drag.activate(); + } + fixmystreet.map.addLayer(fixmystreet.markers); + + if ( fixmystreet.zoomToBounds ) { + zoomToBounds( fixmystreet.markers.getDataExtent() ); + } + + $('#hide_pins_link').click(function(e) { + e.preventDefault(); + var showhide = [ + 'Show pins', 'Hide pins', + 'Dangos pinnau', 'Cuddio pinnau', + "Vis nåler", "Skjul nåler", + "Zeige Stecknadeln", "Stecknadeln ausblenden" + ]; + for (var i=0; i<showhide.length; i+=2) { + if (this.innerHTML == showhide[i]) { + fixmystreet.markers.setVisibility(true); + fixmystreet.select_feature.activate(); + this.innerHTML = showhide[i+1]; + } else if (this.innerHTML == showhide[i+1]) { + fixmystreet.markers.setVisibility(false); + fixmystreet.select_feature.deactivate(); + this.innerHTML = showhide[i]; + } + } + }); - // Create the basics of the map - fixmystreet.map = new OpenLayers.Map( - "map", OpenLayers.Util.extend({ - controls: fixmystreet.controls, - displayProjection: new OpenLayers.Projection("EPSG:4326") - }, fixmystreet.map_options) - ); + $('#all_pins_link').click(function(e) { + e.preventDefault(); + fixmystreet.markers.setVisibility(true); + var texts = [ + 'en', 'Show old', 'Hide old', + 'nb', 'Vis gamle', 'Skjul gamle', + 'cy', 'Cynnwys hen adroddiadau', 'Cuddio hen adroddiadau' + ]; + for (var i=0; i<texts.length; i+=3) { + if (this.innerHTML == texts[i+1]) { + this.innerHTML = texts[i+2]; + fixmystreet.markers.protocol.options.params = { all_pins: 1 }; + fixmystreet.markers.refresh( { force: true } ); + lang = texts[i]; + } else if (this.innerHTML == texts[i+2]) { + this.innerHTML = texts[i+1]; + fixmystreet.markers.protocol.options.params = { }; + fixmystreet.markers.refresh( { force: true } ); + lang = texts[i]; + } + } + if (lang == 'cy') { + document.getElementById('hide_pins_link').innerHTML = 'Cuddio pinnau'; + } else if (lang == 'nb') { + document.getElementById('hide_pins_link').innerHTML = 'Skjul nåler'; + } else { + document.getElementById('hide_pins_link').innerHTML = 'Hide pins'; + } + }); - // Need to do this here, after the map is created (might not have been when - // resize() called) - if ($('html').hasClass('mobile') && fixmystreet.page == 'around') { - $('#fms_pan_zoom').css({ top: '2.75em' }); } - // Set it up our way + $(function(){ - var layer; - if (!fixmystreet.layer_options) { - fixmystreet.layer_options = [ {} ]; - } - if (!fixmystreet.layer_name) { - fixmystreet.layer_name = ""; - } - for (var i=0; i<fixmystreet.layer_options.length; i++) { - fixmystreet.layer_options[i] = OpenLayers.Util.extend({ - // This option is used by XYZ-based layers - zoomOffset: fixmystreet.zoomOffset, - // This option is used by FixedZoomLevels-based layers - minZoomLevel: fixmystreet.zoomOffset, - // This option is thankfully used by them both - numZoomLevels: fixmystreet.numZoomLevels - }, fixmystreet.layer_options[i]); - if (fixmystreet.layer_options[i].matrixIds) { - layer = new fixmystreet.map_type(fixmystreet.layer_options[i]); - } else { - layer = new fixmystreet.map_type(fixmystreet.layer_name, fixmystreet.layer_options[i]); - } - fixmystreet.map.addLayer(layer); - } + // Set specific map config - some other JS included in the + // template should define this + fixmystreet.maps.config(); - if (!fixmystreet.map.getCenter()) { - var centre = new OpenLayers.LonLat( fixmystreet.longitude, fixmystreet.latitude ); - centre.transform( - new OpenLayers.Projection("EPSG:4326"), - fixmystreet.map.getProjectionObject() + // Create the basics of the map + fixmystreet.map = new OpenLayers.Map( + "map", OpenLayers.Util.extend({ + controls: fixmystreet.controls, + displayProjection: new OpenLayers.Projection("EPSG:4326") + }, fixmystreet.map_options) ); - fixmystreet.map.setCenter(centre, fixmystreet.zoom || 3); - } - if (document.getElementById('mapForm')) { - var click = new OpenLayers.Control.Click(); - fixmystreet.map.addControl(click); - click.activate(); - } - - $(window).hashchange(function(){ - if (location.hash == '#report' && $('.rap-notes').is(':visible')) { - $('.rap-notes-close').click(); - return; + // Set it up our way + + var layer; + if (!fixmystreet.layer_options) { + fixmystreet.layer_options = [ {} ]; + } + if (!fixmystreet.layer_name) { + fixmystreet.layer_name = ""; + } + for (var i=0; i<fixmystreet.layer_options.length; i++) { + fixmystreet.layer_options[i] = OpenLayers.Util.extend({ + // This option is used by XYZ-based layers + zoomOffset: fixmystreet.zoomOffset, + // This option is used by FixedZoomLevels-based layers + minZoomLevel: fixmystreet.zoomOffset, + // This option is thankfully used by them both + numZoomLevels: fixmystreet.numZoomLevels + }, fixmystreet.layer_options[i]); + if (fixmystreet.layer_options[i].matrixIds) { + layer = new fixmystreet.map_type(fixmystreet.layer_options[i]); + } else { + layer = new fixmystreet.map_type(fixmystreet.layer_name, fixmystreet.layer_options[i]); + } + fixmystreet.map.addLayer(layer); } - if (location.hash && location.hash != '#') { - return; + if (!fixmystreet.map.getCenter()) { + var centre = new OpenLayers.LonLat( fixmystreet.longitude, fixmystreet.latitude ); + centre.transform( + new OpenLayers.Projection("EPSG:4326"), + fixmystreet.map.getProjectionObject() + ); + fixmystreet.map.setCenter(centre, fixmystreet.zoom || 3); } - // Okay, back to around view. - fixmystreet.bbox_strategy.activate(); - fixmystreet.markers.refresh( { force: true } ); - if ( fixmystreet.state_pins_were_hidden ) { - // If we had pins hidden when we clicked map (which had to show the pin layer as I'm doing it in one layer), hide them again. - $('#hide_pins_link').click(); + if (document.getElementById('mapForm')) { + var click = new OpenLayers.Control.Click(); + fixmystreet.map.addControl(click); + click.activate(); } - fixmystreet.drag.deactivate(); - $('#side-form').hide(); - $('#side').show(); - $('body').removeClass('with-notes'); - fixmystreet.map.updateSize(); // required after changing the size of the map element - $('#sub_map_links').show(); - //only on mobile - $('#mob_sub_map_links').remove(); - $('.mobile-map-banner').html('<a href="/">' + translation_strings.home + '</a> ' + translation_strings.place_pin_on_map); - fixmystreet.page = 'around'; - }); - // Hide the pin filter submit button. Not needed because we'll use JS - // to refresh the map when the filter inputs are changed. - $(".report-list-filters [type=submit]").hide(); + // Hide the pin filter submit button. Not needed because we'll use JS + // to refresh the map when the filter inputs are changed. + $(".report-list-filters [type=submit]").hide(); - if (fixmystreet.page == "my" || fixmystreet.page == "reports") { - $(".report-list-filters select").change(function() { - $(this).closest("form").submit(); - }); - } + if (fixmystreet.page == "my" || fixmystreet.page == "reports") { + $(".report-list-filters select").change(function() { + $(this).closest("form").submit(); + }); + } - // Vector layers must be added onload as IE sucks - if ($.browser.msie) { - $(window).load(fixmystreet_onload); - } else { - fixmystreet_onload(); - } + // Vector layers must be added onload as IE sucks + if ($.browser.msie) { + $(window).load(onload); + } else { + onload(); + } + + (function() { + var timeout; + $('.item-list--reports').on('mouseenter', '.item-list--reports__item', function(){ + var href = $('a', this).attr('href'); + var id = parseInt(href.replace(/^.*[/]([0-9]+)$/, '$1')); + clearTimeout(timeout); + markers_highlight(id); + }).on('mouseleave', '.item-list--reports__item', function(){ + timeout = setTimeout(markers_highlight, 50); + }); + })(); + }); + +// End maps closure +})(); - (function() { - var timeout; - $('.item-list--reports').on('mouseenter', '.item-list--reports__item', function(){ - var href = $('a', this).attr('href'); - var id = parseInt(href.replace(/^.*[/]([0-9]+)$/, '$1')); - clearTimeout(timeout); - fms_markers_highlight(id); - }).on('mouseleave', '.item-list--reports__item', function(){ - timeout = setTimeout(fms_markers_highlight, 50); - }); - })(); -}); /* Overridding the buttonDown function of PanZoom so that it does zoomTo(0) rather than zoomToMaxExtent() @@ -663,7 +673,7 @@ OpenLayers.Format.FixMyStreet = OpenLayers.Class(OpenLayers.Format.JSON, { if (typeof(obj.current) != 'undefined' && (current = document.getElementById('current'))) { current.innerHTML = obj.current; } - return fms_markers_list( obj.pins, false ); + return fixmystreet.maps.markers_list( obj.pins, false ); }, CLASS_NAME: "OpenLayers.Format.FixMyStreet" }); @@ -691,96 +701,18 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { }, trigger: function(e) { - var cobrand = $('meta[name="cobrand"]').attr('content'); - var lonlat = fixmystreet.map.getLonLatFromViewPortPx(e.xy); - if (fixmystreet.page == 'new') { - /* Already have a pin */ - fixmystreet.markers.features[0].move(lonlat); - } else { - var markers = fms_markers_list( [ [ lonlat.lat, lonlat.lon, 'green' ] ], false ); - fixmystreet.bbox_strategy.deactivate(); - fixmystreet.markers.removeAllFeatures(); - fixmystreet.markers.addFeatures( markers ); - fixmystreet_activate_drag(); + // If we are looking at an individual report, and the report was + // ajaxed into the DOM from the all reports page, then clicking + // the map background should take us back to the all reports list. + if ($('.js-back-to-report-list').length) { + $('.js-back-to-report-list').trigger('click'); + return true; } - // check to see if markers are visible. We click the - // link so that it updates the text in case they go - // back - if ( ! fixmystreet.markers.getVisibility() ) { - fixmystreet.state_pins_were_hidden = true; - $('#hide_pins_link').click(); - } - - // Store pin location in form fields, and check coverage of point - fixmystreet_update_pin(lonlat); - - // It's possible to invoke the OpenLayers.Control `trigger` callback - // multiple times in a row (eg: by clicking on the map multiple times, - // to reposition your report). - // But there is some stuff we only want to happen the first time you - // switch from the "around" view to the "new" report view. - // So, here we check whether we've already transitioned into the "new" - // report view, and if so, we return from the callback early, - // skipping the remainder of the setup stuff. - if (fixmystreet.page == 'new') { - fixmystreet.map.panDuration = 100; - fixmystreet.map.panTo(lonlat); - fixmystreet.map.panDuration = 50; - return; - } - - // If there are notes to be displayed, add the .with-notes class - // to make the sidebar wider. - if ($('#report-a-problem-sidebar').length) { - $('body').addClass('with-notes'); - } - - /* For some reason on IOS5 if you use the jQuery show method it - * doesn't display the JS validation error messages unless you do this - * or you cause a screen redraw by changing the phone orientation. - * NB: This has to happen after the call to show() in fixmystreet_update_pin */ - if ( navigator.userAgent.match(/like Mac OS X/i)) { - document.getElementById('side-form').style.display = 'block'; - } - $('#side').hide(); - - fixmystreet.map.updateSize(); // required after changing the size of the map element - - fixmystreet.map.panDuration = 100; - fixmystreet.map.panTo(lonlat); - fixmystreet.map.panDuration = 50; - - $('#sub_map_links').hide(); - if ($('html').hasClass('mobile')) { - var $map_box = $('#map_box'), - width = $map_box.width(), - height = $map_box.height(); - $map_box.append( '<p id="mob_sub_map_links">' + '<a href="#" id="try_again">' + translation_strings.try_again + '</a>' + '<a href="#ok" id="mob_ok">' + translation_strings.ok + '</a>' + '</p>' ).css({ position: 'relative', width: width, height: height, marginBottom: '1em' }); - // Making it relative here makes it much easier to do the scrolling later - - $('.mobile-map-banner').html('<a href="/">' + translation_strings.home + '</a> ' + translation_strings.right_place); - - // mobile user clicks 'ok' on map - $('#mob_ok').toggle(function(){ - //scroll the height of the map box instead of the offset - //of the #side-form or whatever as we will probably want - //to do this on other pages where #side-form might not be - $('html, body').animate({ scrollTop: height-60 }, 1000, function(){ - $('#mob_sub_map_links').addClass('map_complete'); - $('#mob_ok').text(translation_strings.map); - }); - }, function(){ - $('html, body').animate({ scrollTop: 0 }, 1000, function(){ - $('#mob_sub_map_links').removeClass('map_complete'); - $('#mob_ok').text(translation_strings.ok); - }); - }); - } + var lonlat = fixmystreet.map.getLonLatFromViewPortPx(e.xy); + fixmystreet.display.begin_report(lonlat); - fixmystreet.page = 'new'; - location.hash = 'report'; - if ( typeof ga !== 'undefined' && cobrand == 'fixmystreet' ) { + if ( typeof ga !== 'undefined' && window.cobrand == 'fixmystreet' ) { ga('send', 'pageview', { 'page': '/map_click' } ); } } diff --git a/web/js/map-OpenStreetMap.js b/web/js/map-OpenStreetMap.js index 5dcf3cab3..b2d6a4f8b 100644 --- a/web/js/map-OpenStreetMap.js +++ b/web/js/map-OpenStreetMap.js @@ -1,4 +1,4 @@ -function set_map_config(perm) { +fixmystreet.maps.config = function() { var permalink_id; if ($('#map_permalink').length) { permalink_id = 'map_permalink'; @@ -10,7 +10,7 @@ function set_map_config(perm) { new OpenLayers.Control.PermalinkFMS(permalink_id), new OpenLayers.Control.PanZoomFMS({id: 'fms_pan_zoom' }) ]; -} +}; // http://www.openstreetmap.org/openlayers/OpenStreetMap.js (added maxResolution) diff --git a/web/js/map-bing-ol.js b/web/js/map-bing-ol.js index 5e29daea1..3ad92b27e 100644 --- a/web/js/map-bing-ol.js +++ b/web/js/map-bing-ol.js @@ -1,4 +1,4 @@ -function _set_map_config() { +fixmystreet.maps.config = function() { var permalink_id; if ($('#map_permalink').length) { permalink_id = 'map_permalink'; @@ -15,12 +15,8 @@ function _set_map_config() { if ( fixmystreet.page == 'report' ) { fixmystreet.controls.push( new OpenLayers.Control.PermalinkFMS('key-tool-problems-nearby', '/around') ); } -} - -function set_map_config(perm) { - _set_map_config(); fixmystreet.map_type = OpenLayers.Layer.Bing; -} +}; OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { attributionTemplate: '${logo}${copyrights}', diff --git a/web/js/map-fms.js b/web/js/map-fms.js index c5bf70191..65c02a503 100644 --- a/web/js/map-fms.js +++ b/web/js/map-fms.js @@ -1,13 +1,14 @@ -var fms_tile_base = [ [ '', 'a-', 'b-', 'c-' ], '//{S}tilma.mysociety.org/sv' ]; +fixmystreet.maps.tile_base = [ [ '', 'a-', 'b-', 'c-' ], '//{S}tilma.mysociety.org/sv' ]; -function set_map_config(perm) { - _set_map_config(); - - if (fixmystreet.map_type) { - fms_tile_base = fixmystreet.map_type; - } - fixmystreet.map_type = OpenLayers.Layer.BingUK; -} +fixmystreet.maps.config = (function(original) { + return function(){ + if (fixmystreet.map_type) { + this.tile_base = fixmystreet.map_type; + } + original(); + fixmystreet.map_type = OpenLayers.Layer.BingUK; + }; +})(fixmystreet.maps.config); OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.Bing, { uk_bounds: [ @@ -54,8 +55,8 @@ OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.Bing, { var in_uk = this.in_uk(bounds.getCenterLonLat()); if (z >= 16 && in_uk) { urls = []; - for (var i=0; i< fms_tile_base[0].length; i++) { - urls.push( fms_tile_base[1].replace('{S}', fms_tile_base[0][i]) + "/${z}/${x}/${y}.png" ); + for (var i=0; i< fixmystreet.maps.tile_base[0].length; i++) { + urls.push( fixmystreet.maps.tile_base[1].replace('{S}', fixmystreet.maps.tile_base[0][i]) + "/${z}/${x}/${y}.png" ); } } else { var type = ''; diff --git a/web/js/map-google-ol.js b/web/js/map-google-ol.js index 5a1aa3c57..96ec6fe9b 100644 --- a/web/js/map-google-ol.js +++ b/web/js/map-google-ol.js @@ -15,7 +15,7 @@ $(function(){ } }); -function set_map_config(perm) { +fixmystreet.maps.config = function() { var permalink_id; if ($('#map_permalink').length) { permalink_id = 'map_permalink'; @@ -37,5 +37,4 @@ function set_map_config(perm) { {}, { type: google.maps.MapTypeId.HYBRID } ]; -} - +}; diff --git a/web/js/map-google.js b/web/js/map-google.js index 5009bebac..4c3f6188e 100644 --- a/web/js/map-google.js +++ b/web/js/map-google.js @@ -5,313 +5,269 @@ TODO Pin size on report page */ -function PaddingControl(div) { - div.style.padding = '40px'; -} +var fixmystreet = fixmystreet || {}; +fixmystreet.maps = {}; -function fixmystreet_update_pin(lonlat) { - document.getElementById('fixmystreet.latitude').value = lonlat.lat(); - document.getElementById('fixmystreet.longitude').value = lonlat.lng(); +(function() { - $.getJSON('/report/new/ajax', { - latitude: $('#fixmystreet\\.latitude').val(), - longitude: $('#fixmystreet\\.longitude').val() - }, function(data) { - if (data.error) { - if (!$('#side-form-error').length) { - $('<div id="side-form-error"/>').insertAfter($('#side-form')); - } - $('#side-form-error').html('<h1>' + translation_strings.reporting_a_problem + '</h1><p>' + data.error + '</p>').show(); - $('#side-form').hide(); - return; - } - $('#side-form, #site-logo').show(); - $('#councils_text').html(data.councils_text); - $('#form_category_row').html(data.category); - if ( data.extra_name_info && !$('#form_fms_extra_title').length ) { - // there might be a first name field on some cobrands - var lb = $('#form_first_name').prev(); - if ( lb.length === 0 ) { lb = $('#form_name').prev(); } - lb.before(data.extra_name_info); - } - }); - - if (!$('#side-form-error').is(':visible')) { - $('#side-form, #site-logo').show(); - } -} - -var infowindow = new google.maps.InfoWindow(); -function make_infowindow(marker) { - return function() { - infowindow.setContent(marker.title + "<br><a href=/report/" + marker.id + ">" + translation_strings.more_details + "</a>"); - infowindow.open(fixmystreet.map, marker); + fixmystreet.maps.update_pin = function(lonlat) { + var lat = lonlat.lat(); + var lon = lonlat.lng(); + document.getElementById('fixmystreet.latitude').value = lat; + document.getElementById('fixmystreet.longitude').value = lon; + return { + 'url': { 'lon': lon, 'lat': lat }, + 'state': { 'lon': lon, 'lat': lat } + }; }; -} -function fms_markers_list(pins, transform) { - var markers = []; - if (fixmystreet.markers) { - for (var m=0; m<fixmystreet.markers.length; m++) { - fixmystreet.markers[m].setMap(null); - } - } - for (var i=0; i<pins.length; i++) { - var pin = pins[i]; - var pin_args = { - position: new google.maps.LatLng( pin[0], pin[1] ), - //size: pin[5] || 'normal', - id: pin[3], - title: pin[4] || '', - map: fixmystreet.map - }; - if (pin[2] == 'green') { - pin_args.icon = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|87dd00"; - } - if (pin[2] == 'yellow') { - pin_args.icon = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|ffd600"; + fixmystreet.maps.begin_report = function(lonlat) { + if (typeof lonlat.lat !== 'function') { + lonlat = new google.maps.LatLng(lonlat.lat, lonlat.lon); } - var marker = new google.maps.Marker(pin_args); - if (fixmystreet.page == 'around' || fixmystreet.page == 'reports' || fixmystreet.page == 'my') { - var l = new google.maps.event.addListener(marker, 'click', make_infowindow(marker)); + + if (fixmystreet.page == 'new') { + /* Already have a pin */ + fixmystreet.report_marker.setPosition(lonlat); + } else { + var marker = new google.maps.Marker({ + position: lonlat, + draggable: true, + animation: google.maps.Animation.DROP, + map: fixmystreet.map + }); + var l = google.maps.event.addListener(marker, 'dragend', function(){ + fixmystreet.update_pin( marker.getPosition() ); + }); + fixmystreet.report_marker = marker; + google.maps.event.removeListener(fixmystreet.event_update_map); + for (m=0; m<fixmystreet.markers.length; m++) { + fixmystreet.markers[m].setMap(null); + } } - markers.push( marker ); - } - return markers; -} + return lonlat; + }; -function fms_map_clicked(e) { - var lonlat = e.latLng; - if (fixmystreet.page == 'new') { - /* Already have a pin */ - fixmystreet.report_marker.setPosition(lonlat); - } else { - var marker = new google.maps.Marker({ - position: lonlat, - draggable: true, - animation: google.maps.Animation.DROP, - map: fixmystreet.map - }); - var l = google.maps.event.addListener(marker, 'dragend', function(){ - fixmystreet_update_pin( marker.getPosition() ); - }); - fixmystreet.report_marker = marker; - google.maps.event.removeListener(fixmystreet.event_update_map); - for (m=0; m<fixmystreet.markers.length; m++) { - fixmystreet.markers[m].setMap(null); + fixmystreet.maps.display_around = function() { + if (fixmystreet.report_marker) { + fixmystreet.report_marker.setMap(null); } - } + fixmystreet.event_update_map = google.maps.event.addListener(fixmystreet.map, 'idle', update_pins); + google.maps.event.trigger(fixmystreet.map, 'idle'); + }; - // check to see if markers are visible. We click the - // link so that it updates the text in case they go - // back - if ( ! 1 ) { // XXX fixmystreet.markers.getVisibility() ) - fixmystreet.state_pins_were_hidden = true; - $('#hide_pins_link').click(); + function PaddingControl(div) { + div.style.padding = '40px'; } - // Store pin location in form fields, and check coverage of point - fixmystreet_update_pin(lonlat); - - // Already did this first time map was clicked, so no need to do it again. - if (fixmystreet.page == 'new') { - return; + var infowindow = new google.maps.InfoWindow(); + function make_infowindow(marker) { + return function() { + infowindow.setContent(marker.title + "<br><a href=/report/" + marker.id + ">" + translation_strings.more_details + "</a>"); + infowindow.open(fixmystreet.map, marker); + }; } - $('#side').hide(); - - // If we clicked the map somewhere inconvenient - // TODO - - $('#sub_map_links').hide(); - fixmystreet.page = 'new'; - location.hash = 'report'; -} - -/* Pan data handler */ -function fms_read_pin_json(obj) { - var current, current_near; - if (typeof(obj.current) != 'undefined' && (current = document.getElementById('current'))) { - current.innerHTML = obj.current; - } - if (typeof(obj.current_near) != 'undefined' && (current_near = document.getElementById('current_near'))) { - current_near.innerHTML = obj.current_near; + function markers_list(pins, transform) { + var markers = []; + if (fixmystreet.markers) { + for (var m=0; m<fixmystreet.markers.length; m++) { + fixmystreet.markers[m].setMap(null); + } + } + for (var i=0; i<pins.length; i++) { + var pin = pins[i]; + var pin_args = { + position: new google.maps.LatLng( pin[0], pin[1] ), + //size: pin[5] || 'normal', + id: pin[3], + title: pin[4] || '', + map: fixmystreet.map + }; + if (pin[2] == 'green') { + pin_args.icon = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|87dd00"; + } + if (pin[2] == 'yellow') { + pin_args.icon = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|ffd600"; + } + var marker = new google.maps.Marker(pin_args); + if (fixmystreet.page == 'around' || fixmystreet.page == 'reports' || fixmystreet.page == 'my') { + var l = new google.maps.event.addListener(marker, 'click', make_infowindow(marker)); + } + markers.push( marker ); + } + return markers; } - fixmystreet.markers = fms_markers_list( obj.pins, false ); -} -function fms_update_pins() { - var b = fixmystreet.map.getBounds(), - b_sw = b.getSouthWest(), - b_ne = b.getNorthEast(), - bbox = b_sw.lng() + ',' + b_sw.lat() + ',' + b_ne.lng() + ',' + b_ne.lat(), - params = { - bbox: bbox - }; - if (fixmystreet.all_pins) { - params.all_pins = 1; + function map_clicked(e) { + if ($('.js-back-to-report-list').length) { + $('.js-back-to-report-list').trigger('click'); + return true; + } + + var lonlat = e.latLng; + fixmystreet.display.begin_report(lonlat); } - $.getJSON('/ajax', params, fms_read_pin_json); -} -function fms_map_initialize() { - var centre = new google.maps.LatLng( fixmystreet.latitude, fixmystreet.longitude ); - var map_args = { - mapTypeId: google.maps.MapTypeId.ROADMAP, - center: centre, - zoom: 13 + fixmystreet.zoom, - disableDefaultUI: true, - panControl: true, - panControlOptions: { - position: google.maps.ControlPosition.RIGHT_TOP - }, - zoomControl: true, - zoomControlOptions: { - position: google.maps.ControlPosition.RIGHT_TOP - }, - mapTypeControl: true, - mapTypeControlOptions: { - position: google.maps.ControlPosition.RIGHT_TOP, - style: google.maps.MapTypeControlStyle.DROPDOWN_MENU + /* Pan data handler */ + function read_pin_json(obj) { + var current, current_near; + if (typeof(obj.current) != 'undefined' && (current = document.getElementById('current'))) { + current.innerHTML = obj.current; } - }; - if (!fixmystreet.zoomToBounds) { - map_args.minZoom = 13; - map_args.maxZoom = 18; + if (typeof(obj.current_near) != 'undefined' && (current_near = document.getElementById('current_near'))) { + current_near.innerHTML = obj.current_near; + } + fixmystreet.markers = markers_list( obj.pins, false ); } - fixmystreet.map = new google.maps.Map(document.getElementById("map"), map_args); - - /* Space above the top right controls */ - var paddingDiv = document.createElement('div'); - var paddingControl = new PaddingControl(paddingDiv); - paddingDiv.index = 0; - fixmystreet.map.controls[google.maps.ControlPosition.RIGHT_TOP].push(paddingDiv); - if (document.getElementById('mapForm')) { - var l = google.maps.event.addListener(fixmystreet.map, 'click', fms_map_clicked); + function update_pins() { + var b = fixmystreet.map.getBounds(), + b_sw = b.getSouthWest(), + b_ne = b.getNorthEast(), + bbox = b_sw.lng() + ',' + b_sw.lat() + ',' + b_ne.lng() + ',' + b_ne.lat(), + params = { + bbox: bbox + }; + if (fixmystreet.all_pins) { + params.all_pins = 1; + } + $.getJSON('/ajax', params, read_pin_json); } - $(window).hashchange(function(){ - if (location.hash == '#report' && $('.rap-notes').is(':visible')) { - $('.rap-notes-close').click(); - return; + function map_initialize() { + var centre = new google.maps.LatLng( fixmystreet.latitude, fixmystreet.longitude ); + var map_args = { + mapTypeId: google.maps.MapTypeId.ROADMAP, + center: centre, + zoom: 13 + fixmystreet.zoom, + disableDefaultUI: true, + panControl: true, + panControlOptions: { + position: google.maps.ControlPosition.RIGHT_TOP + }, + zoomControl: true, + zoomControlOptions: { + position: google.maps.ControlPosition.RIGHT_TOP + }, + mapTypeControl: true, + mapTypeControlOptions: { + position: google.maps.ControlPosition.RIGHT_TOP, + style: google.maps.MapTypeControlStyle.DROPDOWN_MENU + } + }; + if (!fixmystreet.zoomToBounds) { + map_args.minZoom = 13; + map_args.maxZoom = 18; } + fixmystreet.map = new google.maps.Map(document.getElementById("map"), map_args); - if (location.hash && location.hash != '#') { - return; - } + /* Space above the top right controls */ + var paddingDiv = document.createElement('div'); + var paddingControl = new PaddingControl(paddingDiv); + paddingDiv.index = 0; + fixmystreet.map.controls[google.maps.ControlPosition.RIGHT_TOP].push(paddingDiv); - // Okay, back to around view. - fixmystreet.report_marker.setMap(null); - fixmystreet.event_update_map = google.maps.event.addListener(fixmystreet.map, 'idle', fms_update_pins); - google.maps.event.trigger(fixmystreet.map, 'idle'); - if ( fixmystreet.state_pins_were_hidden ) { - // If we had pins hidden when we clicked map (which had to show the pin layer as I'm doing it in one layer), hide them again. - $('#hide_pins_link').click(); + if (document.getElementById('mapForm')) { + var l = google.maps.event.addListener(fixmystreet.map, 'click', map_clicked); } - $('#side-form').hide(); - $('#side').show(); - $('#sub_map_links').show(); - //only on mobile - $('#mob_sub_map_links').remove(); - $('.mobile-map-banner').html('<a href="/">' + translation_strings.home + '</a> ' + translation_strings.place_pin_on_map); - fixmystreet.page = 'around'; - }); - if ( fixmystreet.area.length ) { - for (var i=0; i<fixmystreet.area.length; i++) { - var args = { - url: "http://mapit.mysociety.org/area/" + fixmystreet.area[i] + ".kml?simplify_tolerance=0.0001", - clickable: false, - preserveViewport: true, - map: fixmystreet.map - }; - if ( fixmystreet.area.length == 1 ) { - args.preserveViewport = false; + if ( fixmystreet.area.length ) { + for (var i=0; i<fixmystreet.area.length; i++) { + var args = { + url: "http://mapit.mysociety.org/area/" + fixmystreet.area[i] + ".kml?simplify_tolerance=0.0001", + clickable: false, + preserveViewport: true, + map: fixmystreet.map + }; + if ( fixmystreet.area.length == 1 ) { + args.preserveViewport = false; + } + var a = new google.maps.KmlLayer(args); + a.setMap(fixmystreet.map); } - var a = new google.maps.KmlLayer(args); - a.setMap(fixmystreet.map); } - } - if (fixmystreet.page == 'around') { - fixmystreet.event_update_map = google.maps.event.addListener(fixmystreet.map, 'idle', fms_update_pins); - } + if (fixmystreet.page == 'around') { + fixmystreet.event_update_map = google.maps.event.addListener(fixmystreet.map, 'idle', update_pins); + } - fixmystreet.markers = fms_markers_list( fixmystreet.pins, true ); + fixmystreet.markers = markers_list( fixmystreet.pins, true ); - /* - if ( fixmystreet.zoomToBounds ) { - var bounds = fixmystreet.markers.getDataExtent(); - if (bounds) { - var center = bounds.getCenterLonLat(); - var z = fixmystreet.map.getZoomForExtent(bounds); - if ( z < 13 && $('html').hasClass('mobile') ) { - z = 13; + /* + if ( fixmystreet.zoomToBounds ) { + var bounds = fixmystreet.markers.getDataExtent(); + if (bounds) { + var center = bounds.getCenterLonLat(); + var z = fixmystreet.map.getZoomForExtent(bounds); + if ( z < 13 && $('html').hasClass('mobile') ) { + z = 13; + } + fixmystreet.map.setCenter(center, z); } - fixmystreet.map.setCenter(center, z); } - } - */ + */ - $('#hide_pins_link').click(function(e) { - var i, m; - e.preventDefault(); - var showhide = [ - 'Show pins', 'Hide pins', - 'Dangos pinnau', 'Cuddio pinnau', - "Vis nåler", "Gjem nåler", - "Zeige Stecknadeln", "Stecknadeln ausblenden" - ]; - for (i=0; i<showhide.length; i+=2) { - if (this.innerHTML == showhide[i]) { - for (m=0; m<fixmystreet.markers.length; m++) { - fixmystreet.markers[m].setMap(fixmystreet.map); - } - this.innerHTML = showhide[i+1]; - } else if (this.innerHTML == showhide[i+1]) { - for (m=0; m<fixmystreet.markers.length; m++) { - fixmystreet.markers[m].setMap(null); + $('#hide_pins_link').click(function(e) { + var i, m; + e.preventDefault(); + var showhide = [ + 'Show pins', 'Hide pins', + 'Dangos pinnau', 'Cuddio pinnau', + "Vis nåler", "Gjem nåler", + "Zeige Stecknadeln", "Stecknadeln ausblenden" + ]; + for (i=0; i<showhide.length; i+=2) { + if (this.innerHTML == showhide[i]) { + for (m=0; m<fixmystreet.markers.length; m++) { + fixmystreet.markers[m].setMap(fixmystreet.map); + } + this.innerHTML = showhide[i+1]; + } else if (this.innerHTML == showhide[i+1]) { + for (m=0; m<fixmystreet.markers.length; m++) { + fixmystreet.markers[m].setMap(null); + } + this.innerHTML = showhide[i]; } - this.innerHTML = showhide[i]; } - } - }); + }); - $('#all_pins_link').click(function(e) { - var i; - e.preventDefault(); - for (i=0; i<fixmystreet.markers.length; i++) { - fixmystreet.markers[i].setMap(fixmystreet.map); - } - var texts = [ - 'en', 'Show old', 'Hide old', - 'nb', 'Inkluder utdaterte problemer', 'Skjul utdaterte rapporter', - 'cy', 'Cynnwys hen adroddiadau', 'Cuddio hen adroddiadau' - ]; - for (i=0; i<texts.length; i+=3) { - if (this.innerHTML == texts[i+1]) { - this.innerHTML = texts[i+2]; - fixmystreet.markers.protocol.options.params = { all_pins: 1 }; - fixmystreet.markers.refresh( { force: true } ); - lang = texts[i]; - } else if (this.innerHTML == texts[i+2]) { - this.innerHTML = texts[i+1]; - fixmystreet.markers.protocol.options.params = { }; - fixmystreet.markers.refresh( { force: true } ); - lang = texts[i]; + $('#all_pins_link').click(function(e) { + var i; + e.preventDefault(); + for (i=0; i<fixmystreet.markers.length; i++) { + fixmystreet.markers[i].setMap(fixmystreet.map); } - } - if (lang == 'cy') { - document.getElementById('hide_pins_link').innerHTML = 'Cuddio pinnau'; - } else if (lang == 'nb') { - document.getElementById('hide_pins_link').innerHTML = 'Gjem nåler'; - } else { - document.getElementById('hide_pins_link').innerHTML = 'Hide pins'; - } - }); + var texts = [ + 'en', 'Show old', 'Hide old', + 'nb', 'Inkluder utdaterte problemer', 'Skjul utdaterte rapporter', + 'cy', 'Cynnwys hen adroddiadau', 'Cuddio hen adroddiadau' + ]; + for (i=0; i<texts.length; i+=3) { + if (this.innerHTML == texts[i+1]) { + this.innerHTML = texts[i+2]; + fixmystreet.markers.protocol.options.params = { all_pins: 1 }; + fixmystreet.markers.refresh( { force: true } ); + lang = texts[i]; + } else if (this.innerHTML == texts[i+2]) { + this.innerHTML = texts[i+1]; + fixmystreet.markers.protocol.options.params = { }; + fixmystreet.markers.refresh( { force: true } ); + lang = texts[i]; + } + } + if (lang == 'cy') { + document.getElementById('hide_pins_link').innerHTML = 'Cuddio pinnau'; + } else if (lang == 'nb') { + document.getElementById('hide_pins_link').innerHTML = 'Gjem nåler'; + } else { + document.getElementById('hide_pins_link').innerHTML = 'Hide pins'; + } + }); + + } -} + google.maps.visualRefresh = true; + google.maps.event.addDomListener(window, 'load', map_initialize); -google.maps.visualRefresh = true; -google.maps.event.addDomListener(window, 'load', fms_map_initialize); +})(); diff --git a/web/js/map-streetview.js b/web/js/map-streetview.js index 58d856781..6d9195246 100644 --- a/web/js/map-streetview.js +++ b/web/js/map-streetview.js @@ -1,4 +1,4 @@ -function set_map_config(perm) { +fixmystreet.maps.config = function() { fixmystreet.controls = [ new OpenLayers.Control.ArgParser(), new OpenLayers.Control.Navigation(), @@ -6,7 +6,7 @@ function set_map_config(perm) { new OpenLayers.Control.PanZoomFMS() ]; fixmystreet.map_type = OpenLayers.Layer.StreetView; -} +}; // http://os.openstreetmap.org/openlayers/OS.js (added one line) diff --git a/web/js/map-toner-lite.js b/web/js/map-toner-lite.js index 5291d0254..eda12ff28 100644 --- a/web/js/map-toner-lite.js +++ b/web/js/map-toner-lite.js @@ -1,4 +1,4 @@ -function set_map_config(perm) { +fixmystreet.maps.config = function() { var permalink_id; if ($('#map_permalink').length) { permalink_id = 'map_permalink'; @@ -16,4 +16,4 @@ function set_map_config(perm) { // The Stamen JS returns HTTP urls, fix that stamen.tile.getProvider('toner-lite').url = 'https://stamen-tiles-{S}a.ssl.fastly.net/toner-lite/{Z}/{X}/{Y}.png'; -} +}; diff --git a/web/js/map-wmts-bristol.js b/web/js/map-wmts-bristol.js index 0fb664d76..94ed2bdb2 100644 --- a/web/js/map-wmts-bristol.js +++ b/web/js/map-wmts-bristol.js @@ -94,10 +94,10 @@ var matrix_ids = [ ]; /* - * set_map_config() is called on dom ready in map-OpenLayers.js + * maps.config() is called on dom ready in map-OpenLayers.js * to setup the way the map should operate. */ - function set_map_config(perm) { +fixmystreet.maps.config = function() { // This stuff is copied from js/map-bing-ol.js var nav_opts = { zoomWheelEnabled: false }; @@ -120,9 +120,9 @@ var matrix_ids = [ } setup_wmts_base_map(); -} +}; -function fms_marker_size_for_zoom(zoom) { +fixmystreet.maps.marker_size_for_zoom = function(zoom) { if (zoom >= 7) { return 'normal'; } else if (zoom >= 4) { @@ -130,4 +130,4 @@ function fms_marker_size_for_zoom(zoom) { } else { return 'mini'; } -} +}; diff --git a/web/js/map-wmts-zurich.js b/web/js/map-wmts-zurich.js index aa673f52d..1995cb401 100644 --- a/web/js/map-wmts-zurich.js +++ b/web/js/map-wmts-zurich.js @@ -113,58 +113,62 @@ var matrix_ids = [ } ]; -function fixmystreet_zurich_admin_drag() { - var admin_drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, { - onComplete: function(feature, e) { - var lonlat = feature.geometry.clone(); - lonlat.transform( - fixmystreet.map.getProjectionObject(), - new OpenLayers.Projection("EPSG:4326") - ); - if (window.confirm( 'Richtiger Ort?' ) ) { - // Store new co-ordinates - document.getElementById('fixmystreet.latitude').value = lonlat.y; - document.getElementById('fixmystreet.longitude').value = lonlat.x; - } else { - // Put it back - var lat = document.getElementById('fixmystreet.latitude').value; - var lon = document.getElementById('fixmystreet.longitude').value; - lonlat = new OpenLayers.LonLat(lon, lat).transform( - new OpenLayers.Projection("EPSG:4326"), - fixmystreet.map.getProjectionObject() +(function() { + + function admin_drag() { + var drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, { + onComplete: function(feature, e) { + var lonlat = feature.geometry.clone(); + lonlat.transform( + fixmystreet.map.getProjectionObject(), + new OpenLayers.Projection("EPSG:4326") ); - fixmystreet.markers.features[0].move(lonlat); + if (window.confirm( 'Richtiger Ort?' ) ) { + // Store new co-ordinates + document.getElementById('fixmystreet.latitude').value = lonlat.y; + document.getElementById('fixmystreet.longitude').value = lonlat.x; + } else { + // Put it back + var lat = document.getElementById('fixmystreet.latitude').value; + var lon = document.getElementById('fixmystreet.longitude').value; + lonlat = new OpenLayers.LonLat(lon, lat).transform( + new OpenLayers.Projection("EPSG:4326"), + fixmystreet.map.getProjectionObject() + ); + fixmystreet.markers.features[0].move(lonlat); + } } - } - } ); - fixmystreet.map.addControl( admin_drag ); - admin_drag.activate(); -} + } ); + fixmystreet.map.addControl( drag ); + drag.activate(); + } -$(function(){ - $('#map_layer_toggle').toggle(function(){ - $(this).text('Luftbild'); - fixmystreet.map.setBaseLayer(fixmystreet.map.layers[1]); - }, function(){ - $(this).text('Stadtplan'); - fixmystreet.map.setBaseLayer(fixmystreet.map.layers[0]); - }); + $(function(){ + $('#map_layer_toggle').toggle(function(){ + $(this).text('Luftbild'); + fixmystreet.map.setBaseLayer(fixmystreet.map.layers[1]); + }, function(){ + $(this).text('Stadtplan'); + fixmystreet.map.setBaseLayer(fixmystreet.map.layers[0]); + }); - /* Admin dragging of pin */ - if (fixmystreet.page == 'admin') { - if ($.browser.msie) { - $(window).load(fixmystreet_zurich_admin_drag); - } else { - fixmystreet_zurich_admin_drag(); + /* Admin dragging of pin */ + if (fixmystreet.page == 'admin') { + if ($.browser.msie) { + $(window).load(admin_drag); + } else { + admin_drag(); + } } - } -}); + }); + +})(); /* - * set_map_config() is called on dom ready in map-OpenLayers.js + * maps.config() is called on dom ready in map-OpenLayers.js * to setup the way the map should operate. */ - function set_map_config(perm) { +fixmystreet.maps.config = function() { // This stuff is copied from js/map-bing-ol.js fixmystreet.controls = [ @@ -183,9 +187,9 @@ $(function(){ setup_wmts_base_map(); fixmystreet.area_format = { fillColor: 'none', strokeWidth: 4, strokeColor: 'black' }; -} +}; -function fms_marker_size_for_zoom(zoom) { +fixmystreet.maps.marker_size_for_zoom = function(zoom) { if (zoom >= 6) { return 'normal'; } else if (zoom >= 3) { @@ -193,4 +197,4 @@ function fms_marker_size_for_zoom(zoom) { } else { return 'mini'; } -} +}; |