From a252b0a80bd0f71f567520e566c4429fb8ecd272 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Sun, 14 May 2017 20:55:49 +0000 Subject: [PATCH] Add attributions to the map --- map.js | 46 +++++++++++++++++++++++++++++++--------------- 1 files changed, 31 insertions(+), 15 deletions(-) diff --git a/map.js b/map.js index f791391..0cbdf09 100644 --- a/map.js +++ b/map.js @@ -23,7 +23,6 @@ var map = null; var map_sphere = null; -var fail_element = document.getElementById('fail'); var ignore_hashchange = false; @@ -63,10 +62,25 @@ }, }; -function fail(msg) { - setText(fail_element, msg); - fail_element.style.top = '0.5em'; -} +var Alert = { + element: document.getElementById('fail'), + action: undefined, + + fail: function(message, action) { + if(this.action) { + this.element.removeEventListener('click', this.action); + this.action = undefined; + } + + setText(this.element, message); + this.element.style.top = '0.5em'; + + if(action) { + this.action = action; + this.element.addEventListener('click', action); + } + }, +}; function fail_ajax_generic(data, fnc) { // abort() is not a failure @@ -82,11 +96,11 @@ } function fail_ajax(data) { - fail_ajax_generic(data, fail); + fail_ajax_generic(data, Alert.fail.bind(Alert)); } function fail_ajax_popup(data) { - fail_ajax_generic(data, Panel.fail); + fail_ajax_generic(data, Panel.fail.bind(Panel)); } function getGeometry(object) { @@ -588,7 +602,7 @@ function init() { if(!window.jQuery) { - fail(lang.jquery_not_loaded); + Alert.fail(lang.jquery_not_loaded); return; } @@ -602,6 +616,7 @@ }); stops_layer = new ol.layer.Vector({ source: stops_source, + }); stop_points_source = new ol.source.Vector({ @@ -614,6 +629,7 @@ vehicles_source = new ol.source.Vector({ features: [], + attributions: lang.copy_zikit, }); vehicles_layer = new ol.layer.Vector({ source: vehicles_source, @@ -621,6 +637,7 @@ route_source = new ol.source.Vector({ features: [], + attributions: lang.copy_jacekk, }); route_layer = new ol.layer.Vector({ source: route_source, @@ -633,7 +650,9 @@ target: 'map', layers: [ new ol.layer.Tile({ - source: new ol.source.OSM() + source: new ol.source.OSM({ + attributions: lang.copy_osm, + }) }), route_layer, stops_layer, @@ -653,7 +672,7 @@ element: document.getElementById('title'), }), new ol.control.Control({ - element: fail_element, + element: Alert.element, }) ]), loadTilesWhileAnimating: true, @@ -725,10 +744,6 @@ featureClicked(feature); }); - - fail_element.addEventListener('click', function() { - fail_element.style.top = '-10em'; - }); // Change mouse cursor when over marker map.on('pointermove', function(e) { @@ -756,8 +771,9 @@ if(vehicles_xhr) vehicles_xhr.abort(); if(vehicles_timer) clearTimeout(vehicles_timer); - fail(lang.error_refresh); + Alert.fail(lang.error_refresh); }, 1800000); } init(); +checkVersion(); -- Gitblit v1.9.1