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

    
106
	// some built-in controls
107
	//map.addControl(new OpenLayers.Control.NavToolbar());
108
	map.addControl(new OpenLayers.Control.LayerSwitcher());
109
	map.addControl(new OpenLayers.Control.MousePosition());
110

    
111
	// zoom to center
112
    if (!map.getCenter()) {
113
         map.zoomToMaxExtent();
114
    }
115

    
116
}
117

    
118
// for named location navigation
119
function zoomToLocation(locations) {
120
	var selectedLocation = locations.options[locations.selectedIndex].value;
121
	// add a comma for the rectangle
122
	selectedLocation = selectedLocation.replace(" ", ",")
123
	var bounds = OpenLayers.Bounds.fromString(selectedLocation);
124
    map.zoomToExtent(bounds);
125
}
(2-2/5)