Project

General

Profile

1
// global variables for the map
2
var map;
3
var control;
4

    
5
function initMap(GEOSERVER_URL, SERVLET_URL, qformat, bounds, additionalLayers) {
6
	if (!bounds) {
7
		bounds = new OpenLayers.Bounds(-180,-90,180,90);
8
	}
9
    map = new OpenLayers.Map('map', { 'maxExtent':bounds, 'maxResolution':'auto'});
10

    
11
    var metacat_points = new OpenLayers.Layer.WMS( "Metacat Doc Points",
12
        GEOSERVER_URL + "/wms",
13
        {layers: "data_points",
14
         transparent: "true", format: "image/gif"} );
15

    
16
    var metacat_bounds = new OpenLayers.Layer.WMS( "Metacat Doc Bounds",
17
    	GEOSERVER_URL + "/wms",
18
        {layers: "data_bounds",
19
         transparent: "true", format: "image/gif"} );
20

    
21
    var world_borders = new OpenLayers.Layer.WMS( "World Borders",
22
    	GEOSERVER_URL + "/wms",
23
        {layers: "world_borders",
24
         format: "image/jpeg"} );
25

    
26
    var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
27
        "http://labs.metacarta.com/wms/vmap0",
28
        {layers: 'basic'} );
29

    
30
    var jpl_wms = new OpenLayers.Layer.WMS( "NASA Landsat Mosaic",
31
        "http://wms.jpl.nasa.gov/wms.cgi", 
32
        {layers: "modis,global_mosaic"});
33

    
34
    var demis = new OpenLayers.Layer.WMS( "Demis World Map",
35
        "http://www2.demis.nl/WMS/wms.asp?wms=WorldMap",
36
        {layers: 'Bathymetry,Countries,Topography,Hillshading,Coastlines,Waterbodies,Inundated,Rivers,Streams,Builtup+areas,Railroads,Highways,Roads,Trails,Borders,Cities,Settlements,Airports'} );
37

    
38
	map.addLayers([demis, jpl_wms, ol_wms, world_borders, metacat_points, metacat_bounds]);	
39

    
40
	// perhaps a skin has added more layers
41
	if (additionalLayers) {
42
		map.addLayers(additionalLayers);
43
	}
44
	
45
    // get the drag box event
46
	//control = new OpenLayers.Control();
47
	control = new OpenLayers.Control({title: "Metacat spatial query", displayClass: "spatialQuery"});
48
	OpenLayers.Util.extend(
49
			control, {
50
			    draw: function () {
51
			        // this Handler.Box will intercept the shift-mousedown
52
			        // before Control.MouseDefault gets to see it
53
			        this.box = new OpenLayers.Handler.Box( control,
54
			        		{"done": this.notice}
55
                            //,{keyMask: OpenLayers.Handler.MOD_SHIFT}
56
			        		);
57
			        this.box.activate();
58
			    },
59
			    notice: function (bounds) {
60
			    	var min_px;
61
			        var max_px;
62
			        // check that it is a rectangle
63
			        if (bounds.left) { 
64
				        min_px = new OpenLayers.Pixel( bounds.left, bounds.bottom);
65
				        max_px = new OpenLayers.Pixel( bounds.right, bounds.top);
66
					} else {
67
						var tolerance = new OpenLayers.Pixel(3, 3);
68
					    min_px = new OpenLayers.Pixel( bounds.x - tolerance.x, bounds.y + tolerance.y);
69
					    max_px = new OpenLayers.Pixel( bounds.x + tolerance.x, bounds.y - tolerance.y);
70
					}
71
			        var min_ll = map.getLonLatFromPixel(min_px);
72
			        var max_ll = map.getLonLatFromPixel(max_px);
73
			      	//alert("longitude: " + round(mid_ll.lon,3) + " , latitude: " + round(mid_ll.lat,3) );
74
				    url = SERVLET_URL + '?action=spatial_query&xmin='+min_ll.lon+'&ymin='+min_ll.lat+'&xmax='+max_ll.lon+'&ymax='+max_ll.lat+'&skin=' + qformat;
75
				    OpenLayers.ProxyHost = '';
76
				    newwindow = 
77
					    window.open(
78
							    url,
79
							    'queryWin',
80
				                'height=600,width=800,status=yes,toolbar=yes,menubar=no,location=yes,resizable=yes,scrollbars=yes');
81
				
82
			    }
83
	});
84
	var tb = OpenLayers.Class(OpenLayers.Control.NavToolbar, {
85
		initialize: function() {
86
			var options = null;
87
			OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]);
88
			this.addControls([
89
			                  new OpenLayers.Control.Navigation({'zoomWheelEnabled': false}),
90
			                  new OpenLayers.Control.ZoomBox(),
91
			                  control
92
			                  ]);
93
		}
94
	});
95
	map.addControl(new tb());
96
	//map.addControl(control);
97

    
98
	// some built-in controls
99
	//map.addControl(new OpenLayers.Control.NavToolbar());
100
	map.addControl(new OpenLayers.Control.LayerSwitcher());
101
	map.addControl(new OpenLayers.Control.MousePosition());
102

    
103
	// zoom to center
104
    if (!map.getCenter()) {
105
         map.zoomToMaxExtent();
106
    }
107

    
108
}
109

    
110
// for named location navigation
111
function zoomToLocation(locations) {
112
	var selectedLocation = locations.options[locations.selectedIndex].value;
113
	// add a comma for the rectangle
114
	selectedLocation = selectedLocation.replace(" ", ",")
115
	var bounds = OpenLayers.Bounds.fromString(selectedLocation);
116
    map.zoomToExtent(bounds);
117
}
(3-3/6)