Project

General

Profile

« Previous | Next » 

Revision 5858

break the map generation into parts for easier re-use/customization in other skins

View differences:

lib/style/common/spatial/map.jsp
1 1
<%@ page language="java" %>
2
<%@page import="edu.ucsb.nceas.metacat.util.GeoserverUtil"%>
2 3
<!--
3 4
/**
4 5
  *  '$RCSfile$'
......
31 32
<%@ include file="../common-settings.jsp"%>
32 33
<%@ include file="../configure-check.jsp"%>
33 34
<%
34
	String GEOSERVER_URL = SERVER_URL + "/geoserver";
35
	String GEOSERVER_URL = GeoserverUtil.getGeoserverContextURL();
35 36
%>
36 37
<!-- *********************** START Map ************************* -->
37
<html xmlns="http://www.w3.org/1999/xhtml">
38
<html>
38 39
  <head>
39 40
    <style type="text/css">
40 41
        body { background-color:white; }
......
45 46
        }
46 47
    </style>
47 48
    <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
49
    <script src="<%=STYLE_COMMON_URL%>/spatial/map.js"></script>
48 50
    <script type="text/javascript">
49
        <!--
50

  
51
        // for turning on and off the spatial search control
52
		var control;
53
        var map;
54
        
55
		function round(number,decplaces) {
56
		  var multiplier = '1';
57
		  for (i=0; i < decplaces; i++ ) {
58
		    multiplier = multiplier + '0';
59
		  }
60
		  var rounded = Math.round(number * parseFloat(multiplier)) / parseFloat(multiplier);
61
		  return rounded;
62
		
63
		}
64

  
65
        function init(){
51
        function init() {
66 52
            var bounds = new OpenLayers.Bounds(-180,-90,180,90);
67
            map = new OpenLayers.Map('map', { 'maxExtent':bounds, 'maxResolution':'auto'});
68
            //var map = new OpenLayers.Map('map', { controls: [] });
69

  
70
            var metacat_points = new OpenLayers.Layer.WMS( "Metacat Doc Points",
71
                "<%=GEOSERVER_URL%>/wms",
72
                {layers: "data_points",
73
                 transparent: "true", format: "image/gif"} );
74

  
75
            var metacat_bounds = new OpenLayers.Layer.WMS( "Metacat Doc Bounds",
76
                "<%=GEOSERVER_URL%>/wms",
77
                {layers: "data_bounds",
78
                 transparent: "true", format: "image/gif"} );
79

  
80
            var world_borders = new OpenLayers.Layer.WMS( "World Borders",
81
                "<%=GEOSERVER_URL%>/wms",
82
                {layers: "world_borders",
83
                 format: "image/jpeg"} );
84

  
85
            var sanparks_boundaries = new OpenLayers.Layer.WMS( "SANParks Boundaries",
86
                    "<%=GEOSERVER_URL%>/wms",
87
                    {layers: "SANParks_Boundaries_gcs_wgs84",
88
                     transparent: "true", format: "image/gif"} );
89

  
90
            /* 
91
             *   Other possible WMS base layers to include
92
             */
93
			var showAll = true; 
94
			if (showAll) {
95
	            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
96
	                "http://labs.metacarta.com/wms/vmap0",
97
	                {layers: 'basic'} );
98
	
99
	            var jpl_wms = new OpenLayers.Layer.WMS( "NASA Landsat Mosaic",
100
	                "http://wms.jpl.nasa.gov/wms.cgi", 
101
	                {layers: "modis,global_mosaic"});
102
	
103
	            var demis = new OpenLayers.Layer.WMS( "Demis World Map",
104
	                "http://www2.demis.nl/WMS/wms.asp?wms=WorldMap",
105
	                {layers: 'Bathymetry,Countries,Topography,Hillshading,Coastlines,Waterbodies,Inundated,Rivers,Streams,Builtup+areas,Railroads,Highways,Roads,Trails,Borders,Cities,Settlements,Airports'} );
106
	
107
	            jpl_wms.setVisibility(false);
108
	            ol_wms.setVisibility(false);
109
	            demis.setVisibility(false);
110

  
111
            	map.addLayers([world_borders, sanparks_boundaries, jpl_wms, ol_wms, demis, metacat_points, metacat_bounds]);
112
			}
113
			else {
114
	            map.addLayers([world_borders, sanparks_boundaries, metacat_points, metacat_bounds]);
115
			}
116
            //map.addControl(new OpenLayers.Control.PanZoomBar());
117
            map.addControl(new OpenLayers.Control.MouseToolbar());
118
            map.addControl(new OpenLayers.Control.LayerSwitcher());
119
            map.addControl(new OpenLayers.Control.MousePosition());
120
            //map.addControl(new OpenLayers.Control.Permalink());
121
            //map.addControl(new OpenLayers.Control.Permalink($('permalink')));
122
            // get the drag box event
123
			control = new OpenLayers.Control();
124
			OpenLayers.Util.extend(
125
					control, {
126
					    draw: function () {
127
					        // this Handler.Box will intercept the shift-mousedown
128
					        // before Control.MouseDefault gets to see it
129
					        this.box = new OpenLayers.Handler.Box( control,
130
					            {"done": this.notice}
131
				            	//,{keyMask: OpenLayers.Handler.MOD_SPACE}
132
			            	);
133
					        this.box.activate();
134
					    },
135
					    notice: function (bounds) {
136
					    	var min_px;
137
					        var max_px;
138
					        // check that it is a rectangle
139
					        if (bounds.left) { 
140
						        min_px = new OpenLayers.Pixel( bounds.left, bounds.bottom);
141
						        max_px = new OpenLayers.Pixel( bounds.right, bounds.top);
142
							} else {
143
								var tolerance = new OpenLayers.Pixel(3, 3);
144
							    min_px = new OpenLayers.Pixel( bounds.x - tolerance.x, bounds.y + tolerance.y);
145
							    max_px = new OpenLayers.Pixel( bounds.x + tolerance.x, bounds.y - tolerance.y);
146
							}
147
					        var min_ll = map.getLonLatFromPixel(min_px);
148
					        var max_ll = map.getLonLatFromPixel(max_px);
149
					      	//alert("longitude: " + round(mid_ll.lon,3) + " , latitude: " + round(mid_ll.lat,3) );
150
						    url = '<%=SERVLET_URL%>?action=spatial_query&xmin='+min_ll.lon+'&ymin='+min_ll.lat+'&xmax='+max_ll.lon+'&ymax='+max_ll.lat+'&skin=default';
151
						    OpenLayers.ProxyHost = '';
152
						    newwindow = 
153
							    window.open(
154
									    url,
155
									    'queryWin',
156
						                'height=600,width=800,status=yes,toolbar=yes,menubar=no,location=yes,resizable=yes,scrollbars=yes');
157
						
158
					    }
159
			});
160
			map.addControl(control);
161
			
162
			// zoom to center
163
            if (!map.getCenter()) {
164
                 map.zoomToMaxExtent();
165
            }
166

  
53
            // make the map for this skin
54
            initMap("<%=GEOSERVER_URL%>", "<%=SERVLET_URL%>", "default", bounds);
167 55
        }
168
        
169
        // for named location navigation
170
        function zoomToLocation(locations) {
171
			var selectedLocation = locations.options[locations.selectedIndex].value;
172
			// add a comma for the rectangle
173
			selectedLocation = selectedLocation.replace(" ", ",")
174
			var bounds = OpenLayers.Bounds.fromString(selectedLocation);
175
            map.zoomToExtent(bounds);
176
        }
177
        // -->
178 56
    </script>
179 57
  </head>
180 58
  <body onload="init()">
181
    <!-- <a style="float:right" href="" id="permalink">Permalink</a> -->
182 59
    <div id="map"></div>
183 60
	<div id="featureList">
184 61
		<form>
lib/style/common/spatial/map.js
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
}
0 118

  

Also available in: Unified diff