awips2/edexOsgi/build.edex/opt/esb/js/StopLightMaker.js
root 8e80217e59 Initial revision of AWIPS2 11.9.0-7p5
Former-commit-id: a02aeb236c [formerly 9f19e3f712] [formerly 06a8b51d6d [formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f]]
Former-commit-id: 06a8b51d6d
Former-commit-id: 3360eb6c5f
2012-01-06 08:55:05 -06:00

148 lines
4.6 KiB
JavaScript

/**
* This script creates a stop light (green/yellow/red) decision chart from a
* grid product. The parameter for the grid retrieval are set via the property
* setter. The color map is user selectable, but should be set to "StopLight".
*
* This script may be subscribed using the EDEX subscription service.
*
* This script represents a complete product generation. As such, it is not
* intended to be called from other scripts.
*
* Usage:
* This script creates a temperature based stop light chart.
* include("StopLightMaker.js");
* var dataRequest = new StopLightMaker();
* dataRequest.addParameter("paramid","Temperature");
* dataRequest.addParameter("levelinfo","2.0_m");
* dataRequest.addParameter("forecasttime","0");
* dataRequest.addParameter("gridid",212);
* dataRequest.setCount(1);
* dataRequest.setColormap("StopLight");
* dataRequest.setSortValue("basetime");
* dataRequest.execute();
*/
/**
* Class constructor.
*/
function StopLightMaker(){
this.plugin = "grib";
this.subscribe = false;
this.subscription = null;
this.queryResults = null;
this.reproject = false;
this.colormap = "StopLight";
this.format = "png";
this.scaleFactor = 3.0;
this.query = new TermQuery(this.plugin, subscriptionDataFieldId, subscriptionDataQueryId);
}
/**
* Main action method. Creates the stop light chart.
*
* @return (String) XML representing the final product
*/
function _execute()
{
if(this.subscribe){
this.subscription = new Subscription();
this.subscription.setup(this.query);
}
this.queryResults = this.query.execute();
if(this.queryResults == null || this.queryResults.size() == 0)
{
var response = new MakeResponseNull("Query returned 0 results.",this.query);
return response.execute();
}
else
{
return this.makeImageResponse();
}
}
/* setters */
function _addParameter(name, value){
this.query.addParameter(name, value);
}
function _addList(name, value){
this.query.addParameter(name, value, "in");
}
function _setCount(count){
this.query.setCount(count);
}
function _setScaleFactor(scale){
this.scaleFactor = scale;
}
function _enableSubscription(){
this.subscribe = true;
}
function _reprojectImage(reproject){
this.reproject = reproject;
}
function _setColormap(colormap){
this.colormap = colormap;
}
function _setFormat(format){
this.format = format;
}
function _setSortValue(sortValue){
this.query.setSortBy(sortValue);
}
function _requestImage(image){
this.createImage = image;
}
/* helper methods */
function _makeImageResponse(){
var response = new Array();
for(i=0; i < this.queryResults.size(); i++)
{
var currentQuery = this.queryResults.get(i);
var geom = currentQuery.getGrid().getGridGeom();
var crs = currentQuery.getGrid().getCrs();
var fileIn = new FileIn(this.plugin, currentQuery);
var stopLight = new StopLightImage(fileIn.execute());
var gribMap = new GribMap(this.plugin, this.colormap, stopLight.execute(), geom);
gribMap.setScaleFactor(this.scaleFactor);
var imageData = gribMap.execute();
geom = gribMap.getGridGeometry();
var colorMap = new ColorMapImage(this.colormap, imageData, geom);
var imageOut = null;
if(this.reproject){
var reproject = new ReprojectImage(colorMap.execute(), geom, crs);
var reprojectedImage = reproject.execute();
imageOut = new ImageOut(reprojectedImage, this.format, reproject.getGridGeometry());
}
else
{
imageOut = new ImageOut(colorMap.execute(), this.format);
}
var fileOut = new FileOut(imageOut.execute(), this.format);
var writeFile = fileOut.execute();
var makeResponse = new MakeResponseUri(writeFile, null, currentQuery.getDataURI(), this.format);
response[i] = makeResponse.execute();
}
return response;
}
/* map the functions to the class prototype */
StopLightMaker.prototype.execute = _execute;
StopLightMaker.prototype.makeImageResponse = _makeImageResponse;
StopLightMaker.prototype.addParameter = _addParameter;
StopLightMaker.prototype.addList = _addList;
StopLightMaker.prototype.setCount = _setCount;
StopLightMaker.prototype.setScaleFactor = _setScaleFactor;
StopLightMaker.prototype.enableSubscription = _enableSubscription;
StopLightMaker.prototype.reprojectImage = _reprojectImage;
StopLightMaker.prototype.setColormap = _setColormap;
StopLightMaker.prototype.setFormat = _setFormat;
StopLightMaker.prototype.setSortValue = _setSortValue;
StopLightMaker.prototype.requestImage = _requestImage;