Project

General

Profile

« Previous | Next » 

Revision 5845

invoke spatial search when bounding box is drawn or click on map

View differences:

lib/style/common/spatial/map.jsp
47 47
    <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
48 48
    <script type="text/javascript">
49 49
        <!--
50
function round(number,decplaces) {
51
  var multiplier = '1';
52
  for (i=0; i < decplaces; i++ ) {
53
    multiplier = multiplier + '0';
54
  }
55
  var rounded = Math.round(number * parseFloat(multiplier)) / parseFloat(multiplier);
56
  return rounded;
57 50

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

  
60 64
        function init(){
61 65
            var bounds = new OpenLayers.Bounds(-180,-90,180,90);
......
85 89
            /* 
86 90
             *   Other possible WMS base layers to include
87 91
             */
88
			var showAll = false; 
92
			var showAll = true; 
89 93
			if (showAll) {
90 94
	            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
91 95
	                "http://labs.metacarta.com/wms/vmap0",
......
111 115
            //map.addControl(new OpenLayers.Control.PanZoomBar());
112 116
            map.addControl(new OpenLayers.Control.MouseToolbar());
113 117
            map.addControl(new OpenLayers.Control.LayerSwitcher());
118
            map.addControl(new OpenLayers.Control.MousePosition());
114 119
            //map.addControl(new OpenLayers.Control.Permalink());
115 120
            //map.addControl(new OpenLayers.Control.Permalink($('permalink')));
116
            if (!map.getCenter()) map.zoomToMaxExtent();
121
            // get the drag box event
122
			control = new OpenLayers.Control();
123
			OpenLayers.Util.extend(
124
					control, {
125
					    draw: function () {
126
					        // this Handler.Box will intercept the shift-mousedown
127
					        // before Control.MouseDefault gets to see it
128
					        this.box = new OpenLayers.Handler.Box( control,
129
					            {"done": this.notice}
130
				            	//,{keyMask: OpenLayers.Handler.MOD_SPACE}
131
			            	);
132
					        this.box.activate();
133
					    },
134
					    notice: function (bounds) {
135
					    	var min_px;
136
					        var max_px;
137
					        // check that it is a rectangle
138
					        if (bounds.left) { 
139
						        min_px = new OpenLayers.Pixel( bounds.left, bounds.bottom);
140
						        max_px = new OpenLayers.Pixel( bounds.right, bounds.top);
141
							} else {
142
								var tolerance = new OpenLayers.Pixel(3, 3);
143
							    min_px = new OpenLayers.Pixel( bounds.x - tolerance.x, bounds.y + tolerance.y);
144
							    max_px = new OpenLayers.Pixel( bounds.x + tolerance.x, bounds.y - tolerance.y);
145
							}
146
					        var min_ll = map.getLonLatFromPixel(min_px);
147
					        var max_ll = map.getLonLatFromPixel(max_px);
148
					      	//alert("longitude: " + round(mid_ll.lon,3) + " , latitude: " + round(mid_ll.lat,3) );
149
						    url = '<%=SERVLET_URL%>?action=spatial_query&xmin='+min_ll.lon+'&ymin='+min_ll.lat+'&xmax='+max_ll.lon+'&ymax='+max_ll.lat+'&skin=default';
150
						    OpenLayers.ProxyHost = '';
151
						    newwindow = 
152
							    window.open(
153
									    url,
154
									    'queryWin',
155
						                'height=600,width=800,status=yes,toolbar=yes,menubar=no,location=yes,resizable=yes,scrollbars=yes');
156
						
157
					    }
158
			});
159
			map.addControl(control);
160
			
161
			// zoom to center
162
            if (!map.getCenter()) {
163
                 map.zoomToMaxExtent();
164
            }
117 165

  
118
map.events.register('click', map, function (e) {
119
    var tolerance = new OpenLayers.Pixel(3, 3);
120
    var min_px = new OpenLayers.Pixel( e.xy.x - tolerance.x, e.xy.y + tolerance.y);
121
    var max_px = new OpenLayers.Pixel( e.xy.x + tolerance.x, e.xy.y - tolerance.y);
122
    var mid_px = new OpenLayers.Pixel( e.xy.x , e.xy.y );
123
    var min_ll = map.getLonLatFromPixel(min_px);
124
    var max_ll = map.getLonLatFromPixel(max_px);
125
    var mid_ll = map.getLonLatFromPixel(mid_px);
126
    //alert("longitude:&nbsp; " + round(mid_ll.lon,3) + " , latitude:&nbsp; " + round(mid_ll.lat,3) );
127
    url = '<%=SERVLET_URL%>?action=spatial_query&xmin='+min_ll.lon+'&ymin='+min_ll.lat+'&xmax='+max_ll.lon+'&ymax='+max_ll.lat+'&skin=default';
128
    OpenLayers.ProxyHost = '';
129
    newwindow = window.open(url,'queryWin',
130
                  'height=600,width=800,status=yes,toolbar=yes,menubar=no,location=yes,resizable=yes,scrollbars=yes');
131

  
132
});
133

  
134 166
        }
135 167
        // -->
136 168
    </script>

Also available in: Unified diff