1 |
5858
|
leinfelder
|
// global variables for the map
|
2 |
|
|
var map;
|
3 |
|
|
var control;
|
4 |
|
|
|
5 |
5934
|
leinfelder
|
function initMap(GEOSERVER_URL, SERVLET_URL, qformat, bounds, additionalLayers) {
|
6 |
5858
|
leinfelder
|
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 |
5864
|
leinfelder
|
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
27 |
|
|
"http://labs.metacarta.com/wms/vmap0",
|
28 |
|
|
{layers: 'basic'} );
|
29 |
5858
|
leinfelder
|
|
30 |
5864
|
leinfelder
|
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 |
5858
|
leinfelder
|
|
34 |
5936
|
leinfelder
|
map.addLayers([demis, ol_wms, world_borders, metacat_points, metacat_bounds]);
|
35 |
5858
|
leinfelder
|
|
36 |
5934
|
leinfelder
|
// perhaps a skin has added more layers
|
37 |
|
|
if (additionalLayers) {
|
38 |
|
|
map.addLayers(additionalLayers);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
5858
|
leinfelder
|
// get the drag box event
|
42 |
5928
|
leinfelder
|
//control = new OpenLayers.Control();
|
43 |
5932
|
leinfelder
|
control = new OpenLayers.Control({title: "Metacat spatial query", displayClass: "spatialQuery"});
|
44 |
5858
|
leinfelder
|
OpenLayers.Util.extend(
|
45 |
|
|
control, {
|
46 |
|
|
draw: function () {
|
47 |
|
|
// this Handler.Box will intercept the shift-mousedown
|
48 |
|
|
// before Control.MouseDefault gets to see it
|
49 |
|
|
this.box = new OpenLayers.Handler.Box( control,
|
50 |
5928
|
leinfelder
|
{"done": this.notice}
|
51 |
|
|
//,{keyMask: OpenLayers.Handler.MOD_SHIFT}
|
52 |
|
|
);
|
53 |
5858
|
leinfelder
|
this.box.activate();
|
54 |
|
|
},
|
55 |
|
|
notice: function (bounds) {
|
56 |
|
|
var min_px;
|
57 |
|
|
var max_px;
|
58 |
|
|
// check that it is a rectangle
|
59 |
|
|
if (bounds.left) {
|
60 |
|
|
min_px = new OpenLayers.Pixel( bounds.left, bounds.bottom);
|
61 |
|
|
max_px = new OpenLayers.Pixel( bounds.right, bounds.top);
|
62 |
|
|
} else {
|
63 |
|
|
var tolerance = new OpenLayers.Pixel(3, 3);
|
64 |
|
|
min_px = new OpenLayers.Pixel( bounds.x - tolerance.x, bounds.y + tolerance.y);
|
65 |
|
|
max_px = new OpenLayers.Pixel( bounds.x + tolerance.x, bounds.y - tolerance.y);
|
66 |
|
|
}
|
67 |
|
|
var min_ll = map.getLonLatFromPixel(min_px);
|
68 |
|
|
var max_ll = map.getLonLatFromPixel(max_px);
|
69 |
|
|
//alert("longitude: " + round(mid_ll.lon,3) + " , latitude: " + round(mid_ll.lat,3) );
|
70 |
|
|
url = SERVLET_URL + '?action=spatial_query&xmin='+min_ll.lon+'&ymin='+min_ll.lat+'&xmax='+max_ll.lon+'&ymax='+max_ll.lat+'&skin=' + qformat;
|
71 |
|
|
OpenLayers.ProxyHost = '';
|
72 |
|
|
newwindow =
|
73 |
|
|
window.open(
|
74 |
|
|
url,
|
75 |
|
|
'queryWin',
|
76 |
|
|
'height=600,width=800,status=yes,toolbar=yes,menubar=no,location=yes,resizable=yes,scrollbars=yes');
|
77 |
|
|
|
78 |
|
|
}
|
79 |
|
|
});
|
80 |
5928
|
leinfelder
|
var tb = OpenLayers.Class(OpenLayers.Control.NavToolbar, {
|
81 |
|
|
initialize: function() {
|
82 |
|
|
var options = null;
|
83 |
|
|
OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]);
|
84 |
|
|
this.addControls([
|
85 |
|
|
new OpenLayers.Control.Navigation({'zoomWheelEnabled': false}),
|
86 |
|
|
new OpenLayers.Control.ZoomBox(),
|
87 |
|
|
control
|
88 |
|
|
]);
|
89 |
|
|
}
|
90 |
|
|
});
|
91 |
|
|
map.addControl(new tb());
|
92 |
|
|
//map.addControl(control);
|
93 |
|
|
|
94 |
|
|
// some built-in controls
|
95 |
|
|
//map.addControl(new OpenLayers.Control.NavToolbar());
|
96 |
|
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
97 |
|
|
map.addControl(new OpenLayers.Control.MousePosition());
|
98 |
|
|
|
99 |
5858
|
leinfelder
|
// zoom to center
|
100 |
|
|
if (!map.getCenter()) {
|
101 |
|
|
map.zoomToMaxExtent();
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
// for named location navigation
|
107 |
|
|
function zoomToLocation(locations) {
|
108 |
|
|
var selectedLocation = locations.options[locations.selectedIndex].value;
|
109 |
|
|
// add a comma for the rectangle
|
110 |
|
|
selectedLocation = selectedLocation.replace(" ", ",")
|
111 |
|
|
var bounds = OpenLayers.Bounds.fromString(selectedLocation);
|
112 |
|
|
map.zoomToExtent(bounds);
|
113 |
|
|
}
|