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) {
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 sanparks_boundaries = new OpenLayers.Layer.WMS( "SANParks Boundaries",
27
    		GEOSERVER_URL + "/wms",
28
            {layers: "SANParks_Boundaries_gcs_wgs84",
29
             transparent: "true", format: "image/gif"} );
30

    
31
    /* 
32
     *   Other possible WMS base layers to include
33
     */
34

    
35
    var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
36
        "http://labs.metacarta.com/wms/vmap0",
37
        {layers: 'basic'} );
38

    
39
    var jpl_wms = new OpenLayers.Layer.WMS( "NASA Landsat Mosaic",
40
        "http://wms.jpl.nasa.gov/wms.cgi", 
41
        {layers: "modis,global_mosaic"});
42

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

    
47
    jpl_wms.setVisibility(false);
48
    ol_wms.setVisibility(false);
49
    demis.setVisibility(false);
50

    
51
	map.addLayers([demis, sanparks_boundaries, jpl_wms, ol_wms, world_borders, metacat_points, metacat_bounds]);	
52

    
53
	// some built-in controls
54
	map.addControl(new OpenLayers.Control.MouseToolbar());
55
    map.addControl(new OpenLayers.Control.LayerSwitcher());
56
    map.addControl(new OpenLayers.Control.MousePosition());
57

    
58
    // get the drag box event
59
	control = new OpenLayers.Control();
60
	OpenLayers.Util.extend(
61
			control, {
62
			    draw: function () {
63
			        // this Handler.Box will intercept the shift-mousedown
64
			        // before Control.MouseDefault gets to see it
65
			        this.box = new OpenLayers.Handler.Box( control,
66
			            {"done": this.notice}
67
		            	//,{keyMask: OpenLayers.Handler.MOD_SPACE}
68
	            	);
69
			        this.box.activate();
70
			    },
71
			    notice: function (bounds) {
72
			    	var min_px;
73
			        var max_px;
74
			        // check that it is a rectangle
75
			        if (bounds.left) { 
76
				        min_px = new OpenLayers.Pixel( bounds.left, bounds.bottom);
77
				        max_px = new OpenLayers.Pixel( bounds.right, bounds.top);
78
					} else {
79
						var tolerance = new OpenLayers.Pixel(3, 3);
80
					    min_px = new OpenLayers.Pixel( bounds.x - tolerance.x, bounds.y + tolerance.y);
81
					    max_px = new OpenLayers.Pixel( bounds.x + tolerance.x, bounds.y - tolerance.y);
82
					}
83
			        var min_ll = map.getLonLatFromPixel(min_px);
84
			        var max_ll = map.getLonLatFromPixel(max_px);
85
			      	//alert("longitude: " + round(mid_ll.lon,3) + " , latitude: " + round(mid_ll.lat,3) );
86
				    url = SERVLET_URL + '?action=spatial_query&xmin='+min_ll.lon+'&ymin='+min_ll.lat+'&xmax='+max_ll.lon+'&ymax='+max_ll.lat+'&skin=' + qformat;
87
				    OpenLayers.ProxyHost = '';
88
				    newwindow = 
89
					    window.open(
90
							    url,
91
							    'queryWin',
92
				                'height=600,width=800,status=yes,toolbar=yes,menubar=no,location=yes,resizable=yes,scrollbars=yes');
93
				
94
			    }
95
	});
96
	map.addControl(control);
97
	
98
	// zoom to center
99
    if (!map.getCenter()) {
100
         map.zoomToMaxExtent();
101
    }
102

    
103
}
104

    
105
// for named location navigation
106
function zoomToLocation(locations) {
107
	var selectedLocation = locations.options[locations.selectedIndex].value;
108
	// add a comma for the rectangle
109
	selectedLocation = selectedLocation.replace(" ", ",")
110
	var bounds = OpenLayers.Bounds.fromString(selectedLocation);
111
    map.zoomToExtent(bounds);
112
}
(2-2/3)