From 82e9e60cd5f1bbd5879909e34bd823d6cd4ade9b Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Fri, 6 Nov 2015 12:51:52 +1100 Subject: [PATCH] Function without OpenLayers Signed-off-by: Madhura Jayaratne --- js/OpenStreetMap.js | 233 ++++++++++++++++++------------------ js/tbl_gis_visualization.js | 10 +- 2 files changed, 124 insertions(+), 119 deletions(-) diff --git a/js/OpenStreetMap.js b/js/OpenStreetMap.js index 51694bc86c..0383755b06 100644 --- a/js/OpenStreetMap.js +++ b/js/OpenStreetMap.js @@ -1,126 +1,129 @@ /* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * Namespace: Util.OSM - */ -OpenLayers.Util.OSM = {}; -/** - * Constant: MISSING_TILE_URL - * {String} URL of image to display for missing tiles - */ -OpenLayers.Util.OSM.MISSING_TILE_URL = "http://www.openstreetmap.org/openlayers/img/404.png"; - -/** - * Property: originalOnImageLoadError - * {Function} Original onImageLoadError function. - */ -OpenLayers.Util.OSM.originalOnImageLoadError = OpenLayers.Util.onImageLoadError; - -/** - * Function: onImageLoadError - */ -OpenLayers.Util.onImageLoadError = function () { - if (this.src.match(/^http:\/\/[abc]\.[a-z]+\.openstreetmap\.org\//)) { - this.src = OpenLayers.Util.OSM.MISSING_TILE_URL; - } else if (this.src.match(/^http:\/\/[def]\.tah\.openstreetmap\.org\//)) { - // do nothing - this layer is transparent - } else { - OpenLayers.Util.OSM.originalOnImageLoadError; - } -}; - -/** - * Class: OpenLayers.Layer.OSM.Mapnik - * - * Inherits from: - * - - */ -OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, { +if (typeof OpenLayers !== 'undefined') { /** - * Constructor: OpenLayers.Layer.OSM.Mapnik - * - * Parameters: - * name - {String} - * options - {Object} Hashtable of extra options to tag onto the layer + * Namespace: Util.OSM */ - initialize: function (name, options) { - var url = [ - "http://a.tile.openstreetmap.org/${z}/${x}/${y}.png", - "http://b.tile.openstreetmap.org/${z}/${x}/${y}.png", - "http://c.tile.openstreetmap.org/${z}/${x}/${y}.png" - ]; - options = OpenLayers.Util.extend({ - numZoomLevels: 19, - buffer: 0, - transitionEffect: "resize" - }, options); - var newArguments = [name, url, options]; - OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments); - }, + OpenLayers.Util.OSM = {}; - CLASS_NAME: "OpenLayers.Layer.OSM.Mapnik" -}); - -/** - * Class: OpenLayers.Layer.OSM.Osmarender - * - * Inherits from: - * - - */ -OpenLayers.Layer.OSM.Osmarender = OpenLayers.Class(OpenLayers.Layer.OSM, { /** - * Constructor: OpenLayers.Layer.OSM.Osmarender - * - * Parameters: - * name - {String} - * options - {Object} Hashtable of extra options to tag onto the layer + * Constant: MISSING_TILE_URL + * {String} URL of image to display for missing tiles */ - initialize: function (name, options) { - var url = [ - "http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png", - "http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png", - "http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png" - ]; - options = OpenLayers.Util.extend({ - numZoomLevels: 18, - buffer: 0, - transitionEffect: "resize" - }, options); - var newArguments = [name, url, options]; - OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments); - }, + OpenLayers.Util.OSM.MISSING_TILE_URL = "http://www.openstreetmap.org/openlayers/img/404.png"; - CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender" -}); - -/** - * Class: OpenLayers.Layer.OSM.CycleMap - * - * Inherits from: - * - - */ -OpenLayers.Layer.OSM.CycleMap = OpenLayers.Class(OpenLayers.Layer.OSM, { /** - * Constructor: OpenLayers.Layer.OSM.CycleMap - * - * Parameters: - * name - {String} - * options - {Object} Hashtable of extra options to tag onto the layer + * Property: originalOnImageLoadError + * {Function} Original onImageLoadError function. */ - initialize: function (name, options) { - var url = [ - "http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png", - "http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png", - "http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png" - ]; - options = OpenLayers.Util.extend({ - numZoomLevels: 19, - buffer: 0, - transitionEffect: "resize" - }, options); - var newArguments = [name, url, options]; - OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments); - }, + OpenLayers.Util.OSM.originalOnImageLoadError = OpenLayers.Util.onImageLoadError; - CLASS_NAME: "OpenLayers.Layer.OSM.CycleMap" -}); + /** + * Function: onImageLoadError + */ + OpenLayers.Util.onImageLoadError = function () { + if (this.src.match(/^http:\/\/[abc]\.[a-z]+\.openstreetmap\.org\//)) { + this.src = OpenLayers.Util.OSM.MISSING_TILE_URL; + } else if (this.src.match(/^http:\/\/[def]\.tah\.openstreetmap\.org\//)) { + // do nothing - this layer is transparent + } else { + OpenLayers.Util.OSM.originalOnImageLoadError; + } + }; + + /** + * Class: OpenLayers.Layer.OSM.Mapnik + * + * Inherits from: + * - + */ + OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, { + /** + * Constructor: OpenLayers.Layer.OSM.Mapnik + * + * Parameters: + * name - {String} + * options - {Object} Hashtable of extra options to tag onto the layer + */ + initialize: function (name, options) { + var url = [ + "http://a.tile.openstreetmap.org/${z}/${x}/${y}.png", + "http://b.tile.openstreetmap.org/${z}/${x}/${y}.png", + "http://c.tile.openstreetmap.org/${z}/${x}/${y}.png" + ]; + options = OpenLayers.Util.extend({ + numZoomLevels: 19, + buffer: 0, + transitionEffect: "resize" + }, options); + var newArguments = [name, url, options]; + OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments); + }, + + CLASS_NAME: "OpenLayers.Layer.OSM.Mapnik" + }); + + /** + * Class: OpenLayers.Layer.OSM.Osmarender + * + * Inherits from: + * - + */ + OpenLayers.Layer.OSM.Osmarender = OpenLayers.Class(OpenLayers.Layer.OSM, { + /** + * Constructor: OpenLayers.Layer.OSM.Osmarender + * + * Parameters: + * name - {String} + * options - {Object} Hashtable of extra options to tag onto the layer + */ + initialize: function (name, options) { + var url = [ + "http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png", + "http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png", + "http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png" + ]; + options = OpenLayers.Util.extend({ + numZoomLevels: 18, + buffer: 0, + transitionEffect: "resize" + }, options); + var newArguments = [name, url, options]; + OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments); + }, + + CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender" + }); + + /** + * Class: OpenLayers.Layer.OSM.CycleMap + * + * Inherits from: + * - + */ + OpenLayers.Layer.OSM.CycleMap = OpenLayers.Class(OpenLayers.Layer.OSM, { + /** + * Constructor: OpenLayers.Layer.OSM.CycleMap + * + * Parameters: + * name - {String} + * options - {Object} Hashtable of extra options to tag onto the layer + */ + initialize: function (name, options) { + var url = [ + "http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png", + "http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png", + "http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png" + ]; + options = OpenLayers.Util.extend({ + numZoomLevels: 19, + buffer: 0, + transitionEffect: "resize" + }, options); + var newArguments = [name, url, options]; + OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments); + }, + + CLASS_NAME: "OpenLayers.Layer.OSM.CycleMap" + }); +} \ No newline at end of file diff --git a/js/tbl_gis_visualization.js b/js/tbl_gis_visualization.js index 6a71a946b2..e76aaa8801 100644 --- a/js/tbl_gis_visualization.js +++ b/js/tbl_gis_visualization.js @@ -148,10 +148,12 @@ function initGISVisualization() { selectVisualization(); // Resizes the GIS visualization to fit into the space available resizeGISVisualization(); - // Adds necessary styles to the div that coontains the openStreetMap - styleOSM(); - // Draws openStreetMap with openLayers - drawOpenLayers(); + if (typeof OpenLayers !== 'undefined') { + // Adds necessary styles to the div that coontains the openStreetMap + styleOSM(); + // Draws openStreetMap with openLayers + drawOpenLayers(); + } // Loads the SVG element and make a reference to it loadSVG(); // Adds controllers for zooming and panning