AoiBoxOL.js
Summary
No overview generated for 'AoiBoxOL.js'
mapbuilder.loadScript(baseDir+"/widget/WidgetBase.js");
function AoiBoxOL(widgetNode, model) {
WidgetBase.apply(this,new Array(widgetNode, model));
this.cursor = 'crosshair';
this.createControl = function(objRef) {
var Control = OpenLayers.Class( OpenLayers.Control, {
CLASS_NAME: 'mbControl.AoiBoxOL',
type: OpenLayers.Control.TYPE_TOOL,
draw: function() {
this.handler = new OpenLayers.Handler.Box( this,
{done: this.aoiBox}, {keyMask: this.keyMask} );
},
aoiBox: function (position) {
if (position instanceof OpenLayers.Bounds) {
var minXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.left, position.bottom));
var maxXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.right, position.top));
var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
maxXY.lon, maxXY.lat);
}
else{
var XY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.x, position.y));
var bounds = new OpenLayers.Bounds(XY.lon, XY.lat,
XY.lon,XY.lat);
}
var bboxOL = bounds.toBBOX().split(',');
var ul = new Array(bboxOL[0],bboxOL[3]);
var lr = new Array(bboxOL[2],bboxOL[1]);
objRef.model.setParam("aoi", new Array(ul, lr));
}
});
return Control;
}
this.init = function(objRef) {
var Control = objRef.createControl(objRef);
var ct=new Control();
objRef.model.map.addControl(ct);
ct.activate();
}
this.model.addListener("loadModel",this.init, this);
this.drawAoiBox = function(objRef) {
if(objRef.model.map){
var ext = objRef.model.getParam('aoi');
var bounds = new OpenLayers.Bounds(ext[0][0], ext[1][1], ext[1][0], ext[0][1]);
objRef.model.aoiBoxLayer = new OpenLayers.Layer.Boxes('Boxes');
objRef.model.map.addLayer(objRef.model.aoiBoxLayer);
var box = new OpenLayers.Marker.Box(bounds);
objRef.model.aoiBoxLayer.addMarker(box);
}
}
this.clearAoiBox = function(objRef) {
if (objRef.model.aoiBoxLayer) {
objRef.model.aoiBoxLayer.destroy();
}
}
this.model.addListener('aoi', this.clearAoiBox, this);
this.model.addListener('aoi', this.drawAoiBox, this);
}
Documentation generated by
JSDoc on Sun Apr 27 20:30:54 2008