Project

General

Profile

« Previous | Next » 

Revision 5858

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

View differences:

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>

Also available in: Unified diff