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
    // NOTE: as of Jan 2012, it seems that this WMS service requires basic authentication
31
    //var demis = new OpenLayers.Layer.WMS( "Demis World Map",
32
    //    "http://www2.demis.nl/WMS/wms.asp?wms=WorldMap",
33
    //    {layers: 'Bathymetry,Countries,Topography,Hillshading,Coastlines,Waterbodies,Inundated,Rivers,Streams,Builtup+areas,Railroads,Highways,Roads,Trails,Borders,Cities,Settlements,Airports'} );
34
	
35
	//map.addLayers([demis, ol_wms, world_borders, metacat_points, metacat_bounds]);	
36
	map.addLayers([ol_wms, world_borders, metacat_points, metacat_bounds]);	
37

    
38
	// perhaps a skin has added more layers
39
	if (additionalLayers) {
40
		map.addLayers(additionalLayers);
41
	}
42
	
43
    // off by default
44
	metacat_bounds.setVisibility(false);
45

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

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

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

    
109
}
110

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