[fusion-commits] r2044 - in sandbox/jxlib-3.0: layers/MapGuide
layers/MapServer lib widgets
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Tue Jan 26 15:35:46 EST 2010
Author: madair
Date: 2010-01-26 15:35:43 -0500 (Tue, 26 Jan 2010)
New Revision: 2044
Modified:
sandbox/jxlib-3.0/layers/MapGuide/MapGuide.js
sandbox/jxlib-3.0/layers/MapServer/MapServer.js
sandbox/jxlib-3.0/lib/Map.js
sandbox/jxlib-3.0/widgets/LayerManager.js
sandbox/jxlib-3.0/widgets/Legend.js
Log:
trigger an event after LoadScaleRanges so multiple widgets can listen for it
Modified: sandbox/jxlib-3.0/layers/MapGuide/MapGuide.js
===================================================================
--- sandbox/jxlib-3.0/layers/MapGuide/MapGuide.js 2010-01-25 16:34:33 UTC (rev 2043)
+++ sandbox/jxlib-3.0/layers/MapGuide/MapGuide.js 2010-01-26 20:35:43 UTC (rev 2044)
@@ -380,39 +380,34 @@
* used by the legend widget.
*/
- loadScaleRanges: function(userFunc) {
+ loadScaleRanges: function() {
var sl = Fusion.getScriptLanguage();
var loadmapScript = 'layers/' + this.arch + '/' + sl + '/LoadScaleRanges.' + sl;
var sessionid = this.getSessionID();
var params = {'mapname': this._sMapname, "session": sessionid};
- var options = {onSuccess: OpenLayers.Function.bind(this.scaleRangesLoaded,this, userFunc),
+ var options = {onSuccess: OpenLayers.Function.bind(this.scaleRangesLoaded,this),
parameters:params};
Fusion.ajaxRequest(loadmapScript, options);
},
- scaleRangesLoaded: function(userFunc, r)
+ scaleRangesLoaded: function(r)
{
- if (r.status == 200)
- {
+ if (r.status == 200) {
var o;
eval('o='+r.responseText);
- if (o.layers && o.layers.length > 0)
- {
+ if (o.layers && o.layers.length > 0) {
var iconOpt = {
url: o.icons_url || null,
width: o.icons_width || 16,
height: o.icons_height || 16
};
- for (var i=0; i<o.layers.length; i++)
- {
+ for (var i=0; i<o.layers.length; i++) {
var oLayer = this.getLayerById(o.layers[i].uniqueId);
- if (oLayer)
- {
+ if (oLayer) {
oLayer.scaleRanges = [];
- for (var j=0; j<o.layers[i].scaleRanges.length; j++)
- {
+ for (var j=0; j<o.layers[i].scaleRanges.length; j++) {
var scaleRange = new Fusion.Layers.ScaleRange(o.layers[i].scaleRanges[j],
oLayer.layerType, iconOpt);
oLayer.scaleRanges.push(scaleRange);
@@ -420,10 +415,10 @@
}
}
}
-
- userFunc();
+ this.mapWidget.triggerEvent(Fusion.Event.MAP_SCALE_RANGE_LOADED);
}
},
+
//TBD: this function not yet converted for OL
mapReloaded: function(r) {
if (r.status == 200) {
Modified: sandbox/jxlib-3.0/layers/MapServer/MapServer.js
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/MapServer.js 2010-01-25 16:34:33 UTC (rev 2043)
+++ sandbox/jxlib-3.0/layers/MapServer/MapServer.js 2010-01-26 20:35:43 UTC (rev 2044)
@@ -323,19 +323,19 @@
* used by the legend widget.
*/
- loadScaleRanges: function(userFunc) {
+ loadScaleRanges: function() {
var sl = Fusion.getScriptLanguage();
var loadmapScript = 'layers/' + this.arch + '/' + sl + '/LoadScaleRanges.' + sl;
var sessionid = this.getSessionID();
var params = {'mapname': this._sMapname, "session": this.getSessionID()};
- var options = {onSuccess: OpenLayers.Function.bind(this.scaleRangesLoaded,this, userFunc),
+ var options = {onSuccess: OpenLayers.Function.bind(this.scaleRangesLoaded, this),
parameters:params};
Fusion.ajaxRequest(loadmapScript, options);
},
- scaleRangesLoaded: function(userFunc, r) {
+ scaleRangesLoaded: function(r) {
if (r.status == 200) {
var o;
eval('o='+r.responseText);
@@ -358,8 +358,7 @@
}
}
}
-
- userFunc();
+ this.mapWidget.triggerEvent(Fusion.Event.MAP_SCALE_RANGE_LOADED);
}
},
@@ -410,13 +409,14 @@
var nLayers = layerCopy.length -1;
//Mapserver has list of layers reversed from MapGuide
- aLayerIndex.reverse();
+ //aLayerIndex.reverse();
this.aLayers = [];
this.aVisibleLayers = [];
for (var i=0; i<aLayerIndex.length; ++i) {
- this.aLayers.push( layerCopy[ nLayers - aLayerIndex[i] ] );
+ //this.aLayers.push( layerCopy[ nLayers - aLayerIndex[i] ] );
+ this.aLayers.push( layerCopy[ aLayerIndex[i] ] );
if (this.aLayers[i].visible) {
this.aVisibleLayers.push(this.aLayers[i].layerName);
}
@@ -819,7 +819,7 @@
return oLayer;
},
- getLegendImageURL: function(fScale, layer, style,defaultIcon) {
+ getLegendImageURL: function(fScale, layer, style) {
var sl = Fusion.getScriptLanguage();
var url = Fusion.getFusionURL() + '/layers/' + this.arch + '/' + sl + '/LegendIcon.' + sl;
var sessionid = this.getSessionID();
Modified: sandbox/jxlib-3.0/lib/Map.js
===================================================================
--- sandbox/jxlib-3.0/lib/Map.js 2010-01-25 16:34:33 UTC (rev 2043)
+++ sandbox/jxlib-3.0/lib/Map.js 2010-01-26 20:35:43 UTC (rev 2044)
@@ -42,6 +42,7 @@
Fusion.Event.MAP_SESSION_CREATED = Fusion.Event.lastEventId++;
Fusion.Event.MAP_MAPTIP_REQ_FINISHED = Fusion.Event.lastEventId++;
Fusion.Event.WMS_LAYER_ADDED = Fusion.Event.lastEventId++;
+Fusion.Event.MAP_SCALE_RANGE_LOADED = Fusion.Event.lastEventId++;
Fusion.Constant.LAYER_POINT_TYPE = 0;
Fusion.Constant.LAYER_LINE_TYPE = 1;
@@ -169,6 +170,7 @@
this.registerEventID(Fusion.Event.MAP_SELECTION_OFF);
this.registerEventID(Fusion.Event.MAP_MAPTIP_REQ_FINISHED);
this.registerEventID(Fusion.Event.WMS_LAYER_ADDED);
+ this.registerEventID(Fusion.Event.MAP_SCALE_RANGE_LOADED);
this.registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.mapLoaded,this));
@@ -189,6 +191,7 @@
mapLoaded: function() {
this.setViewOptions(this.getUnits());
+ this.loadScaleRanges(OpenLayers.Function.bind(this.scaleRangesLoaded, this));
},
setMenu: function() {
@@ -394,10 +397,10 @@
}
},
- loadScaleRanges: function(userFunc) {
+ loadScaleRanges: function() {
for (var i=0; i<this.aMaps.length; ++i) {
var map = this.aMaps[i];
- OpenLayers.Function.bind(map.loadScaleRanges(userFunc), map);
+ map.loadScaleRanges();
}
},
Modified: sandbox/jxlib-3.0/widgets/LayerManager.js
===================================================================
--- sandbox/jxlib-3.0/widgets/LayerManager.js 2010-01-25 16:34:33 UTC (rev 2043)
+++ sandbox/jxlib-3.0/widgets/LayerManager.js 2010-01-26 20:35:43 UTC (rev 2044)
@@ -58,6 +58,7 @@
//console.log("initializeWidget");
var json = widgetTag.extension;
this.delIconSrc = json.DeleteIcon ? json.DeleteIcon[0] : 'images/icons/select-delete.png';
+ this.infoIconSrc = json.LayerInfoIcon ? json.LayerInfoIcon[0] : 'images/icons/tree_layer_info.png';
Fusion.addWidgetStyleSheet(widgetTag.location + 'LayerManager/LayerManager.css');
this.cursorNormal = ["url('images/grab.cur'),move", 'grab', '-moz-grab', 'move'];
@@ -65,19 +66,27 @@
this.map = this.getMap();
this.map.registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.mapLoaded, this));
this.map.registerForEvent(Fusion.Event.MAP_RELOADED, OpenLayers.Function.bind(this.mapReLoaded, this));
+ this.map.registerForEvent(Fusion.Event.MAP_SCALE_RANGE_LOADED, OpenLayers.Function.bind(this.scaleRangeLoaded, this));
// update changes to the legend in this widget
this.map.aMaps[0].registerForEvent(Fusion.Event.LAYER_PROPERTY_CHANGED, OpenLayers.Function.bind(this.layerChanged,this));
},
- mapLoaded: function() {
+ scaleRangeLoaded: function() {
this.draw();
},
+
+ mapLoaded: function() {
+ //this.draw();
+ },
+
layerChanged: function() {
this.updateSessionMapFile();
},
+
mapReLoaded: function(){
this.draw();
},
+
/**
* remove the dom objects representing the legend layers and groups
*/
@@ -136,10 +145,10 @@
processMapBlock: function(blockDom, map) {
//console.log("processMapBlock");
- var mapBlockList = document.createElement('ul');
- mapBlockList.className = 'jxLmanSet';
- mapBlockList.id = 'fusionLayerManager_'+map.getMapName();
- blockDom.appendChild(mapBlockList);
+ this.mapBlockList = document.createElement('ul');
+ this.mapBlockList.className = 'jxLmanSet';
+ this.mapBlockList.id = 'fusionLayerManager_'+map.getMapName();
+ blockDom.appendChild(this.mapBlockList);
map.layerPrefix = 'layer_'; //TODO make this unique for each block
//this process all layers within an OL layer
var processArray = map.aLayers;
@@ -148,7 +157,7 @@
var blockItem = document.createElement('li');
blockItem.className = 'jxLmanLayer';
blockItem.id = map.layerPrefix+i;
- mapBlockList.appendChild(blockItem);
+ this.mapBlockList.appendChild(blockItem);
this.createItemHtml(blockItem, processArray[i]);
blockItem.layer = processArray[i];
}
@@ -157,12 +166,18 @@
constrain: true,
clone: false,
revert: true,
- onComplete: OpenLayers.Function.bind(this.updateLayer, $(mapBlockList.id), map)
+ onComplete: OpenLayers.Function.bind(this.updateLayer, this, map)
};
- var mySortables = new Sortables(mapBlockList.id, sortableOptions);
+ var mySortables = new Sortables(this.mapBlockList.id, sortableOptions);
},
createItemHtml: function(parent, layer) {
+ var infoIcon = document.createElement('img');
+ infoIcon.src = this.infoIconSrc;
+ OpenLayers.Event.observe(infoIcon, 'click', OpenLayers.Function.bind(this.showLayerInfo, this, layer));
+ infoIcon.style.visibility = 'hidden';
+ parent.appendChild(infoIcon);
+
var delIcon = document.createElement('img');
delIcon.src = this.delIconSrc;
OpenLayers.Event.observe(delIcon, 'click', OpenLayers.Function.bind(this.deleteLayer, this, layer));
@@ -179,6 +194,23 @@
visSelect.checked = false;
}
+ var img = document.createElement('img');
+ var scale = layer.oMap.getScale();
+ var range = layer.getScaleRange(scale);
+ if (range && range.styles.length>0) {
+ var style = range.styles[0];//TODO: handle multiple styles?
+ var iconX = 0;
+ var iconY = 0;
+ if (style && style.iconX >= 0 && style.iconY >= 0) {
+ iconX = -1 * (style.iconX);
+ iconY = -1 * (style.iconY);
+ }
+ img.src = Jx.aPixel.src;
+ img.style.backgroundImage = 'url('+style.iconOpt.url+')';
+ img.style.backgroundPosition = iconX + 'px ' + iconY + 'px';
+ parent.appendChild(img);
+ }
+
var label = document.createElement('a');
label.innerHTML = layer.legendLabel;
OpenLayers.Event.observe(label, 'mouseover', OpenLayers.Function.bind(this.setGrabCursor, this));
@@ -186,16 +218,18 @@
OpenLayers.Event.observe(label, 'mouseout', OpenLayers.Function.bind(this.setNormalCursor, this));
parent.appendChild(label);
- OpenLayers.Event.observe(parent, 'mouseover', OpenLayers.Function.bind(this.setHandleVis, this, delIcon));
- OpenLayers.Event.observe(parent, 'mouseout', OpenLayers.Function.bind(this.setHandleHide, this, delIcon));
+ OpenLayers.Event.observe(parent, 'mouseover', OpenLayers.Function.bind(this.setHandleVis, this, delIcon, infoIcon));
+ OpenLayers.Event.observe(parent, 'mouseout', OpenLayers.Function.bind(this.setHandleHide, this, delIcon, infoIcon));
},
- setHandleVis: function(delIcon) {
+ setHandleVis: function(delIcon, infoIcon) {
delIcon.style.visibility = 'visible';
+ infoIcon.style.visibility = 'visible';
},
- setHandleHide: function(delIcon) {
+ setHandleHide: function(delIcon, infoIcon) {
delIcon.style.visibility = 'hidden';
+ infoIcon.style.visibility = 'hidden';
},
setGrabCursor: function(ev) {
@@ -210,7 +244,7 @@
this.setCursor('auto', ev.currentTarget.parentNode);
},
- setCursor : function(cursor, domObj) {
+ setCursor: function(cursor, domObj) {
this.cursor = cursor;
if (cursor && cursor.length && typeof cursor == 'object') {
for (var i = 0; i < cursor.length; i++) {
@@ -231,23 +265,38 @@
//reorder the layers in the client as well as the session
var aLayerIndex = [];
var aIds = [];
- var nLayers = this.childNodes.length;
+ var nLayers = this.mapBlockList.childNodes.length;
for (var i=0; i<nLayers; ++i) {
- aIds[i] = this.childNodes[i].id.split('_');
+ aIds[i] = this.mapBlockList.childNodes[i].id.split('_');
var index = parseInt(aIds[i].pop());
aLayerIndex.push(index);
- this.childNodes[i].id = '';
+ this.mapBlockList.childNodes[i].id = '';
}
//reset the ID's on the LI elements to be in order
- for (var i=0; i<this.childNodes.length; ++i) {
- var node = this.childNodes[i];
+ for (var i=0; i<this.mapBlockList.childNodes.length; ++i) {
+ var node = this.mapBlockList.childNodes[i];
aIds[i].push(i);
node.id = aIds[i].join('_');
node.childNodes[1].checked = node.layer.isVisible()
}
+
+ //check tos ee if the layer indexes have been modified
+ var indexModified = false;
+ if (aLayerIndex.length == map.aLayers.length) {
+ for (var i=0; i<aLayerIndex.length; ++i) {
+ if (aLayerIndex[i] != i) {
+ indexModified = true;
+ break;
+ }
+ }
+ } else {
+ indexModified = true;
+ }
- map.reorderLayers(aLayerIndex);
+ if (indexModified) {
+ map.reorderLayers(aLayerIndex);
+ }
},
updateMapBlock: function(map, ul) {
@@ -262,6 +311,13 @@
this.updateLayer(layer.oMap, ul);
},
+ showLayerInfo: function(layer, ev) {
+ var layerInfoUrl = layer.oMap.getLayerInfoUrl(layer.layerName);
+ if (layerInfoUrl) {
+ window.open(layerInfoUrl);
+ }
+ },
+
visChanged: function(layer2, ev) {
var target = (new Event(ev)).target;
var layer = target.parentNode.layer;
Modified: sandbox/jxlib-3.0/widgets/Legend.js
===================================================================
--- sandbox/jxlib-3.0/widgets/Legend.js 2010-01-25 16:34:33 UTC (rev 2043)
+++ sandbox/jxlib-3.0/widgets/Legend.js 2010-01-26 20:35:43 UTC (rev 2044)
@@ -110,6 +110,9 @@
if (this.renderer.mapLoaded)
this.getMap().registerForEvent(Fusion.Event.MAP_LOADED,
OpenLayers.Function.bind(this.renderer.mapLoaded, this.renderer));
+ if (this.renderer.scaleRangesLoaded)
+ this.getMap().registerForEvent(Fusion.Event.MAP_SCALE_RANGE_LOADED,
+ OpenLayers.Function.bind(this.renderer.scaleRangesLoaded, this.renderer));
}
});
@@ -355,6 +358,7 @@
this.layerRoot = this.getMap().layerRoot;
this.renderLegend();
},
+
mapLoading: function() {
this.getMap().deregisterForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, this.extentsChangedWatcher);
this.clear();
@@ -362,12 +366,11 @@
mapLoaded: function() {
this.getMap().registerForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, this.extentsChangedWatcher);
- this.getMap().loadScaleRanges(OpenLayers.Function.bind(this.scaleRangesLoaded, this));
},
mapReloaded: function() {
- this.getMap().loadScaleRanges(OpenLayers.Function.bind(this.scaleRangesLoaded, this));
},
+
/**
* the map state has become invalid in some way (layer added, removed,
* ect). For now, we just re-request the map state from the server
More information about the fusion-commits
mailing list