// USGS_NATMAP_params.js

//******************  Object prototypes used in this file ********************

function RankingMode(name, desc)
{
	this.name = name;
	this.displayName = name.charAt(0).toUpperCase() + name.replace('_',' ').substring(1, name.length);
	this.desc = desc;
	rankingModes[name] = this;
	return this;
}

// Skins

// skin extents 

// map left to right width in degrees; when view extent goes
// below this threshold switch from an extent to a crosshair

// startXYs: start map extents
// ovStartXYs: ov map extents

// All extents are given in the following order:
// minx    miny    maxx    maxy

// skin element sets (ES). a skin's ES overrides
// a supplied URL param value.

// Constructor

function Skin(
	tag,
	name,
	ovSymbolSwitchThreshold,
	boundingBox,
	elementSet,
	rankingMode )
{
	this.tag = tag;
	this.name = name;
	this.ovSymbolSwitchThreshold = ovSymbolSwitchThreshold;
	this.startXYs = boundingBox;
	this.ovStartXYs = boundingBox;
	this.elementSet = elementSet;
	this.rankingMode = rankingModes[rankingMode.name];
	skins[tag] = this;
	return this;
}


//******************************  Parameters **********************************


// ============= URL Resources ===============

// Following statement retrieves dynamic parameters from 
// parammanager servlet and writes them to this page:
// var USE_EXTERNAL_MIDDLEWARE
// 		if true connect to external middleware component,
// 		if false connect to local tnm server side code component.
// var nmCatURL
// var ovOgcUrlStub
// var acetateOgcUrlStub
document.writeln('<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="/tnm/parammanager/controller?type=paramjs"></' + 'SCRIPT>');

// get machine name
var hostName = document.location.host;
var webAppRoot = "http://" + hostName + "/tnm";

// Location of the connectors - consolidated mw approach
var connectorURL = webAppRoot + "/theCatalog?";
var printStub    = connectorURL;
var extractStub  = connectorURL;
var gnisStub     = webAppRoot + '/gnis';

// fully qualified URL to the root of the viewer
// use for forming absolute links to the viewer root
var viewerURLRoot = document.location.protocol + '//' + hostName 
	+ document.location.pathname.substr(0,(document.location.pathname.lastIndexOf('/') + 1));

// for elevation lookup service
var elevLookupStub = 'http://gisdata.usgs.net/XMLWebServices/Elevation_Result.aspx?';
var elevLookupResultUrl = viewerURLRoot + 'elevationResults.html';

// for place tag layer service
var placeTagUrlStub = 'http://nmcatalog.usgs.gov/annotator/annotatorservlet?';
// ============= End URL Resources ===============

// ============= Viewer Configuration Variables ===============

var rankingModes = new Array();

var applicationMode = new RankingMode('application','Displays only a small set of preselected layers in map view (default mode).');
var scaleclassMode = new RankingMode('scaleclass','Displays the recommended, most detailed base layers needed to fill the map view for a selected class.');
var scaleclass_applicationMode = new RankingMode('scaleclass_application','Displays the default set of preselected layers, plus the recommended, most detailed base layers needed to fill the map view for a selected class.');
var noRankingMode = new RankingMode('none','Displays all layers in the map view for a selected class.');

// -------- skin parameters (note: the 0-elem skin is the default)

// viewer skin capability boolean (false==skin param ignored)
var allowSkins    = true; 
// skin state boolean - (false==default skin)
var useCustomSkin = false; 

var skinLibDir = "skin-library";

var skins = new Array();

// Skin constructor

var defaultSkin = new Skin(
	'DEFAULT', 'National Map',
	2, 
	[-170, 15, -55, 75],
	'1',
	applicationMode  );

var tutorSkin = new Skin(
	'TNMTUTOR', 'National Map Tutorial',
	2, 
	[-170, 15, -55, 75],
	'1',
	applicationMode );

var indianaSkin = new Skin(
	'IN', 'Indiana',
	0.2, 
	[-88.16, 37.66, -84.68, 41.91],
	'1',
	noRankingMode );
	
var skin        = defaultSkin;
var rankingMode = applicationMode;
// initializes all layers in a class as perferred=false (off) if user selects an individual layer
// otherwise all recommended layers will be selected when any layer in the class is selected by the user
var allowDefaultOffOnUserLayerSelection = true;

// All extents are given in the following order:
// minx    miny    maxx    maxy

// map viewer limits: NOTE, this can be removed if we decide to 
// go with full-extent function that uses skin startXYs
var limitXYs = [-190, 5, -45, 85];

// placeholders - populated in USGS_NATMAP_utilities.js:processUrlParams()
var limitMinX, limitMinY, limitMaxX, limitMaxY;
var startOVLeft, startOVBottom, startOVRight, startOVTop;

// -------- start-up context

// 1 is the national map element set
var elementSetId = "1";
var allowElementSetOverRide = false;

// place holder in case pipe-separated list of class names to show on startup
// is passed in as the CLASSES url parameter, otherwise not used.
var defaultOnClasses = null;
// array of classIds to turn on at viewer startup, replaces defaultOnClasses for general case
var defaultOnClassIds = [ 39, //BOUNDARIES - STATE/TERRITORY
  20, //TRANSPORTATION - ROADS
  4, //ELEVATION - SHADED RELIEF
  64 //ORTHOIMAGERY - INDEX/STATUS (IMAGERY)
];
// pipe-separated list of layer ids to show on startup
var defaultOnLayers = "";
// pipe-separated list of layer ids to not show on startup
  // ELEV 1691: GTOPO60 Grayscale Shaded Relief
  // ORTHO 9521: Montana Ortho Photo Index
  // ORTHO 9630: NDOP
var defaultOffLayers = "1691|9521|9630"; 

// Status bar mouseover coordinate format: deg-min-sec (Dms) or dec-degrees
var useDmsDisplayCoords = true;


// -------- viewer config values

// -------- booleans for various functionality
var showOptionsButton = true;  // if options should be presented to user
var showScalePercent  = true;  // show scale factor in status bar
var useMetric         = false; // 
var useFineMeasure    = false; // adds more decimal places to measured values
var useInstantRefresh = false; // default setting
var legendVisible     = false; // init value
var resize      = false;
var addBookMark = true; 
var tagAddress  = false;
// temporary, if xml should use new xml request response for 
// get_image, must be true for instant refresh to work;
var useNewImageCommunication = true;  
// for toc; can individual wms layer be turned on or off
// if false only classes can be turned on or off
var canToggleLayers = true;
// display coords in status line
var showXYs=true;
// display National Grid Coords - only shows if showXYs is set to true
var showNationalGrid = true;
// Scale Bar
var drawScaleBar = true;

// -------- params for GNIS zoom on/off layers
// array of catalog map service Ids for GNIS layers
var GnisIds = new Array( "3369", "3370", "3371", "3372", "3373", "3374", "3378");
// Array of catalog map service Ids for Geographic Names -> NAMES 
// layers to hide when GNIS layers are turned on in GNIS feature zoom.
var NamesClassHideIds = new Array("1695"); // Road Labels BTS
// Catalog class names for NHD layers turned on for GNIS results page
// feature links. 
var	GnisNhdClassNames = new Array("WATERBODIES", "STREAM NETWORK");

// -------- debug params
// allow the clientLog* functions to open a window and write client log statements.
var allowClientLog = false; 
// allow debugging
var setDebug = false;
// other debug flags
var globalDebugFlag  = 0;
// > 2 shows logs requests and responses
// >= 5 shows response split on OUTPUT elems
// >= 5 shows GETFEATUREINFO details
// >= 5 shows extract tnm info details

// -------- Zoomback history
var historyLength = 5;
var historyIndex  = 0;
var savedExtents  = 0
var mycounter     = 0;
var extentsHistory = new Array(historyLength);


// -------- miscellaneous
// character used by browser in decimals - either point or comma
var decimalChar = ((("theChar is" + (10/100)).indexOf("."))==-1) ? "," : ".";
var appDir = "";

// parameters of measure Tool Click Points
var numClickPointLayers = 5; // number of click point layers to create
var clickPointColor     = '#00ff00';
var clickPointSize      = 4;

// Number of placeholders for OGC WMS layers
var maxOgcMapLayers = 50;

var pageDisplayCoordPrecision = 4;

// measure tool params
var measureBoxUnits = "MILES"; //uppercase, currently supports FEET,MILES,METERS,KILOMETERS
var numDecimals = 2; // used to set precision on measure tool - default == 2

var zoomFactor = 2
var panFactor = 50/100;

var MapUnits = "DEGREES";

// default annotation coords
var tagX=-1;
var tagY=-1;

var theCursor = "hand";
var dQuote = '"';

// variables to store identify request params
var identifyX, identifyY;


// -------- viewer windows, img & obj dims 

// map size . . . dynamically updated
var iWidth = 630;
var iHeight = 512;

// overview map image size in pixels, always positive . . . dynamically updated
var ovImgWidth = 150;
var ovImgHeight = 120;

// pop-up window dims
var extractWinHt  = 650;
var extractWinWth = 750;
var elevWinHt     = 480;
var elevWinWth    = 400;
var findPlcWinHt  = 610;
var findPlcWinWth = 630;
var identWinHt    = 600;
var identWinWth   = 800;
var instrWinHt    = 600;
var instrWinWth   = 800;
var gnisWinHt  = 540;
var gnisWinWth = 400;
var helpWinHt  = 340;
var helpWinWth = 400;
var optionsWinWth = 650;
var optionsWinHt  = 675;
var bookmarkWinWth = 600;
var bookmarkWinHt  = 460;
var popUpScrnCoordTop = 100;
var popUpScrnCoordLeft = 100;

// loading...  info
var loadDataSrc    = "images/loadData.gif";
var loadDataHeight = 100;
var loadDataWidth  = 100;

var loadMapSrc    = "images/loadMap.gif";
var loadMapHeight = 100;
var loadMapWidth  = 100;


// -------- scale settings

// Scale Settings - scale factors used for zoomScale() function,
//  sets breaks between scale tiers
var MIN_SCALE_FACTOR  = 0.00087;
var MIN1_SCALE_FACTOR = 0.0029;
var MIN2_SCALE_FACTOR = 0.0058;
var MID_SCALE_FACTOR  = 0.0116;
var MAX2_SCALE_FACTOR = 0.0232;
var MAX1_SCALE_FACTOR = 0.232;

// for zoomToPoint, the denominator of a releative scale
// see the caveats at the top of USGS_NATMAP_scale.js
var DEFAULT_ZOOM_REL_SCALE = 24000;
var REL_SCALE_LOCAL  = 12000;
var REL_SCALE_NEIGHBORHOOD = 24000;
var REL_SCALE_CITY   = 48000;
var REL_SCALE_REGION = 250000;
var REL_SCALE_STATE  = 5000000;
var REL_SCALE_MULTI_STATE = 20000000;


// -------- overview map

var hasOVMap = true; // NOTE: placeholder box remains when this is false; 
var ovIsVisible = true;
//recognized colors: white,yellow,lightyellow, light green,red,magenta,lightgrey,lightblue,orange,etc
var zoomOVCrossColor = 'red'; 
var zoomOVBoxColor   = 'red';
var zoomBoxColor = 'red';
// CREATE A VARIABLE TO SET OV MAP STATE TO HIDDEN ?
var ovBoxSize = 3;
var ovBorderWidth   = 1;
var ovExtentBoxSize = 1;

// These are set in USGS_NATMAP_Init.js
var ovBbMinX, ovBbMaxX, ovBbMaxY, ovBbMinY;

// -------- text strings

var msgList = new Array();
// some error messages
msgList[0] = "Unable to load one of the following Javascript Libraries:\naimsCommon.js\naimsXML.js\naimsMap.js";
msgList[1] = "Unable to start. Required HTML Form missing (jsForm.htm).";
msgList[2] = "Response from previous request(s) not received.";
msgList[3] = "Form for posting request not found. Unable to communicate with server.";
msgList[4] = "\nUnable to execute response.";
msgList[5] = "Function not enabled.";
// used with debugging messages
msgList[6] = "ServiceName: ";
msgList[7] = "\nRequest:\n ";
msgList[8] = "Response:\n ";
// Text for scrollover of  status bar
msgList[9] = "Map: ";
msgList[10] = "Image: ";
msgList[11] = "ScaleFactor: ";
msgList[12] = "NatGrid: "; // NG status title
msgList[13] = " -- ";      // delimiter for status elements
msgList[14] = " , ";       // coord delimiter
msgList[15] = " dec degrees/pixel"; //after scale factor number
msgList[16] = "Missing USGS_NATMAP_utilities library.";
msgList[17] = "Missing USGS_NATMAP_xml library.";
msgList[18] = "Missing USGS_NATMAP_regions library.";
msgList[19] = "Missing USGS_NATMAP_print library.";
msgList[20] = "Missing USGS_NATMAP_OgcParams library.";
msgList[21] = "Missing USGS_NATMAP_MapTools library.";
msgList[22] = "Missing USGS_NATMAP_Identify library.";
msgList[23] = "Missing USGS_NATMAP_Constants library.";
msgList[24] = "Missing USGS_NATMAP_class library.";
msgList[25] = "Missing USGS_NatGridFunctions library.";
msgList[26] = "Element Set cannot be changed. \r\nThis application is configured to only use the default element set.";

