From 721967745b88f87c40326c52a3e21693489fc418 Mon Sep 17 00:00:00 2001 From: Jim Klassen Date: Fri, 21 Sep 2012 19:41:15 -0500 Subject: [PATCH 1/2] Allow adding map-sources after initialization --- htdocs/geomoose/GeoMOOSE/Application.js | 83 +++++++++++++++++-------------- 1 files changed, 46 insertions(+), 37 deletions(-) diff --git a/htdocs/geomoose/GeoMOOSE/Application.js b/htdocs/geomoose/GeoMOOSE/Application.js index 10b29a8..68ccc3d 100644 --- a/htdocs/geomoose/GeoMOOSE/Application.js +++ b/htdocs/geomoose/GeoMOOSE/Application.js @@ -354,6 +354,51 @@ dojo.declare('GeoMOOSE.Application', null, { }, + /** Method: configureMapSource + * Parses a map-source XML fragment and creates necessary GM and OL classes + * + * Parameters + * map_source_xml - The xml node + */ + configureMapSource: function(map_source_xml, override_list) { + var map_source_class = GeoMOOSE.getMapSourceType(map_source_xml.getAttribute('type')); + var name = map_source_xml.getAttribute('name'); + + /* pre-process the map-source's layer params with the override list */ + var layers = map_source_xml.getElementsByTagName('layer'); + for(var l = 0, ll = layers.length; l < ll; l++) { + var layer = layers[l]; + /* copy the old status to the new. */ + var layer_status = layer.getAttribute('status'); + if(!GeoMOOSE.isDefined(layer_status)) { + layer_status = 'off'; + /* Lazy complete the XML definition for the user */ + layer.setAttribute('status', 'off'); + } + layer.setAttribute('_status', layer_status); + + /* check to see if we've turned this on or off... */ + var layer_name = layer.getAttribute('name'); + var path = name+'/'+layer_name; + if(GeoMOOSE.isDefined(override_list[path])) { + layer.setAttribute('status', override_list[path]); + } + } + + if(typeof(map_source_class) == 'undefined') { + GeoMOOSE.warning('Undefined Layer Type : ' + map_source_xml.getAttribute('type')); + } else { + /* warn the user they did something wrong */ + if(this.mapSources[name]) { + GeoMOOSE.warning('map-source "'+name+'" is being redefined!.'); + } + /* but do it anyway */ + this.mapSources[name] = new map_source_class(map_source_xml); + this.mapSources[name].addToMap(Map); + dojo.connect(this.mapSources[name], 'onLayersChange', this.onLayersChange); + } + }, + /** * Method: configureMapSources * Creates real classes for all of the MapSources. @@ -369,7 +414,6 @@ dojo.declare('GeoMOOSE.Application', null, { var override_list = {}; var args = GeoMOOSE.getUrlParameters(); - var overrideStatusList = {}; if(args.on) { var on_list = new String(args.on).split(';'); for(var i = 0, ii = on_list.length; i < ii; i++) { @@ -388,42 +432,7 @@ dojo.declare('GeoMOOSE.Application', null, { var map_sources = response.getElementsByTagName('map-source'); for(var i = map_sources.length - 1; i >= 0; i--) { var map_source_xml = map_sources[i]; - var map_source_class = GeoMOOSE.getMapSourceType(map_source_xml.getAttribute('type')); - var name = map_source_xml.getAttribute('name'); - - /* pre-process the map-source's layer params with the override list */ - var layers = map_source_xml.getElementsByTagName('layer'); - for(var l = 0, ll = layers.length; l < ll; l++) { - var layer = layers[l]; - /* copy the old status to the new. */ - var layer_status = layer.getAttribute('status'); - if(!GeoMOOSE.isDefined(layer_status)) { - layer_status = 'off'; - /* Lazy complete the XML definition for the user */ - layer.setAttribute('status', 'off'); - } - layer.setAttribute('_status', layer_status); - - /* check to see if we've turned this on or off... */ - var layer_name = layer.getAttribute('name'); - var path = name+'/'+layer_name; - if(GeoMOOSE.isDefined(override_list[path])) { - layer.setAttribute('status', override_list[path]); - } - } - - if(typeof(map_source_class) == 'undefined') { - GeoMOOSE.warning('Undefined Layer Type : ' + map_source_xml.getAttribute('type')); - } else { - /* warn the user they did something wrong */ - if(this.mapSources[name]) { - GeoMOOSE.warning('map-source "'+name+'" is being redefined!.'); - } - /* but do it anyway */ - this.mapSources[name] = new map_source_class(map_source_xml); - this.mapSources[name].addToMap(Map); - dojo.connect(this.mapSources[name], 'onLayersChange', this.onLayersChange); - } + this.configureMapSource( map_source_xml, override_list ); if(parseBoolean(map_source_xml.getAttribute('active'), false)) { active_map_source = name; -- 1.7.2.5 From 8cb47c0ce8daa4de5d32c8466a18a324d745f20c Mon Sep 17 00:00:00 2001 From: Jim Klassen Date: Mon, 24 Sep 2012 12:18:45 -0500 Subject: [PATCH 2/2] Create public API for configureMapSource. --- htdocs/geomoose/geomoose.js | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/htdocs/geomoose/geomoose.js b/htdocs/geomoose/geomoose.js index 9d74a57..1a58afe 100644 --- a/htdocs/geomoose/geomoose.js +++ b/htdocs/geomoose/geomoose.js @@ -109,6 +109,17 @@ window.GeoMOOSE = { return layer_list; }, + /** Method: configureMapSource + * Parses a map-source XML fragment and adds it to the map. + * Important: this does not add anything to the catalog! + * + * Parameters + * map_source_xml - The xml node + */ + configureMapSource: function( map_source_xml ) { + Application.configureMapSource( map_source_xml, {} ); + }, + /** * Method: changeLayerVisibility * Turn a layer on or off. -- 1.7.2.5