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
	var showAll = true; 
35
	if (showAll) {
36
        var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
37
            "http://labs.metacarta.com/wms/vmap0",
38
            {layers: 'basic'} );
39

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

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

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

    
52
    	map.addLayers([world_borders, sanparks_boundaries, jpl_wms, ol_wms, demis, metacat_points, metacat_bounds]);
53
	}
54
	else {
55
        map.addLayers([world_borders, sanparks_boundaries, metacat_points, metacat_bounds]);
56
	}
57

    
58
	// some built-in controls
59
	map.addControl(new OpenLayers.Control.MouseToolbar());
60
    map.addControl(new OpenLayers.Control.LayerSwitcher());
61
    map.addControl(new OpenLayers.Control.MousePosition());
62

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