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 demis = new OpenLayers.Layer.WMS( "Demis World Map",
31
        "http://www2.demis.nl/WMS/wms.asp?wms=WorldMap",
32
        {layers: 'Bathymetry,Countries,Topography,Hillshading,Coastlines,Waterbodies,Inundated,Rivers,Streams,Builtup+areas,Railroads,Highways,Roads,Trails,Borders,Cities,Settlements,Airports'} );
33

    
34
	map.addLayers([demis, ol_wms, world_borders, metacat_points, metacat_bounds]);	
35

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

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

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

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

    
107
}
108

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