PageSourceSearch

https://polardata.ca/pdcsearch/js/main-actions.js

js polardata.ca collected 2026-10-02 07:09:14 UTC 9,173 bytes, 272 lines download raw bytes

1
2// Convert OpenLayers.Geometry.LinearRing to OpenLayers.Feature.Vector
3function openConvert(linear_ring) {
4	var open_poly = new OpenLayers.Geometry.Polygon([linear_ring]);
5	var open_vector_of_interest = new OpenLayers.Feature.Vector(open_poly,null,default_style);
6	return open_vector_of_interest;
7}
8
9// Convert arrays of coordinates to OpenLayers.Geometry.LinearRing
10function openConvertLinear(xCoords, yCoords, n) {		
11   var src = projGlobal, dest, xTemp;
12   var open_points = new Array();  // applied to store four points rechieved from Oracle
13   var open_MutiplePoints = new Array(); // store points used to create polygon in openlayer 
14   dest = projArctic;
15	if (n == 0) {
16     	dest = projArctic;
17  	} else if (n == 1) {
18     	dest = projAntarctic;
19  	}
20	//create polygons with arc boundaries
21	for (var i = 0; i < xCoords.length; i ++) { //? assume xcoords and ycoords are the same?
22		open_points[i] = new OpenLayers.Geometry.Point(xCoords[i], yCoords[i]);
23		 // alert(xCoords[i]+"  "+ yCoords[i]);//testing code
24		if (i>0) {   // create points between point[i-1] and point[i] in order to make arc-like boundaries
25			if ((open_points[i].y - open_points[i-1].y) > -0.0001 && (open_points[i].y - open_points[i-1].y)<0.0001){ //ensure two points has the same lat coordinates
26				xTemp = open_points[i].x - open_points[i-1].x;
27				// alert ("xTemp = "+ xTemp );//testing code
28				if (xTemp >0){
29					for (var j=0; j<xTemp; j++){  // add one point for one lontitude degree
30						open_MutiplePoints.push(new OpenLayers.Geometry.Point( open_points[i-1].x + j, yCoords[i] ));
31					}
32				}
33				else{     
34					xTemp = -xTemp;
35					for (var j=0; j<xTemp; j++){
36						open_MutiplePoints.push(new OpenLayers.Geometry.Point(open_points[i-1].x - j, yCoords[i]));
37					}
38				}
39
40			}
41		}
42		open_MutiplePoints.push(new OpenLayers.Geometry.Point(xCoords[i], yCoords[i]));
43	}
44	//testing code alert(open_MutiplePoints.length);
45	for (var i =0; i < open_MutiplePoints.length; i++){
46		OpenLayers.Projection.transform(open_MutiplePoints[i], src, dest); 
47		if (open_MutiplePoints[i] == null ) return null;
48	}
49
50	open_MutiplePoints.push(open_MutiplePoints[0]);  // create a closed ring 
51	var open_ring = new OpenLayers.Geometry.LinearRing(open_MutiplePoints);
52	return open_ring; 
53}
54
55
56//Generate the footprint (polygon and tear drop) of a metadata RECORD
57//@param ID: recordId
58// Jan 25 2013
59//This code has been called from the result jsp directly!
60function pushSelectionValues(ID, coordString) {
61	var n = getActiveMapNumber();
62	var check = true;
63	var vector;
64	var wkt;
65	var pfeature; 
66	var src = projGlobal, dest;
67	// Check if the footprint for this metadata set already exists
68	if (resultsIdArrays[n].length > 0) {
69		for (var i = 0; i < resultsIdArrays[n].length; i ++) {
70			if (resultsIdArrays[n][i] == ID) {
71				check = false;
72				break;
73			}
74		}
75	}
76	// if the footprint does not exist
77	
78	if (check == true) {
79		wkt = new OpenLayers.Format.WKT();
80 		pfeature = wkt.read(coordString);
81 		if (pfeature)
82 			{
83 			pfeature.style = default_style;
84 			
85 	 		dest = projArctic;
86 	 		if (n == 0) {
87 	 	     	dest = projArctic;
88 	 	  	} else if (n == 1) {
89 	 	     	dest = projAntarctic;
90 	 	  	}
91 	 		//
92 	 		pfeature.geometry.transform(src, dest); 
93 			vector = pfeature; 
94 			//alert("vector: "+vector.geometry);
95 			}
96 		else
97 			{
98 			var coords = coordString.split(";");
99 	 		var xCoords = new Array();
100 	 		var yCoords = new Array();
101 	 		for (var i = 0, j = 1; i < coords.length; i += 2, j += 2) {
102 	       		xCoords[i / 2] = parseFloat(coords[i]);
103 	       		yCoords[j / 2 - 0.5] = parseFloat(coords[j]);
104 	       }
105 	 	// make sure the (-90,90,180,-180) is display on the map
106 	      	dest = projArctic;
107 	      	if (n == 0) {
108 	      		dest = projArctic;
109 	      		for (var ia =0; ia < yCoords.length; ia++){
110 	      			if (yCoords[ia]<0) yCoords[ia] = 0;
111 	      		}
112 	      	} else if (n == 1) {
113 	      		dest = projAntarctic;
114 	      		for (var ia =0; ia < yCoords.length; ia++){
115 	      			if (yCoords[ia]>0) yCoords[ia] = 0;
116 	      		}
117 	      	}
118
119 	     //Check if coordinates belong to active map, if not do nothing
120 	 		pfeature = openConvertLinear(xCoords, yCoords, n);
121 	 		vector = openConvert(pfeature);
122 	 		//alert(vector.geometry);
123 	 		
124 			}
125 		
126 		if (pfeature!=null) {
127 			resultsIdArrays[n].push(ID);
128 			resultsVectorArrays[n].push(vector);
129	      	var point =vector.geometry.getCentroid();// new OpenLayers.Geometry.Point((xCoords[0] + xCoords[2]) / 2, (yCoords[0] + yCoords[2]) / 2);
130	      	var marker = new OpenLayers.Feature.Vector(point);
131          	resultsMarkerArrays[n].push(marker);
132      		// Draw the footprint
133          	resultsLayers[n].addFeatures([vector]);
134          	resultsLayers[n].drawFeature(vector, select_style);
135          	resultsLayers[n].addFeatures([marker]);
136          	resultsLayers[n].drawFeature(marker, resultsMarkerSelectStyle);
137 		}
138	}
139}
140
141//Remove a footprint of a metadata set
142function removeSelectionFromArray(ID) {
143   var n = getActiveMapNumber();
144   // Check if this footprint exists, if it exists,remove it
145	if (resultsIdArrays[n].length > 0) {
146		for (var position = 0; position < resultsIdArrays[n].length; position ++) {
147			if (resultsIdArrays[n][position] == ID) {
148				resultsLayers[n].removeFeatures([resultsVectorArrays[n][position]]);
149				resultsIdArrays[n].splice(position, 1);
150				resultsVectorArrays[n].splice(position, 1);
151				resultsLayers[n].removeFeatures([resultsMarkerArrays[n][position]]);
152				resultsMarkerArrays[n].splice(position, 1);
153				break;
154			}
155		}
156	}
157}
158
159
160// Called when user clicks on the map
161// A polygon representing the user's selection is drawn on the map
162function drawUniversalSelection(n) {
163	points.length = 0;
164   selectionMarkerLayers[n].clearMarkers(); 
165	for (var i = 0; i < lonlats[n].length; i ++) {
166      if (lonlats[n][i] != null) {
167         var marker = new OpenLayers.Marker(new OpenLayers.LonLat(lonlats[n][i].lon, lonlats[n][i].lat), new OpenLayers.Icon("images/ccin/target2.png", icon_size));
168         selectionMarkerLayers[n].addMarker(marker);
169   		var p = new OpenLayers.Geometry.Point(lonlats[n][i].lon, lonlats[n][i].lat);
170   		points.push(p);
171      }		
172	}
173				
174	if (lonlats[n].length > 1) {
175		points.push(points[0]);
176	}
177
178	points_ring = new OpenLayers.Geometry.LinearRing(points);
179	area_of_interest_polygon = new OpenLayers.Geometry.Polygon(points_ring);	
180	area_of_interest_feature = new OpenLayers.Feature.Vector(area_of_interest_polygon,null,vector_style);
181	polygonLayers[n].destroyFeatures();
182	polygonLayers[n].addFeatures([area_of_interest_feature]);
183}
184
185// Set the values of the HTML elements which store
186// the longitudes and latitudes of the points selected by the user
187function setOutputPoints(n) {
188   var src; 
189   src = projArctic;
190   if (n == 0) {
191      src = projArctic;
192   } else if (n == 1){
193      src = projAntarctic;
194   }
195  
196   var dest = projGlobal; 
197	for (var i = 0; i < 4; i ++) {
198		var num = (i + 1).toString();
199      if (i < lonlats[n].length) {
200         var point = new OpenLayers.Geometry.Point(lonlats[n][i].lon, lonlats[n][i].lat);
201       
202         OpenLayers.Projection.transform(point, src, dest); 
203       
204   		document.getElementById("lon_" + num).value = point.x;
205   		document.getElementById("lat_" + num).value = point.y;
206      } else {
207   		document.getElementById("lon_" + num).value = "";
208   		document.getElementById("lat_" + num).value = "";         
209      }		
210	}
211	  
212}
213//Created by Freddy Paya
214// when clicking the search button, the function checks that the coordinates on the form correlate to the tab the user is on (arctic OR antarctic)
215function checkCoords(n) {
216	var n = getActiveMapNumber();    
217	var src; 
218	   src = projArctic;
219	   if (n == 0) {
220	      src = projArctic;
221	   } else if (n == 1){
222	      src = projAntarctic;
223	   }
224	  
225	   var dest = projGlobal; 
226	  
227		var lat = [];
228		var long = [];
229		var latform = [];
230		var longform = [];
231		var diff = 0;
232		
233		
234		if (n==0 || n==1)
235			{
236		
237		for (var i = 0; i < 4; i ++) {
238			var num = (i + 1).toString();
239				 		
240	      if (i < lonlats[n].length) {
241	         var point = new OpenLayers.Geometry.Point(lonlats[n][i].lon, lonlats[n][i].lat);
242	      
243	         OpenLayers.Projection.transform(point, src, dest); 
244	       long[i] = point.x;
245	         lat[i] = point.y;
246	   		
247	    
248	         longform[i] = document.getElementById("lon_" + num).value;
249	         latform[i] = document.getElementById("lat_" + num).value;
250	         
251	         
252	      } 
253		diff = lat[0] - latform[0];
254		
255		if (diff>40 || diff<-40){
256			Ext.MessageBox.alert('Search Error', 'Note: The Search is using coordinates from the map. To update the Latitude/Longitude values to match the box on the map, please click the Update Points button in the right panel.');
257			return false;
258			}
259		}
260		
261	}
262		
263
264}
265
266function frameRefresh() {
267	//document.getElementById('results').src = "";
268	document.getElementById('searchoptions').src = "search.jsp";
269}
270
271
272

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.