OverviewMap.js
Summary
No overview generated for 'OverviewMap.js'
mapbuilder.loadScript(baseDir+"/util/openlayers/OpenLayers.js");
mapbuilder.loadScript(baseDir+"/widget/WidgetBase.js");
function OverviewMap(widgetNode, model) {
WidgetBase.apply(this,new Array(widgetNode, model));
var width = this.getProperty("mb:width");
if (width) {
this.width = new Number(width);
}
var height = this.getProperty("mb:height");
if (height) {
this.height = new Number(height);
}
var minRatio = this.getProperty("mb:minRatio");
if (minRatio) {
this.minRatio = new Number(minRatio);
}
var maxRatio = this.getProperty("mb:maxRatio");
if (maxRatio) {
this.maxRatio = new Number(maxRatio);
}
var layersNode = widgetNode.selectSingleNode("mb:layers");
if (layersNode) {
this.layerNames = new Array();
var layers = layersNode.childNodes;
for (var i = 0; i < layers.length; i++) {
if (layers[i].firstChild) {
this.layerNames.push(getNodeValue(layers[i]));
}
}
}
this.model.addListener("refresh", this.addOverviewMap, this);
}
OverviewMap.prototype.addOverviewMap = function(objRef) {
if (objRef.model && objRef.model.map) {
var map = objRef.model.map;
this.control = null
var options = {
div: objRef.getNode(),
objRef: this,
destroy: function() {
OpenLayers.Control.OverviewMap.prototype.destroy.apply(this, arguments);
this.div = null;
objRef.control = null;
objRef = null;
},
layers: new Array()
};
if (objRef.minRatio) options.minRatio = objRef.minRatio;
if (objRef.maxRatio) options.maxRatio = objRef.maxRatio;
if (!objRef.layerNames) {
for (var i in map.mbMapPane.oLlayers) {
var oLlayer = map.mbMapPane.oLlayers[i];
if (oLlayer) {
var baseLayer = objRef.getClonedLayer(oLlayer, true);
options.layers.push(baseLayer);
break;
}
}
}
var isBaseLayer = true;
if (objRef.layerNames) {
for (var i = 0; i < objRef.layerNames.length; i++) {
var oLlayer = map.mbMapPane.getLayer(map.mbMapPane, objRef.layerNames[i]);
if (oLlayer) {
options.layers.push(objRef.getClonedLayer(oLlayer, isBaseLayer));
isBaseLayer = false;
}
}
}
var extent = map.getExtent();
if (objRef.width && objRef.height) {
options.size = new OpenLayers.Size(objRef.width, objRef.height);
}
else if (objRef.width) {
options.size = new OpenLayers.Size(
objRef.width,
objRef.width * extent.getHeight() / extent.getWidth());
}
else if (objRef.height) {
options.size = new OpenLayers.Size(
objRef.height * extent.getWidth() / extent.getHeight(),
objRef.height);
}
if (!objRef.control) {
objRef.control = new OpenLayers.Control.OverviewMap(options);
objRef.control.mapOptions = {theme: null};
map.addControl(objRef.control);
}
for (var i=0; i<options.layers.length; i++) {
options.layers[i].setVisibility(true);
}
}
}
OverviewMap.prototype.getClonedLayer = function(layer, isBaseLayer) {
if (layer == null) {
return null;
}
isBaseLayer = isBaseLayer ? true : false;
if (layer instanceof OpenLayers.Layer.WMS) {
var layerOptions = {
units: layer.units,
projection: layer.projection,
maxExtent: layer.maxExtent,
maxResolution: "auto",
ratio: 1,
singleTile: true,
isBaseLayer: isBaseLayer
};
return new OpenLayers.Layer.WMS(layer.name,
layer.url, {
layers: layer.params.LAYERS,
format: layer.params.FORMAT,
transparent: layer.params.TRANSPARENT,
sld: layer.params.SLD,
sld_body: layer.params.SLD_BODY,
styles: layer.params.STYLES
}, layerOptions);
}
else {
var clonedLayer = layer.clone();
clonedLayer.setVisibility(true);
return clonedLayer;
}
}
Documentation generated by
JSDoc on Sun Apr 27 20:30:54 2008