var map, drawControls, select, polygonLayer, boxLayer, selectBoxFeature, layerNames, layerObjs, overlays, overlayStates, zoomLevelElms, initZoomLevel, overviewControl; function mapinit(userWestLon,userSouthLat,userEastLon,userNorthLat,westLon,southLat,eastLon,northLat,markerText) { var maxBounds = new OpenLayers.Bounds( -365, -90, 365, 90 ); layerNames = new Array(); OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; // **************************** // CREATE WMS MAP LAYERS... // **************************** // create metacarta layer //var wmsUrlA = ["http://t1.labs.metacarta.com/wms-c/Basic.py", // "http://t2.labs.metacarta.com/wms-c/Basic.py"]; //var wmsUrl = "http://disc1.sci.gsfc.nasa.gov/daac-bin/wms_ogc?"; var wmsUrl = "http://labs.metacarta.com/wms/vmap0"; var ol_wms = new OpenLayers.Layer.WMS( "Basic Political Map", wmsUrl, {layers: 'basic', format: 'image/png'}, {wrapDateLine: true, isBaseLayer: true, 'buffer': 1} ); // register metacarta event handlers (handle the failover condition in the event of a timeout) //if(!(ie)){ // ol_wms.events.register("loadstart",ol_wms,layerLoadFailOver); // ol_wms.events.register("loadend","",layerLoadEnd); //} layerNames[0] = "Basic Political Map"; // old blue marble layer using G3's map server //var g3bmurl = "http://gdev.sci.gsfc.nasa.gov:9393/wmsc/wmscgiovanni.py/wmsc2km8km"; //var g3bm_wms = new OpenLayers.Layer.WMS("Blue Marble", g3bmurl, // {layers:"SummerBMNG", format:"image/png"}, // {wrapDateLine: true, isBaseLayer: true, 'buffer': 1}); var minnWMSUrl = "http://g0hep12u.ecs.nasa.gov/mapserv-bin/wms_airsnrt?"; var minnWMS = new OpenLayers.Layer.WMS("Blue Marble", minnWMSUrl, {layers:"bluemarble,coastline", format:"image/png"}, {wrapDateLine: true, isBaseLayer: true, 'buffer': 1}); //SERVICE=WMS&VERSION=1.0.0&REQUEST=GETMAP&SRS=EPSG:4326&FORMAT=image/png&BBOX=-180,-90,180, 90&WIDTH=1000&HEIGHT=500&LAYERS=AIRVBRAD,coastline,grid60 // create the JPL Global Mosaic layer var jplwms = new OpenLayers.Layer.WMS( "Landsat 7 Global Mosaic", "http://t1.hypercube.telascience.org/cgi-bin/landsat7", {layers: "landsat7"},{transparent: true, wrapDateLine: true}); layerNames[1] = "Landsat 7 Global Mosaic"; // old JPL Blue Marble url //browse.cgi?wms_server=wms.cgi&layers=BMNG&srs=EPSG:4326&width=800&height=400&bbox=-180,-90,180,90&format=image/jpeg&zoom=&styles=Feb layerNames[2] = "Blue Marble"; // create political and hydrology layers using the local map server..... var disc1_MMSURL = "http://disc1.sci.gsfc.nasa.gov/daac-bin/wms_ogc?"; var airsNRT_MMSURL = "http://g0hep12u.ecs.nasa.gov/mapserv-bin/wms_airsnrt"; var countriesLyr = new OpenLayers.Layer.WMS("VMAP0 Political Boundaries", disc1_MMSURL, {layers:"countries", format:"image/png"}, {transparent: true, wrapDateLine: true, isBaseLayer: false, opacity: 0.35}); var coastlines = new OpenLayers.Layer.WMS( "Coastlines", airsNRT_MMSURL, {layers: 'coastline', format: 'image/png'}, {wrapDateLine: true, isBaseLayer: false, 'buffer': 1} ); var grid = new OpenLayers.Layer.WMS( "Grid", airsNRT_MMSURL, {layers: 'grid30', format: 'image/png'}, {wrapDateLine: true, isBaseLayer: false, 'buffer': 1} ); // CLOUD TEST LAYER var g3wmsurl = "//G3/giovanni-wms.cgi"; var cloudTitle = "Cloud Optical Thickness Layer"; var cloudlayer = "MOD08_D3.005::Cloud_Optical_Thickness_Combined_QA_Mean"; var cloudstyle = "DecoratedMap"; var cloudtime = "2006-02-01T00:00:00Z"; var cloudwms = new OpenLayers.Layer.WMS(cloudTitle, g3wmsurl, {layers:cloudlayer, format:"image/gif",transparent:"true",time:cloudtime, style: cloudstyle}, {opacity: 0.3, isBaseLayer: false, wrapDateLine: true}); // CLOUD COVERAGE TEST LAYER var g3wmxurl = "//G3/giovanni-wmx.cgi?STYLES=ctype=custom:palette=Grey%20Scale&FORMAT=image/"; var cloudTopTitle = "Cloud Pressure Mean Layer"; var cloudTopLayer = "MYD08_D3.005::Cloud_Top_Pressure_Mean"; var cloudTopStyle = "ctype=custom:palette=Grey Scale"; // OL WMS does not seem to read STYLES var cloudTopTime = "2008-02-01T00:00:00Z"; // nor does it seem to read TIME var cloudTopWms = new OpenLayers.Layer.WMS(cloudTopTitle, g3wmxurl, {layers:cloudTopLayer, format:"image/jpeg",transparent:"true",time:cloudTopTime, style: cloudTopStyle}, {opacity: 0.85, isBaseLayer: false, wrapDateLine: true}); overlays = { "Political Boundaries": countriesLyr, "Coastlines": coastlines, "Grid": grid } overlayStates = { "Political Boundaries": "checked", "Coastlines": "unchecked", "Grid": "unchecked" } // ***************************** // END OF WMS LAYER CREATION // ***************************** // create map options var options = { //numZoomLevels: 5, //resolutions: [0.46875,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.00137329101], //resolutions: [0.46875,0.3515625,0.17578125,0.087890625,0.0439453125], //minResolution: 0.0539453125, maxResolution: 1.40625, restrictedExtent: maxBounds, eventListeners: { "changebaselayer": mapBaseLayerChanged }, controls: [] }; // intialize new map map = new OpenLayers.Map('map', options); // initialize the array that holds the zoom level elments zoomLevelElms = new Array(); // register map listeners //map.events.register('movestart', map, setZoomDisplay); map.events.register('moveend', map, setZoomDisplay); // draw controls in the form of new vector layers - like the WMS layers above, these layers // are simply available for rendering polygonLayer = new OpenLayers.Layer.Vector("Various Features",{displayInLayerSwitcher: false}); boxLayer = new OpenLayers.Layer.Vector("Box Layer",{wrapDateLine: false, reproject: false, displayInLayerSwitcher: false}); // customize the polygon handler var customPolyHandler = OpenLayers.Handler.Polygon; OpenLayers.Util.extend( customPolyHandler, { dblclick: function(evt) { if(!this.freehandMode(evt)) { // remove the penultimate point var index = this.line.geometry.components.length - 2; this.line.geometry.removeComponent(this.line.geometry.components[index]); this.finalize(); } return false; }, mousedown: function(evt) { this.destroyFeature(); if (this.lastDown && this.lastDown.equals(evt.xy)) { return false; } if(this.lastDown == null) { this.createFeature(); } this.mouseDown = true; this.lastDown = evt.xy; var lonlat = this.control.map.getLonLatFromPixel(evt.xy); this.point.geometry.x = lonlat.lon; this.point.geometry.y = lonlat.lat; if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) { this.addPoint(); } this.drawFeature(); this.drawing = true; return false; } } ); var customPolyFeature = new OpenLayers.Control.DrawFeature(polygonLayer, OpenLayers.Handler.Polygon, { callbacks: { "point" : polyPointHandler } } ); // customize the box handler var customBoxHandler = OpenLayers.Handler; OpenLayers.Util.extend( customBoxHandler, { dblclick: function(evt) { //alert("dblclick"); if(!this.freehandMode(evt)) { // remove the penultimate point var index = this.line.geometry.components.length - 2; this.line.geometry.removeComponent(this.line.geometry.components[index]); this.finalize(); } return false; } } ); // test box stuff var testCtrl = new OpenLayers.Control(); OpenLayers.Util.extend(testCtrl, { draw: function () { // this Handler.Box will intercept the shift-mousedown // before Control.MouseDefault gets to see it this.box = new OpenLayers.Handler.Box( testCtrl, {"done": this.notice} //{keyMask: OpenLayers.Handler.MOD_SHIFT} ); }, notice: function (bounds) { boxHandler(bounds); }, toggleActivate: function(handler) { if(mode == 'box'){ this.box.activate(); }else{ this.box.deactivate(); } }, activate: function() { this.box.activate(); }, deactivate: function() { this.box.deactivate(); } }); var customBoxFeature = new OpenLayers.Control.DrawFeature(boxLayer, customBoxHandler, {} ); drawControls = { pan: new OpenLayers.Control.Navigation({'zoomWheelEnabled': false}), zoom: new OpenLayers.Control.ZoomBox(), aoi: testCtrl //box: new OpenLayers.Control.DrawFeature(boxLayer, // OpenLayers.Handler.Rectangle, // {} ), //polygon: new OpenLayers.Control.DrawFeature(polygonLayer, // OpenLayers.Handler.Polygon, // { callbacks: { "done" : polyDoneHandler, "point" : polyPointHandler, "cancel" : polyCancelHandler } }, //polygon: customPolyFeature, //select: new OpenLayers.Control.SelectFeature(polygonLayer), //hover: new OpenLayers.Control.SelectFeature(polygonLayer, // {hover: true}) }; for(var key in drawControls) { map.addControl(drawControls[key]); } map.addLayers([minnWMS,jplwms,ol_wms,polygonLayer,boxLayer]); // see if there is a previously selected layer //if( selectedLayer != '' ){ // var sl = map.getLayer(selectedLayer); // map.setBaseLayer(sl); // } map.addControl(new OpenLayers.Control.MousePosition( { div: $('mPosDiv') } )); //overviewControl = new OpenLayers.Control.OverviewMap(); //map.addControl( overviewControl ); //map.addControl(new OpenLayers.Control.KeyboardDefaults()); //if (!map.getCenter()) map.zoomToMaxExtent(); setMapBounds( westLon, southLat, eastLon, northLat, markerText ); // check parent user-entered coordinates var wloc = window.location.href; if( wloc.indexOf("iSpatial") > -1 ){ var parent = window.opener; if(parent != null){ var conWest = parent.document.myForm.West.value; if(conWest != ""){ var conEast = parent.document.myForm.East.value; var conNorth = parent.document.myForm.North.value; var conSouth = parent.document.myForm.South.value; if(conWest != '-180' &&conWest != userWestLon){ userWestLon = conWest; } if(conEast != '180' && conEast != userEastLon){ userEastLon = conEast; } if(conNorth != '90' && conNorth != userNorthLat){ userNorthLat = conNorth; } if(conSouth != '-90' && conSouth != userSouthLat){ userSouthLat = conSouth; } } } } setBoundingBox( userWestLon, userSouthLat, userEastLon, userNorthLat, map ); //map.zoomToMaxExtent(); //map.setCenter(new OpenLayers.LonLat(0, 0), 0); //setMapBaseLayer(); setDrawControlElements(); setZoomLevelElms(); // set map toggle to match map default //activateControlElem(document.getElementById(layerNames[0])); } // end of init function // ******************************************* // layer event handler variables and functions // ******************************************* var layerLoadTime = 0; var t; var limit = false; // map layer count var layerIdx = 0; // layer loadstart event handler function layerLoadFailOver(event){ //alert("loadstart"); // start the counting loop // if layer loading goes on too long, // cancel the loading of this layer and start another layerLoadTime = 0; timedCount(); } // layer load end event handler function layerLoadEnd(event){ //alert("loadend"); clearTimeout(t); layerLoadTime = 0; } // timing function function timedCount(){ // use 'west' as a test field //document.getElementById("west").value = layerLoadTime; // increment load time layerLoadTime = layerLoadTime + 1; // start timeout loop t = setTimeout("timedCount()",1000); // set timing limit based on zoom factor var zoom = map.getZoom(); if( zoom == 0 ){ limit = 5; if(ie){ limit = 10; } }else { limit = 20; if(ie){ limit = 30; } } // if load time is greater than the limit, // try to display the next layer in the stack if(layerLoadTime > limit){ //map.zoomToMaxExtent(); //var elayer = map.getLayer(loadingLayerId); clearTimeout(t); //elayer.destroy(); //elayer.setVisibility(false); //map.removeLayer(elayer); var mapLayers = map.layers; var oldLayer = mapLayers[layerIdx]; // if the layer at the current index failed, // use the next index layerIdx++; // if the index grows beyond the current base layers, // report an error if( layerIdx > 2 ){ alert("All map base layers were inaccessible. Please report this error to the site administrator."); }else{ var newLayer = mapLayers[layerIdx]; map.setBaseLayer(newLayer); //map.removeLayer(oldLayer); // leave the temporarily inaccessible layer available for later requests } document.getElementById("mPosDiv").style.zIndex = "999"; //document.getElementById("mPosDiv").style.visibility = "visible"; //document.getElementById("mPosDiv").style.display = "block"; //document.getElementById("mPosDiv").style.color = "red"; //document.getElementById("mPosDiv").style.top = "-15px"; //document.getElementById("mPosDiv").style.border = "1px solid black"; } } // ************************************* // ************************************* // ************************************* // Map event handler functions // ************************************* // changebaselayer event handler function mapBaseLayerChanged(event) { document.getElementById("selectedMap").value = event.layer.name; //alert(event.layer.name); } function setMapBaseLayer() { // set selected base layer //var selectedBaseLayerID = document.getElementById("selectedBaseLayer").value; var defaultLayerID = "Blue Marble"; var URLParameterStr = window.location.search; if(URLParameterStr.indexOf("selectedMap") > -1){ //URLParameterStr = URLParameterStr.replace('%20',' '); //alert(URLParameterStr); var parameters = URLParameterStr.split("&"); var pLen = parameters.length; var selectedBaseLayerID = ""; for(var i=0;i -1 && elm.style.border.indexOf("inset") > -1 ){ // alert("placenames"); // map.setBaseLayer( ol_us_states ); //}else{ map.setBaseLayer( layers[0] ); //} activateControlElem(elm); }else{ // deactive the toggle deactivateControlElem(document.getElementById(layerNames[i])); } } } // ******* map pan functions ******* function panToGMT() { map.setCenter(new OpenLayers.LonLat(0, 0), 1); setZoomLevelElm(1); } function panToDL() { map.setCenter(new OpenLayers.LonLat(180,0), 1); setZoomLevelElm(1); } function panUp() { map.pan(0,-50,{}); } function panDown() { map.pan(0,50,{}); } function panLeft() { map.pan(-50,0,{}); } function panRight() { map.pan(50,0,{}); } function toggleCenter(elm) { if(elm.value == 'gm'){ panToGMT(); elm.value = 'dl'; elm.title = 'Center map on the International Dateline'; }else if(elm.value == 'dl'){ panToDL(); elm.value = 'gm'; elm.title = 'Center map on the Greenwich Meridian'; } } // ***** end of pan functions ****** // map zoom functions var maxZoomLevels = 5; function zoomIn() { var zl = map.getZoom(); if(zl < 5){ map.zoomIn(); setZoomLevelElm(zl+1); } } function zoomOut() { var zl = map.getZoom(); if(zl > 1){ map.zoomOut(); setZoomLevelElm(zl-1); } } function zoomTo(lvl) { var zl = map.getZoom(); if(zl <= 5 && zl >= 1){ map.zoomTo(lvl); setZoomLevelElm(lvl); }else if( zl > 5 ){ map.zoomTo(5); setZoomLevelElm(5); }else if( zl < 1 ){ map.zoomTo(1); setZoomLevelElm(1); } } function setZoomLevelElms(){ var zoomElmId = ''; var zlElm; var zl = 0; for(var i=0; i= 5){ setZoomLevelElm(5); } if(zl >= 4 && zl < 5){ setZoomLevelElm(4); } if(zl >= 3 && zl < 4){ setZoomLevelElm(3); } if(zl >= 2 && zl < 3){ setZoomLevelElm(2); } if(zl >= 1 && zl < 2){ setZoomLevelElm(1); } if(zl < 1){ setZoomLevelElm(1); } } // map mode control function var mode = ""; function toggleControl(element,e) { for(key in drawControls) { var control = drawControls[key]; var controlElem = drawControlElems[key]; if(element.value == key) { control.activate(); mode = element.value; //if( mode == "polygon" ){ // displayClickPoint(map,e); //} activateControlElem(controlElem); } else { control.deactivate(); deactivateControlElem(controlElem); } } } var drawControlElems; function setDrawControlElements() { var box = document.getElementById("boxToggle"); var pan = document.getElementById("noneToggle"); var zoombox = document.getElementById("zoomToggle"); drawControlElems = { 'aoi': box, 'pan': pan, 'zoom': zoombox }; } function activateControlElem(elem){ elem.style.background = 'rgb(120,120,120)'; elem.style.border = '2px inset'; } function deactivateControlElem(elem){ elem.style.background = 'rgb(200,200,200)'; elem.style.border = '2px groove rgb(200,200,200)'; } // used by init function to set default map mode function activateBoxMode() { //var box = document.getElementById("boxToggle"); var box = drawControlElems['aoi']; //box.checked = true; toggleControl(box,""); } function activatePanMode() { //var pan = document.getElementById("noneToggle"); var pan = drawControlElems['pan']; //none.checked = true; toggleControl(pan,""); } function activateZoomBox() { //var zoombox = document.getElementById("zoomToggle"); var zoombox = drawControlElems['zoom']; //zoombox.checked = true; toggleControl(zoombox,""); } // layer select function(s) function toggleLayer(elm){ for(var key in overlays) { if(elm.id == key){ if(elm.checked){ map.addLayer(overlays[key]); overlayStates[key] = "checked"; }else{ map.removeLayer(overlays[key]); overlayStates[key] = "unchecked"; } } } } function setOverlays() { // political layer should be checked by default map.addLayer(overlays["Political Boundaries"]); } // global select function(s) function showSelectMenu(elm,evt,yoffset) { var elmId = elm.id; var menuId = elmId.replace('BTN','MENU'); var menu = document.getElementById(menuId); if(menu.style.visibility != "visible"){ var pos = findMenuCtrlPos(elm); var yoff = yoffset; if(yoff == ''){ yoff = 20; } var elmLeft = pos[1] + 30; var elmTop = pos[0] + yoff; //alert( elmTop + ", " + elmLeft ); if(menuId == 'selectLayersMENU'){ // we need to build the menu if possible var menuStr = ""; var layerChecked = ""; for(var key in overlays) { if( overlayStates[key] == "checked" ){ layerChecked = "checked='checked'"; }else{ layerChecked = ""; } menuStr += ""+key+"
"; } menu.innerHTML = menuStr; //elmLeft = elmLeft - 300; elmLeft = elmLeft - 160; }else if(menuId == 'globalSelMENU'){ elmLeft = elmLeft - 160; } elmTop = elmTop + 'px'; elmLeft = elmLeft + 'px'; menu.style.left = elmLeft; menu.style.top = elmTop; menu.style.position = 'absolute'; menu.style.zIndex = '99999'; menu.style.visibility = 'visible'; menu.style.display = 'block'; }else{ hideSelectMenu(elm); } } function hideSelectMenu(elm) { var elmId = elm.id; var menuId = elmId.replace('BTN','MENU'); var menu = document.getElementById(menuId); menu.style.visibility = 'hidden'; menu.style.display = 'none'; } function globalMenu_selGM() { selectGlobeGM(); var gm = document.getElementById('globalSelMENU'); gm.style.visibility = 'hidden'; gm.style.display = 'none'; } function globalMenu_selDL() { selectGlobeDL(); var gm = document.getElementById('globalSelMENU'); gm.style.visibility = 'hidden'; gm.style.display = 'none'; } function findMenuCtrlPos(obj) { var curLeft = curTop = 0; if( obj.offsetParent ){ do { curLeft += obj.offsetLeft; curTop += obj.offsetTop; } while (obj = obj.offsetParent); } var pos = new Array(); pos[0] = curTop; pos[1] = curLeft; return pos; } // POLYGON handling vars and functions // takes mouse event to display current click point - used only in polygon mode at present function displayClickPoint(map,e) { var position = map.events.getMousePosition(e); if( mode == "polygon" ){ OpenLayers.Util.getElement("coords").innerHTML = position; } } // test function for polygon mode function polyDoneHandler(lineGeom) { alert("doneHandler:" + lineGeom.getComponentsString()); } // handles display of incoming polygon points to list var gPointCount = 0; var geolocs = new Array(); var last = ""; function polyPointHandler(aPoint) { gPointCount++; //alert("pointHandler:point n." + // gPointCount + " geom = " + aPoint.toShortString()); var incoming = aPoint.toShortString(); if( incoming != last ){ geolocs.push( incoming ); last = incoming; } displayList( geolocs ); } // wipes out the currently displayed polygon point list function polyCancelHandler(lineGeom){ alert("cancelHandler:" + lineGeom.getComponentsString()); geolocs = new Array(); } // BOX handling vars and functions // box handler callbacks function boxHandler(bounds){ //alert("called box handler: bounds: "+bounds.toString()); var boundStr = bounds + ""; var firstpair = boundStr.substring( boundStr.indexOf("(") + 1, boundStr.indexOf(")") + 1 ); var secondpair = boundStr.substring( boundStr.lastIndexOf("(") + 1 , boundStr.lastIndexOf(")") + 1 ); var fA = firstpair.split(","); var sA = secondpair.split(","); var leftbot = new OpenLayers.Pixel( fA[0], fA[1] ); var righttop = new OpenLayers.Pixel( sA[0], sA[1] ); var leftbotGeo = map.getLonLatFromPixel( leftbot ); var righttopGeo = map.getLonLatFromPixel( righttop ); //alert("leftbotgeo: "+leftbotGeo.toString()+", righttopgeo: "+righttopGeo.toString()); var westLon = leftbotGeo.lon; var southLat = leftbotGeo.lat; var eastLon = righttopGeo.lon; var northLat = righttopGeo.lat; //var westQuad = bounds.determineQuadrant( leftbotGeo ); //var eastQuad = bounds.determineQuadrant( righttopGeo ); //alert( "West: "+westQuad + ", East:" + eastQuad ); try{ document.myForm.West.value = westLon; document.myForm.East.value = eastLon; document.myForm.North.value = northLat; document.myForm.South.value = southLat; document.myForm.WestLongitude.value = westLon; document.myForm.EastLongitude.value = eastLon; document.myForm.NorthLatitude.value = northLat; document.myForm.SouthLatitude.value = southLat; }catch(err){} //var htmlStr = "North: "+northLat+"
East: "+eastLon+"
South: "+southLat+"
West: "+westLon; //OpenLayers.Util.getElement("coords").innerHTML = htmlStr; // correct for lon values > +/-180 degrees var curExt = map.getExtent(); if( curExt.left < -180 && westLon > eastLon ){ westLon = ((180 - westLon) + 180) * -1; }else if( curExt.right > 180 && westLon > eastLon ){ eastLon = 180 + (180 - Math.abs(eastLon)); } var pA = new Array(); pA[0] = new OpenLayers.Geometry.Point( westLon, northLat ); pA[1] = new OpenLayers.Geometry.Point( westLon, southLat ); pA[2] = new OpenLayers.Geometry.Point( eastLon, southLat ); pA[3] = new OpenLayers.Geometry.Point( eastLon, northLat ); // we want opaque external graphics and non-opaque internal graphics var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); layer_style.fillOpacity = 0.2; layer_style.graphicOpacity = 1; // create a polygon feature from a linear ring of points var pointList = []; //if(westLon > eastLon){ // for(var p=3;p>=0;p=p-1){ // pointList.push(pA[p]); // } //}else{ for(var p=0; p<4; p++) { pointList.push(pA[p]); } //} // destroy all features in the box layer (there should be only one anyhow) // so we can't draw multiple boxes for the moment...... boxLayer.destroyFeatures(); // use the linear ring geo to draw the polygon (restricted by points // to conform to a box) var linearRing = new OpenLayers.Geometry.LinearRing(pointList); var newPolygon = new OpenLayers.Geometry.Polygon(linearRing); var selectBoxFeature = new OpenLayers.Feature.Vector( newPolygon); //var testBoxFeature = new OpenLayers.Feature.Vector(); // add new polygon box feature to the box layer boxLayer.addFeatures([selectBoxFeature]); // if we're done with drawing, activate the pan mode (force a new draw selection) //activatePanMode(); // allow things to stick for now.... var baseLyr = map.baseLayer; var selectedLyrElm = document.getElementById("selectedMap"); selectedLyrElm.value = baseLyr.id; } // set the users bounding box on the map function setBoundingBox( westLon, southLat, eastLon, northLat, map ){ if( westLon != "" && southLat != "" && eastLon != "" && northLat != "" ){ // populate the form fields with the "un-corrected" coordinate values // check the constraint form values first if there is a parent //var wloc = window.location.href; // alert(wloc); //if( wloc.indexOf("iSpatial") > -1 ){ // var parent = window.opener; // if(parent != null){ // var conWest = parent.document.myForm.West.value; // if(conWest != ""){ // var conEast = parent.document.myForm.East.value; // var conNorth = parent.document.myForm.North.value; // var conSouth = parent.document.myForm.South.value; // if(conWest != westLon){ westLon = conWest; } // if(conEast != eastLon){ eastLon = conEast; } // if(conNorth != northLat){ northLat = conNorth; } // if(conSouth != southLat){ southLat = conSouth; } // } // } // } document.myForm.West.value = parseFloat(westLon); document.myForm.East.value = parseFloat(eastLon); document.myForm.North.value = parseFloat(northLat); document.myForm.South.value = parseFloat(southLat); document.myForm.WestLongitude.value = parseFloat(westLon); document.myForm.EastLongitude.value = parseFloat(eastLon); document.myForm.NorthLatitude.value = parseFloat(northLat); document.myForm.SouthLatitude.value = parseFloat(southLat); // check to see if we've crossed the date line if( parseFloat(westLon) > parseFloat(eastLon) ){ westLon = ((180 - westLon) + 180) * -1; } // check to see that the box is right-side up if( parseFloat(northLat) < parseFloat(southLat) ){ alert("Southern latitude is greater than the northern latitude. Please correct the latitude values."); }else{ // set the map extent as needed if( map != null ){ var newBounds = new OpenLayers.Bounds( westLon, southLat, eastLon, northLat ); map.zoomToExtent( newBounds ); //map.zoomOut(); } //if( document.myForm.WestLongitude.value == 'NaN' && // document.myForm.EastLongitude.value == 'NaN' && // document.myForm.NorthLatitude.value == 'NaN' && // document.myForm.SouthLatitude.value == 'Nan'){ //} // draw the bounding box var pA = new Array(); pA[0] = new OpenLayers.Geometry.Point( westLon, northLat ); pA[1] = new OpenLayers.Geometry.Point( westLon, southLat ); pA[2] = new OpenLayers.Geometry.Point( eastLon, southLat ); pA[3] = new OpenLayers.Geometry.Point( eastLon, northLat ); // we want opaque external graphics and non-opaque internal graphics var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); layer_style.fillOpacity = 0.2; layer_style.graphicOpacity = 1; // create a polygon feature from a linear ring of points var pointList = []; for(var p=0; p<4; p++) { pointList.push(pA[p]); } // destroy all features in the box layer (there should be only one anyhow) // so we can't draw multiple boxes for the moment...... boxLayer.destroyFeatures(); // use the linear ring geo to draw the polygon (restricted by points // to conform to a box) var linearRing = new OpenLayers.Geometry.LinearRing(pointList); var selectBoxFeature = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Polygon([linearRing])); // add new polygon box feature to the box layer boxLayer.addFeatures([selectBoxFeature]); } } } function selectGlobeGM() { setBoundingBox( '-180','-90','180','90', map ); panToGMT(); //activatePanMode(); } function selectGlobeDL() { setBoundingBox( '0','-90','360','90', map ); panToDL(); //activatePanMode(); } // handles the interaction with the map from the coordinate input form controls function updateSelectionKP(evt){ var keynum; var keychar; var crcheck; if(window.event) // IE { keynum = evt.keyCode; } else if(evt.which) // Netscape/Firefox/Opera { keynum = evt.which; } keychar = String.fromCharCode(keynum); var crcheck = /\r/; var tabcheck = /\t/; // check for carriage return; if so, update the user selection if( crcheck.test(keychar) || tabcheck.test(keychar) ){ var west = document.getElementById("west").value; var east = document.getElementById("east").value; var north = document.getElementById("north").value; var south = document.getElementById("south").value; if( (parseFloat(west) >= -365) && (parseFloat(east) <= 365) && (parseFloat(north) >= -90) && (parseFloat(south) <= 90) && sizeNotZero(west,east,north,south) ){ setBoundingBox( west, south, east, north, map ); } } } // used by the update button to take the input from the coordinate fields and update the map function updateSelection(){ var west = document.getElementById("west").value; var east = document.getElementById("east").value; var north = document.getElementById("north").value; var south = document.getElementById("south").value; if( (parseFloat(west) >= -365) && (parseFloat(east) <= 365) && (parseFloat(north) >= -90) && (parseFloat(south) <= 90) && sizeNotZero(west,east,north,south) ){ setBoundingBox( west, south, east, north, map ); } //var res = map.getResolution(); //var maxres = map.getMaxResolution(); //var scale = map.getScale(); //var units = map.getUnits(); //alert("updating..."+maxres+", "+scale); } // Enables the update button only if there is something to update...in theory function enableUpdateBtn(){ var west = document.getElementById("west").value; var east = document.getElementById("east").value; var north = document.getElementById("north").value; var south = document.getElementById("south").value; if( (parseFloat(west) >= -365) && (parseFloat(east) <= 365) && (parseFloat(north) >= -90) && (parseFloat(south) <= 90) && sizeNotZero(west,east,north,south) ){ document.getElementById("mapUpdateBtn").disabled = false; }else{ document.getElementById("mapUpdateBtn").disabled = true; } } // Makes sure that the updated box is, at least, not 0,0,0,0.... // should check the *size*.... function sizeNotZero(west,east,north,south){ var wlon = parseFloat(west); var elon = parseFloat(east); var nlat = parseFloat(north); var slat = parseFloat(south); if( wlon == 0 && elon == 0 ){ return false; }else if( nlat == 0 && slat == 0 ){ return false; }else if( wlon == elon || nlat == slat ){ return false; }else{ return true; } } // Used by the initialization function....in theory function disableUpdateBtn(){ document.getElementById("mapUpdateBtn").disabled = true; } // convert geographic coord into pixels and zoom to the // bounds set by the pixels. function setMapBounds( westLon, southLat, eastLon, northLat, markerText ){ // if the map is configured to be other than global in preliminary extent.... //if( westLon > -180 && southLat > -90 && eastLon < 180 && northLat < 90 ){ if( westLon != null && southLat != null && eastLon != null && northLat != null){ var mapBounds = new OpenLayers.Bounds( westLon, southLat, eastLon, northLat ); //alert( 'west: '+westLon+', south: '+southLat+', east: '+eastLon+', north: '+northLat ); var defaultBounds = new OpenLayers.Bounds( -180, -90, 180, 90 ); if( mapBounds.equals( defaultBounds) || (mapBounds.left <= -180 && mapBounds.right > 180) ){ //var testBounds = new OpenLayers.Bounds( -139.5, -39.5, 139.5, 39.5 ); map.zoomToExtent( mapBounds ); //map.zoomToExtent( testBounds ); //map.setCenter( new OpenLayers.LonLat(0,0), 1 ); //map.zoomIn(); //alert("default bounds: "+defaultBounds.toString()); }else{ //alert("non-default bounds: "+mapBounds.toString()+", defaultBounds: "+defaultBounds.toString()); //if( eastLon == 180 || eastLon == 180.0 ){ // eastLon = 179.999999; // mapBounds.right = eastLon; //} //if( westLon == -180 || westLon == -180.0 ){ // westLon = 179.999999; // mapBounds.left = westLon; //} var pA = new Array(); pA[0] = new OpenLayers.Geometry.Point( westLon, northLat ); pA[1] = new OpenLayers.Geometry.Point( westLon, southLat ); pA[2] = new OpenLayers.Geometry.Point( eastLon, southLat ); pA[3] = new OpenLayers.Geometry.Point( eastLon, northLat ); // we want opaque external graphics and non-opaque internal graphics var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); layer_style.fillOpacity = 0.1; layer_style.graphicOpacity = 0.1; layer_style.strokeColor = "#cc0099"; layer_style.fillColor = "white"; // create a polygon feature from a linear ring of points var pointList = new Array(); for(var p=0; p<4; p++) { pointList.push(pA[p]); } // destroy all features in the box layer (there should be only one anyhow) // so we can't draw multiple boxes for the moment...... polygonLayer.destroyFeatures(); // use the linear ring geo to draw the polygon (restricted by points // to conform to a box) var linearRing = new OpenLayers.Geometry.LinearRing(pointList); var selectBoxFeature = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Polygon([linearRing]),{},layer_style); // test grid feature //var lsList1 = new Array(); //var lsList2 = new Array(); //lsList1[0] = new OpenLayers.Geometry.Point( -280, 0 ); //lsList1[1] = new OpenLayers.Geometry.Point( 280, 0 ); //lsList2[0] = new OpenLayers.Geometry.Point( 0, 90 ); //lsList2[1] = new OpenLayers.Geometry.Point( 0, -90 ); //var ls1 = new OpenLayers.Geometry.LineString(lsList1); //var ls2 = new OpenLayers.Geometry.LineString(lsList2); //var lsA = new Array(); //lsA[0] = ls1; //lsA[1] = ls2; //var mls = new OpenLayers.Geometry.MultiLineString( lsA ); //var grid = new OpenLayers.Feature.Vector( mls,{},layer_style); // add new polygon box feature to the box layer polygonLayer.addFeatures([selectBoxFeature]); if( markerText == "neespi" ){ var markers = new OpenLayers.Layer.Markers( "Instance Features",{displayInLayerSwitcher: false} ); var size = new OpenLayers.Size(223,20); //var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); var offset = new OpenLayers.Pixel(-1, -size.h); if( mapBounds.top >= 90 ){ offset.x = 0; //offset.y = ((mapBounds.getHeight() + size.h) * 2) + (size.h - 1); offset.y = 0; } var icon = new OpenLayers.Icon('/G3/images/neespiResearchArea.gif',size,offset); var marker = new OpenLayers.Marker(new OpenLayers.LonLat(westLon,northLat),icon); marker.setOpacity(0.2); marker.events.register('mousedown', marker, function(evt) { goToNEESPISiteConfirm(); OpenLayers.Event.stop(evt); }); markers.addMarker( marker ); map.addLayer(markers); } map.zoomToExtent( mapBounds ); //map.zoomIn(); }// end of defaultBounds test }else{ //map.zoomToExtent( maxBounds ); map.setCenter( new OpenLayers.LonLat( 0, 0), 1 ); } } function toggleOverview(telm,evt){ if( telm.value == 'ovshow' ){ overviewControl.maximizeControl(evt); //ovElm.style.display = 'block'; //ovElm.style.visibility = 'visible'; telm.style.background = 'rgb(140,140,140)'; telm.value = 'ovhide'; }else{ overviewControl.minimizeControl(evt); //ovElm.style.display = 'none'; //ovElm.style.visibility = 'hidden'; telm.style.background = 'rgb(200,200,200)'; telm.value = 'ovshow'; } } // Show the current geolocation coordinates of the user selection in a list function displayList( locs ){ var htmlStr = "Geolocation Coordinates:
"; var row; for(var i=0; i"; } OpenLayers.Util.getElement("coords").innerHTML = htmlStr; } var points = new Array(); function addPointsToList(map,e) { var position = map.events.getMousePosition(e); if( mode == "polygon" ){ points.push(position); } var htmlStr = ""; for(var i=0;i"; } OpenLayers.Util.getElement("coords").innerHTML = htmlStr; } function goToNEESPISiteConfirm() { var r=confirm("The Northern Eurasia Earth Science Partnership Initiative, or NEESPI, is a currently active, yet strategically evolving program of internationally-supported Earth systems science research, which has as its foci issues in northern Eurasia that are relevant to regional and Global scientific and decision-making communities.\n\nWould you like to view the NEESPI home page?"); if (r==true) { window.open("http://neespi.org","neespi"); } else { //document.write("You pressed Cancel!"); } } // INITIALIZATION functions function setMapDefaultConfig(state) { activateBoxMode(); setMapBaseLayer(); //setSizeByFlowState(state); setOverlays(); } function setSizeByFlowState(state) { // if it's for the landing page, that's one size, // if it's for the results page, that's another; // it'll probably be different for individual parameter // tweaking as well. var mapDiv = document.getElementById("map"); var hintsDiv = document.getElementById("maphints"); var controlsDiv = document.getElementById("controls"); var mPosDiv = document.getElementById("mPosDiv"); if( state == 'landing' ){ mapDiv.className = 'map'; //hintsDiv.className = 'hints'; controlsDiv.className = 'controls'; //mPosDiv.className = 'mousePosition'; }else if ( state == 'results' ){ mapDiv.className = 'resultsMap'; //hintsDiv.className = 'resultsHints'; controlsDiv.className = 'resultsControls'; //mPosDiv.className = 'resultsMousePosition'; }else{ mapDiv.className = 'map'; //hintsDiv.className = 'hints'; controlsDiv.className = 'controls'; //mPosDiv.className = 'mousePosition'; } } function resetSpatialMap(westLon,southLat,eastLon,northLat) { try{ var eLon = parseFloat(eastLon); var wLon = parseFloat(westLon); var nLat = parseFloat(northLat); var sLat = parseFloat(southLat); //var ueLon = parseFloat(document.myForm.EastLongitude.value); //var uwLon = parseFloat(document.myForm.WestLongitude.value); //var unLat = parseFloat(document.myForm.NorthLatitude.value); //var usLat = parseFloat(document.myForm.SouthLatitude.value); //if( eLon == ueLon && wLon == uwLon && nLat == unLat && sLat == usLat ){ //boxLayer.destroyFeatures(); document.myForm.West.value = wLon; document.myForm.East.value = eLon; document.myForm.North.value = nLat; document.myForm.South.value = sLat; document.myForm.WestLongitude.value = wLon; document.myForm.EastLongitude.value = eLon; document.myForm.NorthLatitude.value = nLat; document.myForm.SouthLatitude.value = sLat; //}else{ setBoundingBox(wLon,sLat,eLon,nLat,map); //} }catch(err){} } function updateSpatialCoordinates() { var parentDoc = window.opener.document; parentDoc.myForm.West.value = document.myForm.West.value; parentDoc.myForm.East.value = document.myForm.East.value; parentDoc.myForm.North.value = document.myForm.North.value; parentDoc.myForm.South.value = document.myForm.South.value; }