From faeeb1736b7596490f2bb6cecd62bd0f3a99f11b Mon Sep 17 00:00:00 2001 From: Nikolaus Krismer <niko@krismer.de> Date: Fri, 14 Feb 2014 18:34:30 +0100 Subject: [PATCH] fixed various jsHint warnings --- build.gradle | 4 +- src/main/webapp/js/app.js | 7 +- src/main/webapp/js/isochrone/configuration.js | 2 +- src/main/webapp/js/map/control/geosearch.js | 800 +++++++++--------- .../js/map/control/geosearchProvider/osm.js | 162 ++-- src/main/webapp/js/map/control/help.js | 30 +- src/main/webapp/js/map/control/settings.js | 30 +- .../webapp/js/map/ipLocator/mapIncluder.js | 2 +- src/main/webapp/js/map/isoMap.js | 98 +-- src/main/webapp/js/map/layer/bing.js | 14 +- src/main/webapp/js/map/layer/google.js | 37 +- .../webapp/js/service/serviceConfiguration.js | 2 +- src/main/webapp/js/service/websocket.js | 22 +- 13 files changed, 612 insertions(+), 598 deletions(-) diff --git a/build.gradle b/build.gradle index 67f901f0..5d5cfe25 100644 --- a/build.gradle +++ b/build.gradle @@ -183,14 +183,14 @@ task javadocJar(type: Jar, dependsOn: javadoc) { } task jsDoc(type:com.eriwen.gradle.js.tasks.JsDocTask) { - source = fileTree(dir: 'src/main/webapp/js', include: '**/*.js', exclude: '**/*.min.js') + source = fileTree(dir: 'src/main/webapp/js', include: '**/*.js', excludes: ['**/*.min.js', 'lib/**']) destinationDir = file("${buildDir}/docs/jsdoc") } tasks.jsDoc.dependsOn tasks.processResources task jsHint(type:com.eriwen.gradle.js.tasks.JsHintTask) { - source = fileTree(dir: 'src/main/webapp/js', include: '**/*.js', exclude: '**/*.min.js') + source = fileTree(dir: 'src/main/webapp/js', include: '**/*.js', exclude: ['**/*.min.js', 'lib/**']) dest = file("${buildDir}/reports/jshint/main.xml") reporter = 'checkstyle' } diff --git a/src/main/webapp/js/app.js b/src/main/webapp/js/app.js index e628c5dd..fae5c494 100644 --- a/src/main/webapp/js/app.js +++ b/src/main/webapp/js/app.js @@ -1,3 +1,6 @@ +/** + * RequireJS Configuration + */ require.config({ baseUrl: 'js', paths: { @@ -17,10 +20,10 @@ require.config({ exports: '$' }, 'jQueryUI': { - deps: ['jQuery'], + deps: ['jQuery'] }, 'jQueryUI-timepicker': { - deps: ['jQueryUI'], + deps: ['jQueryUI'] }, 'leaflet': { exports: 'L' diff --git a/src/main/webapp/js/isochrone/configuration.js b/src/main/webapp/js/isochrone/configuration.js index 6d54ed3e..27b50a6e 100644 --- a/src/main/webapp/js/isochrone/configuration.js +++ b/src/main/webapp/js/isochrone/configuration.js @@ -3,7 +3,7 @@ * This is used to store the client's configuration */ define(['console'], function(logger) { - instance = null; + var instance = null; function Configuration() { var datasetConfigMap = {}; diff --git a/src/main/webapp/js/map/control/geosearch.js b/src/main/webapp/js/map/control/geosearch.js index 0e65ce23..b230d8d5 100644 --- a/src/main/webapp/js/map/control/geosearch.js +++ b/src/main/webapp/js/map/control/geosearch.js @@ -5,408 +5,408 @@ */ define(['leaflet'], function(L) { L.Control.GeoSearch = L.Control.extend({ - options: { - doReverseLookup: false, - position: 'topleft', - provider: null, - showMarker: true - }, - - _config: { - country: '', - searchLabel: 'Search for address ...', - notFoundMessage: 'Sorry, that address could not be found.', - messageHideDelay: 3000, - zoomLevel: 18 - }, - - // Public methods - - initialize: function (options) { - L.Util.extend(this.options, options); - L.Util.extend(this._config, options); - }, - - geosearch: function (qry) { - try { - var provider = this._config.provider; - - if(typeof provider.GetLocations == 'function') { - provider.GetLocations(qry, function(results) { - this._processResults(results); - }.bind(this)); - } else { - var url = provider.GetServiceUrl(qry); - this.sendRequest(provider, url); - } - } catch (error) { - this._printError(error); - } - }, - - onAdd: function (map) { - this._map = map; - this._container = L.DomUtil.create('div', 'leaflet-control-geosearch'); - this._suggestSet = []; - - var searchdiv = document.createElement('div'); - searchdiv.id = 'leaflet-control-geosearch-searchdiv'; - searchdiv.className = 'leaflet-control-geosearch-searchdiv'; - this._searchdiv = searchdiv; - - var searchbox = document.createElement('input'); - searchbox.id = 'leaflet-control-geosearch-qry'; - searchbox.type = 'text'; - searchbox.placeholder = this._config.searchLabel; - this._searchbox = searchbox; - - var searchbtn = document.createElement('button'); - searchbtn.id = 'leaflet-control-geosearch-btn'; - searchbtn.className = 'leaflet-control-geosearch-btn'; - this._searchbtn = searchbtn; - - var msgbox = document.createElement('div'); - msgbox.id = 'leaflet-control-geosearch-msg'; - msgbox.className = 'leaflet-control-geosearch-msg'; - this._msgbox = msgbox; - - var result = document.createElement('ul'); - result.id = 'leaflet-control-geosearch-result'; - result.className = 'leaflet-control-geosearch-result'; - this._result = result; - - var suggestlist = document.createElement('ul'); - suggestlist.id = 'leaflet-control-geosearch-suggests'; - suggestlist.className = 'leaflet-control-geosearch-suggests'; - this._suggestlist = suggestlist; - - this._msgbox.appendChild(this._suggestlist); - this._msgbox.appendChild(this._result); - this._searchdiv.appendChild(this._searchbtn); - this._searchdiv.appendChild(this._searchbox); - this._container.appendChild(this._searchdiv); - this._container.appendChild(this._msgbox); - - L.DomEvent - .addListener(this._container, 'click', L.DomEvent.stop) - .addListener(this._searchbtn, 'click', this._onSearchClick, this) - .addListener(this._searchbox, 'keypress', this._onKeyUp, this); - - if (this._config.doReverseLookup && this._config.provider.options.reverseable) { - L.DomEvent.addListener(this._map, 'click', this._onMapClick, this); - } - - L.DomEvent.disableClickPropagation(this._container); - - return this._container; - }, - - sendRequest: function (provider, url) { - var that = this; - - window.parseLocation = function (response) { - var results = provider.ParseJSON(response); - that._processResults(results); - - document.body.removeChild(document.getElementById('getJsonP')); - delete window.parseLocation; - }; - - function getJsonP (url) { - url = url + '&callback=parseLocation'; - var script = document.createElement('script'); - script.id = 'getJsonP'; - script.src = url; - script.async = true; - document.body.appendChild(script); - } - - if (XMLHttpRequest) { - var xhr = new XMLHttpRequest(); - - if ('withCredentials' in xhr) { - var xhr = new XMLHttpRequest(); - - xhr.onreadystatechange = function () { - if (xhr.readyState == 4) { - if (xhr.status == 200) { - var response = JSON.parse(xhr.responseText), - results = provider.ParseJSON(response); - - that._processResults(results); - } else if (xhr.status == 0 || xhr.status == 400) { - getJsonP(url); - } else { - that._printError(xhr.responseText); - } - } - }; - - xhr.open('GET', url, true); - xhr.send(); - } else if (XDomainRequest) { - var xdr = new XDomainRequest(); - - xdr.onerror = function (err) { - that._printError(err); - }; - - xdr.onload = function () { - var response = JSON.parse(xdr.responseText), - results = provider.ParseJSON(response); - - that._processResults(results); - }; - - xdr.open('GET', url); - xdr.send(); - } else { - getJsonP(url); - } - } - }, - - // Private methods - - _addressToString : function(address) { - if (!address) { - return ''; - } - - var addressStr = ''; - if (address.road) addressStr += address.road + ', '; - if (address.postcode) addressStr += address.postcode + ', '; - if (address.country) addressStr += address.country; - if (/, $/.test(addressStr)) addressStr = addressStr.substring(0, addressStr.length - 2); - - return addressStr; - }, - - _clearResult : function() { - if (this._timeout != null) { - clearTimeout(this._timeout); - this._timeout = null; - } - - var elem = this._result; - elem.innerHTML = ''; - elem.style.display = 'none'; - }, - - _clearSuggestList : function() { - this._suggestSet = []; - if (this._timeout != null) { - clearTimeout(this._timeout); - this._timeout = null; - } - - var elem = this._suggestlist; - elem.innerHTML = ''; - elem.style.display = 'none'; - }, - - _isInSuggestSet : function(o) { - var i = 0, - set = this._suggestSet; - - for (i = 0; i < set.length; ++i) { - if (set[i].lat == o.lat && set[i].lon == o.lon) { - return true; - } - } - - return false; - }, - - _onKeyUp: function (e) { - var esc = 27, - enter = 13, - queryBox = document.getElementById('leaflet-control-geosearch-qry'); - - if (e.keyCode === esc) { // escape key detection is unreliable - queryBox.value = ''; - this._map._container.focus(); - } else if (e.keyCode === enter) { - this.geosearch(queryBox.value); - } - }, - - _onMapClick: function (e) { - var location = e.latlng, - provider = this._config.provider; - - if (!location || !provider) { - return; - } - - try { - var url = provider.GetServiceUrl(location.lat, location.lng); - this.sendRequest(provider, url); - } catch (error) { - this._printError(error); - } - }, - - _onSuggestClick : function (e) { - var suggestId = e.target.id, - suggestIndex = -1, - suggest = null; - - if (suggestId) { - suggestIndex = suggestId.substring(suggestId.lastIndexOf('-') + 1); - } - - if (suggestIndex >= 0) { - suggest = this._suggestSet[suggestIndex]; - } - - if (suggest) { - this._showLocation(suggest); - } - }, - - _onSearchClick: function (e) { - var queryBox = document.getElementById('leaflet-control-geosearch-qry'); - - this.geosearch(queryBox.value); - }, - - _processResults: function(results) { - if (results instanceof Array) { - this._processForwardResults(results); - } else { - this._processReverseResults(results); - } - }, - - _processForwardResults: function(results) { - var resultCount = results.length; - if (resultCount <= 0) { - this._printError(this._config.notFoundMessage); - return; - } - - this._map.fireEvent('geosearch_foundlocations', {Locations: results}); - if (resultCount == 1) { - // only one result found... show it - this._showLocation(results[0]); - } else { - // multiple results found... add to results list and let user choose which one to show - this._setSuggestList(results); - } - }, - - _processReverseResults: function(result) { - if (!result) { - this._printError(this._config.notFoundMessage); - } - - this._map.fireEvent('geosearch_clicklocation', {Location: result}); - this._setResult(result); - }, - - _setResult: function(result) { - var displayName = null, - displayDescription = null, - divText = document.createElement('div'), - elem = this._result, - index = -1; - li = document.createElement('li'), - txtDescription = null, - txtName = null; - - if (result.lat == undefined || result.lon == undefined) { - return; - } - - this._clearResult(); - - index = result.displayName.indexOf(','); - displayName = result.displayName.substring(0, index); - displayDescription = result.displayName.substring(index + 1); - - li.id = 'geosearch-result'; - li.className = 'geosearch-result'; - txtDescription = document.createElement('span'); - txtDescription.className = 'result-description'; - txtDescription.innerHTML = displayDescription.replace(/^\s+|\s+$/g,''); - txtName = document.createElement('span'); - txtName.className = 'result-name'; - txtName.innerHTML = displayName.replace(/^\s+|\s+$/g,''); - divText.className = 'geosearch-result-text'; - divText.appendChild(txtName); - divText.appendChild(txtDescription); - li.appendChild(divText); - - elem.appendChild(li); - elem.style.display = 'block'; - - this._map.fireEvent('geosearch_showresult', {element: elem, queryPoint: L.latLng({lat: parseFloat(result.lat), lon: parseFloat(result.lon)})}); - }, + options: { + doReverseLookup: false, + position: 'topleft', + provider: null, + showMarker: true + }, + + _config: { + country: '', + searchLabel: 'Search for address ...', + notFoundMessage: 'Sorry, that address could not be found.', + messageHideDelay: 3000, + zoomLevel: 18 + }, + + // Public methods + + initialize: function (options) { + L.Util.extend(this.options, options); + L.Util.extend(this._config, options); + }, + + geosearch: function (qry) { + try { + var provider = this._config.provider; + + if(typeof provider.GetLocations == 'function') { + provider.GetLocations(qry, function(results) { + this._processResults(results); + }.bind(this)); + } else { + var url = provider.GetServiceUrl(qry); + this.sendRequest(provider, url); + } + } catch (error) { + this._printError(error); + } + }, + + onAdd: function (map) { + this._map = map; + this._container = L.DomUtil.create('div', 'leaflet-control-geosearch'); + this._suggestSet = []; + + var searchdiv = document.createElement('div'); + searchdiv.id = 'leaflet-control-geosearch-searchdiv'; + searchdiv.className = 'leaflet-control-geosearch-searchdiv'; + this._searchdiv = searchdiv; + + var searchbox = document.createElement('input'); + searchbox.id = 'leaflet-control-geosearch-qry'; + searchbox.type = 'text'; + searchbox.placeholder = this._config.searchLabel; + this._searchbox = searchbox; + + var searchbtn = document.createElement('button'); + searchbtn.id = 'leaflet-control-geosearch-btn'; + searchbtn.className = 'leaflet-control-geosearch-btn'; + this._searchbtn = searchbtn; + + var msgbox = document.createElement('div'); + msgbox.id = 'leaflet-control-geosearch-msg'; + msgbox.className = 'leaflet-control-geosearch-msg'; + this._msgbox = msgbox; + + var result = document.createElement('ul'); + result.id = 'leaflet-control-geosearch-result'; + result.className = 'leaflet-control-geosearch-result'; + this._result = result; + + var suggestlist = document.createElement('ul'); + suggestlist.id = 'leaflet-control-geosearch-suggests'; + suggestlist.className = 'leaflet-control-geosearch-suggests'; + this._suggestlist = suggestlist; + + this._msgbox.appendChild(this._suggestlist); + this._msgbox.appendChild(this._result); + this._searchdiv.appendChild(this._searchbtn); + this._searchdiv.appendChild(this._searchbox); + this._container.appendChild(this._searchdiv); + this._container.appendChild(this._msgbox); + + L.DomEvent + .addListener(this._container, 'click', L.DomEvent.stop) + .addListener(this._searchbtn, 'click', this._onSearchClick, this) + .addListener(this._searchbox, 'keypress', this._onKeyUp, this); + + if (this._config.doReverseLookup && this._config.provider.options.reverseable) { + L.DomEvent.addListener(this._map, 'click', this._onMapClick, this); + } + + L.DomEvent.disableClickPropagation(this._container); + + return this._container; + }, + + sendRequest: function (provider, url) { + var that = this; + + window.parseLocation = function (response) { + var results = provider.ParseJSON(response); + that._processResults(results); + + document.body.removeChild(document.getElementById('getJsonP')); + delete window.parseLocation; + }; + + function getJsonP (url) { + url = url + '&callback=parseLocation'; + var script = document.createElement('script'); + script.id = 'getJsonP'; + script.src = url; + script.async = true; + document.body.appendChild(script); + } + + if (XMLHttpRequest) { + var xhr = new XMLHttpRequest(); + + if ('withCredentials' in xhr) { + var xhr = new XMLHttpRequest(); + + xhr.onreadystatechange = function () { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + var response = JSON.parse(xhr.responseText), + results = provider.ParseJSON(response); + + that._processResults(results); + } else if (xhr.status == 0 || xhr.status == 400) { + getJsonP(url); + } else { + that._printError(xhr.responseText); + } + } + }; + + xhr.open('GET', url, true); + xhr.send(); + } else if (XDomainRequest) { + var xdr = new XDomainRequest(); + + xdr.onerror = function (err) { + that._printError(err); + }; + + xdr.onload = function () { + var response = JSON.parse(xdr.responseText), + results = provider.ParseJSON(response); + + that._processResults(results); + }; + + xdr.open('GET', url); + xdr.send(); + } else { + getJsonP(url); + } + } + }, + + // Private methods + + _addressToString : function(address) { + if (!address) { + return ''; + } + + var addressStr = ''; + if (address.road) addressStr += address.road + ', '; + if (address.postcode) addressStr += address.postcode + ', '; + if (address.country) addressStr += address.country; + if (/, $/.test(addressStr)) addressStr = addressStr.substring(0, addressStr.length - 2); + + return addressStr; + }, + + _clearResult : function() { + if (this._timeout != null) { + clearTimeout(this._timeout); + this._timeout = null; + } + + var elem = this._result; + elem.innerHTML = ''; + elem.style.display = 'none'; + }, + + _clearSuggestList : function() { + this._suggestSet = []; + if (this._timeout != null) { + clearTimeout(this._timeout); + this._timeout = null; + } + + var elem = this._suggestlist; + elem.innerHTML = ''; + elem.style.display = 'none'; + }, + + _isInSuggestSet : function(o) { + var i = 0, + set = this._suggestSet; + + for (i = 0; i < set.length; ++i) { + if (set[i].lat == o.lat && set[i].lon == o.lon) { + return true; + } + } + + return false; + }, + + _onKeyUp: function (e) { + var esc = 27, + enter = 13, + queryBox = document.getElementById('leaflet-control-geosearch-qry'); + + if (e.keyCode === esc) { // escape key detection is unreliable + queryBox.value = ''; + this._map._container.focus(); + } else if (e.keyCode === enter) { + this.geosearch(queryBox.value); + } + }, + + _onMapClick: function (e) { + var location = e.latlng, + provider = this._config.provider; + + if (!location || !provider) { + return; + } + + try { + var url = provider.GetServiceUrl(location.lat, location.lng); + this.sendRequest(provider, url); + } catch (error) { + this._printError(error); + } + }, + + _onSuggestClick : function (e) { + var suggestId = e.target.id, + suggestIndex = -1, + suggest = null; + + if (suggestId) { + suggestIndex = suggestId.substring(suggestId.lastIndexOf('-') + 1); + } + + if (suggestIndex >= 0) { + suggest = this._suggestSet[suggestIndex]; + } + + if (suggest) { + this._showLocation(suggest); + } + }, + + _onSearchClick: function (e) { + var queryBox = document.getElementById('leaflet-control-geosearch-qry'); + + this.geosearch(queryBox.value); + }, + + _processResults: function(results) { + if (results instanceof Array) { + this._processForwardResults(results); + } else { + this._processReverseResults(results); + } + }, + + _processForwardResults: function(results) { + var resultCount = results.length; + if (resultCount <= 0) { + this._printError(this._config.notFoundMessage); + return; + } + + this._map.fireEvent('geosearch_foundlocations', {Locations: results}); + if (resultCount == 1) { + // only one result found... show it + this._showLocation(results[0]); + } else { + // multiple results found... add to results list and let user choose which one to show + this._setSuggestList(results); + } + }, + + _processReverseResults: function(result) { + if (!result) { + this._printError(this._config.notFoundMessage); + } + + this._map.fireEvent('geosearch_clicklocation', {Location: result}); + this._setResult(result); + }, + + _setResult: function(result) { + var displayName = null, + displayDescription = null, + divText = document.createElement('div'), + elem = this._result, + index = -1; + li = document.createElement('li'), + txtDescription = null, + txtName = null; + + if (result.lat == undefined || result.lon == undefined) { + return; + } + + this._clearResult(); + + index = result.displayName.indexOf(','); + displayName = result.displayName.substring(0, index); + displayDescription = result.displayName.substring(index + 1); + + li.id = 'geosearch-result'; + li.className = 'geosearch-result'; + txtDescription = document.createElement('span'); + txtDescription.className = 'result-description'; + txtDescription.innerHTML = displayDescription.replace(/^\s+|\s+$/g,''); + txtName = document.createElement('span'); + txtName.className = 'result-name'; + txtName.innerHTML = displayName.replace(/^\s+|\s+$/g,''); + divText.className = 'geosearch-result-text'; + divText.appendChild(txtName); + divText.appendChild(txtDescription); + li.appendChild(divText); + + elem.appendChild(li); + elem.style.display = 'block'; + + this._map.fireEvent('geosearch_showresult', {element: elem, queryPoint: L.latLng({lat: parseFloat(result.lat), lon: parseFloat(result.lon)})}); + }, _setSuggestList: function(results) { - var elem = this._suggestlist, - i = 0, - j = 0, - li = null, - liText = null, - r = null; - - this._clearSuggestList(); - - for (i = 0, j = 0; i < results.length; ++i) { - r = results[i]; - if (r.lat == undefined || r.lon == undefined) { - continue; - } - - if (this._isInSuggestSet(r)) { - continue; - } - - this._suggestSet[this._suggestSet.length] = r; - li = document.createElement('li'); - li.id = 'geosearch-suggest-' + j; - li.className = 'geosearch-suggest'; - liText = document.createTextNode(r.displayName); - li.appendChild(liText); - elem.appendChild(li); - L.DomEvent.addListener(li, 'click', this._onSuggestClick, this); - - ++j; - } - - elem.style.display = 'block'; - }, - - _showLocation: function (location) { - this._setResult(location); - this._clearSuggestList(); - - if (this.options.showMarker == true) { - if (typeof this._positionMarker === 'undefined') { - this._positionMarker = L.marker([location.lat, location.lon]).addTo(this._map); - } else { - this._positionMarker.setLatLng([location.lat, location.lon]); - } - } - - this._map.setView([location.lat, location.lon], this._config.zoomLevel, false); - this._map.fireEvent('geosearch_showlocation', {Location: location}); - }, - - _printError: function(message) { - var elem = this._result; - elem.innerHTML = '<li>' + message + '</li>'; - elem.style.display = 'block'; - - var self = this; - self._timeout = setTimeout(function () { - elem.style.display = 'none'; - self._timeout = null; - }, 3000); - } + var elem = this._suggestlist, + i = 0, + j = 0, + li = null, + liText = null, + r = null; + + this._clearSuggestList(); + + for (i = 0, j = 0; i < results.length; ++i) { + r = results[i]; + if (r.lat == undefined || r.lon == undefined) { + continue; + } + + if (this._isInSuggestSet(r)) { + continue; + } + + this._suggestSet[this._suggestSet.length] = r; + li = document.createElement('li'); + li.id = 'geosearch-suggest-' + j; + li.className = 'geosearch-suggest'; + liText = document.createTextNode(r.displayName); + li.appendChild(liText); + elem.appendChild(li); + L.DomEvent.addListener(li, 'click', this._onSuggestClick, this); + + ++j; + } + + elem.style.display = 'block'; + }, + + _showLocation: function (location) { + this._setResult(location); + this._clearSuggestList(); + + if (this.options.showMarker == true) { + if (typeof this._positionMarker === 'undefined') { + this._positionMarker = L.marker([location.lat, location.lon]).addTo(this._map); + } else { + this._positionMarker.setLatLng([location.lat, location.lon]); + } + } + + this._map.setView([location.lat, location.lon], this._config.zoomLevel, false); + this._map.fireEvent('geosearch_showlocation', {Location: location}); + }, + + _printError: function(message) { + var elem = this._result; + elem.innerHTML = '<li>' + message + '</li>'; + elem.style.display = 'block'; + + var self = this; + self._timeout = setTimeout(function () { + elem.style.display = 'none'; + self._timeout = null; + }, 3000); + } }); return L.Control.GeoSearch; -}); \ No newline at end of file +}); diff --git a/src/main/webapp/js/map/control/geosearchProvider/osm.js b/src/main/webapp/js/map/control/geosearchProvider/osm.js index 4edad207..74b1c423 100644 --- a/src/main/webapp/js/map/control/geosearchProvider/osm.js +++ b/src/main/webapp/js/map/control/geosearchProvider/osm.js @@ -5,93 +5,93 @@ */ define(['leaflet'], function(L) { ReverseResult = function (lon, lat, address, displayName) { - this.lon = lon; - this.lat = lat; - this.address = address; - this.displayName = displayName; + this.lon = lon; + this.lat = lat; + this.address = address; + this.displayName = displayName; }; Result = function (lon, lat, displayName) { - this.lon = lon; - this.lat = lat; - this.displayName = displayName; + this.lon = lon; + this.lat = lat; + this.displayName = displayName; }; OsmProvider = L.Class.extend({ - options : { - reverseable: true - }, - - initialize : function(options) { - options = L.Util.setOptions(this, options); - }, - - GetServiceUrl : function(qry, lon) { - if (!lon) { - // only one parameter given (query).. perform a forward lookup - return this._getForwardServiceUrl(qry); - } - - // second parameter set... perform a reverse lookup - return this._getReverseServiceUrl(qry, lon); - }, - - ParseJSON : function(data) { - if (data instanceof Array) { - return this._parseForwardJSON(data); - } - - return this._parseReverseJSON(data); - }, - - _getReverseServiceUrl : function(lat, lon) { - var parameters = L.Util.extend({ - lat: lat, - lon: lon, - format : 'json' - }, this.options); - - return 'http://nominatim.openstreetmap.org/reverse' - + L.Util.getParamString(parameters); - }, - - _getForwardServiceUrl: function(qry) { - var parameters = L.Util.extend({ - q : qry, - format : 'json' - }, this.options); - - return 'http://nominatim.openstreetmap.org/search' - + L.Util.getParamString(parameters); - }, - - _parseForwardJSON : function(data) { - if (data.length == 0) - return []; - - var results = []; - for (var i = 0; i < data.length; i++) - results.push(new Result( - data[i].lon, - data[i].lat, - data[i].display_name - )); - - return results; - }, - - _parseReverseJSON : function(data) { - if (data.length == 0) - return {}; - - return new ReverseResult( - data.lon, - data.lat, - data.address, - data.display_name - ); - } + options : { + reverseable: true + }, + + initialize : function(options) { + options = L.Util.setOptions(this, options); + }, + + GetServiceUrl : function(qry, lon) { + if (!lon) { + // only one parameter given (query).. perform a forward lookup + return this._getForwardServiceUrl(qry); + } + + // second parameter set... perform a reverse lookup + return this._getReverseServiceUrl(qry, lon); + }, + + ParseJSON : function(data) { + if (data instanceof Array) { + return this._parseForwardJSON(data); + } + + return this._parseReverseJSON(data); + }, + + _getReverseServiceUrl : function(lat, lon) { + var parameters = L.Util.extend({ + lat: lat, + lon: lon, + format : 'json' + }, this.options); + + return 'http://nominatim.openstreetmap.org/reverse' + L.Util.getParamString(parameters); + }, + + _getForwardServiceUrl: function(qry) { + var parameters = L.Util.extend({ + q : qry, + format : 'json' + }, this.options); + + return 'http://nominatim.openstreetmap.org/search' + L.Util.getParamString(parameters); + }, + + _parseForwardJSON : function(data) { + if (data.length === 0) { + return []; + } + + var results = []; + for (var i = 0; i < data.length; i++) + results.push(new Result( + data[i].lon, + data[i].lat, + data[i].display_name + )); + + return results; + }, + + _parseReverseJSON : function(data) { + if (data.length === 0) { + return {}; + } + + return new ReverseResult( + data.lon, + data.lat, + data.address, + data.display_name + ); + } }); return OsmProvider; -}); \ No newline at end of file +}); diff --git a/src/main/webapp/js/map/control/help.js b/src/main/webapp/js/map/control/help.js index e4274c14..7ad64bd8 100644 --- a/src/main/webapp/js/map/control/help.js +++ b/src/main/webapp/js/map/control/help.js @@ -1,24 +1,24 @@ define(['leaflet', 'console'], function(L, logger) { L.HelpControl = L.Control.extend({ - options: { - position: 'bottomright' - }, + options: { + position: 'bottomright' + }, - onAdd: function (map) { - this._container = L.DomUtil.create('div', 'help-control'); - this._container.id = 'help-control-div'; - this._container.className = 'help-control-div'; + onAdd: function (map) { + this._container = L.DomUtil.create('div', 'help-control'); + this._container.id = 'help-control-div'; + this._container.className = 'help-control-div'; - L.DomEvent.addListener(this._container, 'click', this._onOpen); - L.DomEvent.disableClickPropagation(this._container); + L.DomEvent.addListener(this._container, 'click', this._onOpen); + L.DomEvent.disableClickPropagation(this._container); - return this._container; - }, + return this._container; + }, - _onOpen: function() { - logger.log('Showing helper dialog'); - $('#help-dialog').dialog('open'); - } + _onOpen: function() { + logger.log('Showing helper dialog'); + $('#help-dialog').dialog('open'); + } }); return L.HelpControl; diff --git a/src/main/webapp/js/map/control/settings.js b/src/main/webapp/js/map/control/settings.js index ad6b413b..de082aac 100644 --- a/src/main/webapp/js/map/control/settings.js +++ b/src/main/webapp/js/map/control/settings.js @@ -1,24 +1,24 @@ define(['leaflet', 'console'], function(L, logger) { L.SettingsControl = L.Control.extend({ - options: { - position: 'bottomright' - }, + options: { + position: 'bottomright' + }, - onAdd: function (map) { - this._container = L.DomUtil.create('div', 'settings-control'); - this._container.id = 'settings-control-div'; - this._container.className = 'settings-control-div'; + onAdd: function (map) { + this._container = L.DomUtil.create('div', 'settings-control'); + this._container.id = 'settings-control-div'; + this._container.className = 'settings-control-div'; - L.DomEvent.addListener(this._container, 'click', this._onOpen); - L.DomEvent.disableClickPropagation(this._container); + L.DomEvent.addListener(this._container, 'click', this._onOpen); + L.DomEvent.disableClickPropagation(this._container); - return this._container; - }, + return this._container; + }, - _onOpen: function() { - logger.log('Showing settings'); - $('#settings-dialog').dialog('open'); - } + _onOpen: function() { + logger.log('Showing settings'); + $('#settings-dialog').dialog('open'); + } }); return L.SettingsControl; diff --git a/src/main/webapp/js/map/ipLocator/mapIncluder.js b/src/main/webapp/js/map/ipLocator/mapIncluder.js index 30442d13..2d66153c 100644 --- a/src/main/webapp/js/map/ipLocator/mapIncluder.js +++ b/src/main/webapp/js/map/ipLocator/mapIncluder.js @@ -43,7 +43,7 @@ define(['leaflet', 'map/ipLocator/ipProvider', 'map/ipLocator/ipLocator'], funct var onResponse = L.bind(this._handleGeolocationResponse, this), onError = L.bind(this._handleGeolocationError, this); - (new IpLocator).locateByIp(this._locateOptions.ipProvider, onResponse, onError); + (new IpLocator()).locateByIp(this._locateOptions.ipProvider, onResponse, onError); } }); }); \ No newline at end of file diff --git a/src/main/webapp/js/map/isoMap.js b/src/main/webapp/js/map/isoMap.js index 4ed2db09..cdb5fded 100644 --- a/src/main/webapp/js/map/isoMap.js +++ b/src/main/webapp/js/map/isoMap.js @@ -66,7 +66,7 @@ define(['jQuery', 'leaflet', 'console', 'map/layer/bing','map/layer/google', 'ma this.locateAndDraw = function() { var locator = new IpLocator(); - locator.locateByIp(mapOptions.ipProvider, onLocationSuccess.bind(this), onLocationError.bind(this)); + locator.locateByIp(mapOptions.ipProvider, onLocationSuccess.bind(this), onLocationError.bind(this)); }; // Private methods @@ -78,22 +78,22 @@ define(['jQuery', 'leaflet', 'console', 'map/layer/bing','map/layer/google', 'ma bRoad; bRoad = new BingLayer(apiKey, { - type: 'Road' - }); - bHybrid = new BingLayer(apiKey, { - type: 'AerialWithLabels' - }); - bAerial = new BingLayer(apiKey, { - type: 'Aerial' - }); - - logger.debug('Adding bing layers'); - - c.addBaseLayer(bRoad, 'Bing Road'); - c.addBaseLayer(bHybrid, 'Bing Hybrid'); - c.addBaseLayer(bAerial, 'Bing Aerial'); - - return bAerial; + type: 'Road' + }); + bHybrid = new BingLayer(apiKey, { + type: 'AerialWithLabels' + }); + bAerial = new BingLayer(apiKey, { + type: 'Aerial' + }); + + logger.debug('Adding bing layers'); + + c.addBaseLayer(bRoad, 'Bing Road'); + c.addBaseLayer(bHybrid, 'Bing Hybrid'); + c.addBaseLayer(bAerial, 'Bing Aerial'); + + return bAerial; } function addBlueMarbleLayers(c) { @@ -108,16 +108,16 @@ define(['jQuery', 'leaflet', 'console', 'map/layer/bing','map/layer/google', 'ma blueMarbleJpg = new L.tileLayer.wms( 'http://maps.opengeo.org/geowebcache/service/wms', {layers: 'bluemarble'} - ); + ); blueMarblePng = new L.tileLayer.wms( 'http://maps.opengeo.org/geowebcache/service/wms', {layers: 'bluemarble', format: 'image/png'} - ); + ); openGeoOSM = new L.tileLayer.wms( - 'http://maps.opengeo.org/geowebcache/service/wms', - {layers: 'openstreetmap', format: 'image/png'} + 'http://maps.opengeo.org/geowebcache/service/wms', + {layers: 'openstreetmap', format: 'image/png'} ); logger.debug('Adding openGeo layers (blueMarbel and openGeo OSM)'); @@ -135,25 +135,25 @@ define(['jQuery', 'leaflet', 'console', 'map/layer/bing','map/layer/google', 'ma gHybrid, gSatellite; - gPhysical = new GoogleLayer('TERRAIN'); - gStreet = new GoogleLayer('ROADMAP', - {maxZoom: 20 } - ); - gHybrid = new GoogleLayer('HYBRID', - {maxZoom: 20 } - ); - gSatellite = new GoogleLayer('SATELLITE', - {maxZoom: 22 } - ); - - logger.debug('Adding google layers'); - - c.addBaseLayer(gPhysical, 'Google Physical'); - c.addBaseLayer(gStreet, 'Google Streets'); - c.addBaseLayer(gHybrid, 'Google Hybrid'); - c.addBaseLayer(gSatellite, 'Google Satellite'); - - return gSatellite; + gPhysical = new GoogleLayer('TERRAIN'); + gStreet = new GoogleLayer('ROADMAP', + {maxZoom: 20 } + ); + gHybrid = new GoogleLayer('HYBRID', + {maxZoom: 20 } + ); + gSatellite = new GoogleLayer('SATELLITE', + {maxZoom: 22 } + ); + + logger.debug('Adding google layers'); + + c.addBaseLayer(gPhysical, 'Google Physical'); + c.addBaseLayer(gStreet, 'Google Streets'); + c.addBaseLayer(gHybrid, 'Google Hybrid'); + c.addBaseLayer(gSatellite, 'Google Satellite'); + + return gSatellite; } function addOsmLayer(c) { @@ -162,7 +162,7 @@ define(['jQuery', 'leaflet', 'console', 'map/layer/bing','map/layer/google', 'ma } var layerOsm = new L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { - attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' + attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' }); logger.debug('Adding openstreetmap layer'); @@ -192,17 +192,17 @@ define(['jQuery', 'leaflet', 'console', 'map/layer/bing','map/layer/google', 'ma } function onLocationSuccess(location) { - if (!location || !location.coords) { - logger.debug('Invalid geoLocation found... no coordinates returned!'); - return; - } + if (!location || !location.coords) { + logger.debug('Invalid geoLocation found... no coordinates returned!'); + return; + } - logger.log('GeoLocation found. It will be used as center'); - logger.debug(' - location:', location); + logger.log('GeoLocation found. It will be used as center'); + logger.debug(' - location:', location); - mapOptions.center = [location.coords.latitude, location.coords.longitude]; + mapOptions.center = [location.coords.latitude, location.coords.longitude]; - this.draw(); + this.draw(); } } diff --git a/src/main/webapp/js/map/layer/bing.js b/src/main/webapp/js/map/layer/bing.js index 6fac75b1..0efca45e 100644 --- a/src/main/webapp/js/map/layer/bing.js +++ b/src/main/webapp/js/map/layer/bing.js @@ -21,19 +21,19 @@ define(['leaflet', 'console'], function(L, logger) { for (var i = z; i > 0; i--) { var digit = 0; var mask = 1 << (i - 1); - if ((x & mask) != 0) digit += 1; - if ((y & mask) != 0) digit += 2; + if ((x & mask) !== 0) digit += 1; + if ((y & mask) !== 0) digit += 2; quad = quad + digit; } return quad; }, getTileUrl: function(p, z) { - var z = this._getZoomForUrl(); + var zoom = this._getZoomForUrl(); var subdomains = this.options.subdomains, s = this.options.subdomains[Math.abs((p.x + p.y) % subdomains.length)]; return this._url.replace('{subdomain}', s) - .replace('{quadkey}', this.tile2quad(p.x, p.y, z)) + .replace('{quadkey}', this.tile2quad(p.x, p.y, zoom)) .replace('{culture}', this.options.culture); }, @@ -52,7 +52,7 @@ define(['leaflet', 'console'], function(L, logger) { _this.initMetadata(); }; var url = document.location.protocol + "//dev.virtualearth.net/REST/v1/Imagery/Metadata/" + this.options.type + "?include=ImageryProviders&jsonp=" + cbid + - "&key=" + this._key + "&UriScheme=" + document.location.protocol.slice(0, -1); + "&key=" + this._key + "&UriScheme=" + document.location.protocol.slice(0, -1); var script = document.createElement("script"); script.type = "text/javascript"; script.src = url; @@ -85,7 +85,7 @@ define(['leaflet', 'console'], function(L, logger) { }, _update: function() { - if (this._url == null || !this._map) return; + if (this._url === null || !this._map) return; this._update_attribution(); L.TileLayer.prototype._update.apply(this, []); }, @@ -117,7 +117,7 @@ define(['leaflet', 'console'], function(L, logger) { } } - L.TileLayer.prototype.onRemove.apply(this, [map]); + L.TileLayer.prototype.onRemove.apply(this, [map]); } }); diff --git a/src/main/webapp/js/map/layer/google.js b/src/main/webapp/js/map/layer/google.js index 7b802b54..041ef379 100644 --- a/src/main/webapp/js/map/layer/google.js +++ b/src/main/webapp/js/map/layer/google.js @@ -24,7 +24,7 @@ define(['leaflet'], function(L) { initialize: function(type, options) { L.Util.setOptions(this, options); - this._ready = google.maps.Map != undefined; + this._ready = google.maps.Map !== undefined; if (!this._ready) L.Google.asyncWait.push(this); this._type = type || 'SATELLITE'; @@ -47,7 +47,7 @@ define(['leaflet'], function(L) { map.on('zoomanim', this._handleZoomAnim, this); //20px instead of 1em to avoid a slight overlap with google's attribution - map._controlCorners['bottomright'].style.marginBottom = "20px"; + map._controlCorners.bottomright.style.marginBottom = "20px"; this._reset(); this._update(); @@ -63,7 +63,7 @@ define(['leaflet'], function(L) { this._map.off('zoomanim', this._handleZoomAnim, this); - map._controlCorners['bottomright'].style.marginBottom = "0em"; + map._controlCorners.bottomright.style.marginBottom = "0em"; //this._map.off('moveend', this._update, this); }, @@ -103,18 +103,18 @@ define(['leaflet'], function(L) { if (!this._ready) return; this._google_center = new google.maps.LatLng(0, 0); var map = new google.maps.Map(this._container, { - center: this._google_center, - zoom: 0, - tilt: 0, - mapTypeId: google.maps.MapTypeId[this._type], - disableDefaultUI: true, - keyboardShortcuts: false, - draggable: false, - disableDoubleClickZoom: true, - scrollwheel: false, - streetViewControl: false, - styles: this.options.mapOptions.styles, - backgroundColor: this.options.mapOptions.backgroundColor + center: this._google_center, + zoom: 0, + tilt: 0, + mapTypeId: google.maps.MapTypeId[this._type], + disableDefaultUI: true, + keyboardShortcuts: false, + draggable: false, + disableDoubleClickZoom: true, + scrollwheel: false, + streetViewControl: false, + styles: this.options.mapOptions.styles, + backgroundColor: this.options.mapOptions.backgroundColor }); var _this = this; @@ -160,14 +160,14 @@ define(['leaflet'], function(L) { _resize: function() { var size = this._map.getSize(); - if (this._container.style.width == size.x && - this._container.style.height == size.y) + if (this._container.style.width == size.x && this._container.style.height == size.y) { return; + } + this.setElementSize(this._container, size); this.onReposition(); }, - _handleZoomAnim: function (e) { var center = e.center; var _center = new google.maps.LatLng(center.lat, center.lng); @@ -176,7 +176,6 @@ define(['leaflet'], function(L) { this._google.setZoom(e.zoom); }, - onReposition: function() { if (!this._google) return; google.maps.event.trigger(this._google, "resize"); diff --git a/src/main/webapp/js/service/serviceConfiguration.js b/src/main/webapp/js/service/serviceConfiguration.js index ba0d19f2..00ae341f 100644 --- a/src/main/webapp/js/service/serviceConfiguration.js +++ b/src/main/webapp/js/service/serviceConfiguration.js @@ -72,7 +72,7 @@ define(['jQuery', 'leaflet', 'console', 'isochrone/configuration'], function($, var earthRadius = 6378137; return L.Projection.SphericalMercator.unproject(point.divideBy(earthRadius)); }; - }; + } return ServiceConfiguration; }); diff --git a/src/main/webapp/js/service/websocket.js b/src/main/webapp/js/service/websocket.js index cf93427d..4ae17df2 100644 --- a/src/main/webapp/js/service/websocket.js +++ b/src/main/webapp/js/service/websocket.js @@ -1,6 +1,13 @@ define(['jQuery', 'console'], function($, logger) { + var wsUri = 'ws://localhost:8090/isochrone/websocket'; + + /** + * This class is used to communicate with the server + */ function Websocket() { - var wsUri = "ws://localhost:8090/isochrone/websocket"; + /** + * The websocket object that holds the connection and to which the callback listeners are applied + */ var websocket = null; // Constructor @@ -11,13 +18,18 @@ define(['jQuery', 'console'], function($, logger) { websocket.onmessage = function(evt) { onMessage(evt); }; websocket.onerror = function(evt) { onError(evt); }; - // Public methods + // Public methods + /** + * Sends the specified message to the server + * + * @param msg {String} message to send + */ this.sendWsMessage = function(msg) { if (websocket.readyState === websocket.OPEN) { - websocket.send(msg); + websocket.send(msg); } else if (websocket.readyState === websocket.CONNECTING) { - setTimeout(this.sendWsMessage.bind(this, msg), 100); + setTimeout(this.sendWsMessage.bind(this, msg), 100); } else { logger.error("Could not send message using websocket: socket closed (or closing)"); } @@ -51,7 +63,7 @@ define(['jQuery', 'console'], function($, logger) { logger.error('Could not get data from configuration websocket'); logger.warn('Error data: ' + evt.data); }; - }; + } return Websocket; }); -- GitLab