-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplanetmap.events.js
More file actions
318 lines (294 loc) · 11.1 KB
/
Copy pathplanetmap.events.js
File metadata and controls
318 lines (294 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
var zoomBox;
var navHistory;
var zoomToContextExtent;
var featureInfo;
var featureInfo1;
var featureInfo2;
var featureInfo3;
var featureInfo4;
var measureControls;
function handleMeasurements(event) {
//var geometry = event.geometry;
var units = event.units;
var order = event.order;
var measure = event.measure;
var element = document.getElementById('mapOutput');
var out = "";
// vincenty constants modified to use mars constants, OpenLayers.js line 242
if(order == 1) {
out += "Distance: " + measure.toFixed(3) + " " + units; // distance can be fixed simply by using geodesic: true
} else {
out += "<span class='mapAreaOutput'>Area: " + measure.toFixed(3) + " " + units + "<sup style='font-size:6px'>2</" + "sup></span>"; // area fix inside OpenLayers.js line 870, replaced earth radius by mars radius
}
element.innerHTML = out;
}
function toggleQueryMode1()
{
if(featureInfo1.active) {
queryEventHandler1.activate();
}
else {
queryEventHandler1.deactivate();
}
}
function toggleQueryMode2()
{
if(featureInfo2.active) {
queryEventHandler2.activate();
}
else {
queryEventHandler2.deactivate();
}
}
function toggleQueryMode3()
{
if(featureInfo3.active) {
queryEventHandler3.activate();
}
else {
queryEventHandler3.deactivate();
}
}
function toggleQueryMode4()
{
if(featureInfo4.active) {
queryEventHandler4.activate();
}
else {
queryEventHandler4.deactivate();
}
}
function setUrlParamsFromPixel(pixel)
{
lonlat = map.getLonLatFromPixel(pixel);
urlparams['lat'] = lonlat.lat;
urlparams['lon'] = lonlat.lon;
urlparams['region'] = getRegion(lonlat);
urlparams['productid'] = getProduct(lonlat);
}
function initmapevents()
{
// Used by addspectrum() and chooseratio() in the console
map.events.register("mousemove", map, function(e)
{
setUrlParamsFromPixel(new OpenLayers.Pixel(e.xy.x,e.xy.y));
setUrlHash();
});
map.events.register("mouseout", map, function(e)
{
location.hash = ""
});
zoomBox = new OpenLayers.Control.ZoomBox({ title: "Zoom in box" });
navHistory = new OpenLayers.Control.NavigationHistory();
navHistory.previous.title = "View history backward";
navHistory.next.title = "View history forward";
map.addControl(navHistory);
// build the Select functionality
featureInfo = new OpenLayers.Control({
displayClass: "olControlFeatureInfo",
title: "Select"
});
// build the Spectrum functionality
featureInfo1 = new OpenLayers.Control({
displayClass: "olControlFeatureInfo1",
title: "Spectrum"
});
// register events to the spectrum tool
featureInfo1.events.register("activate", featureInfo1, function() { toggleQueryMode1(); });
featureInfo1.events.register("deactivate", featureInfo1, function() { toggleQueryMode1(); });
// build the spectral ratio functionality
featureInfo2 = new OpenLayers.Control({
displayClass: "olControlFeatureInfo2",
title: "Spectral ratio"
});
// register events to the Spectral ratio tool
featureInfo2.events.register("activate", featureInfo2, function() { toggleQueryMode2(); });
featureInfo2.events.register("deactivate", featureInfo2, function() { toggleQueryMode2(); });
// build the cross functionality
featureInfo3 = new OpenLayers.Control({
displayClass: "olControlFeatureInfo3",
title: "Cross section"
});
// register events to the cross tool
featureInfo3.events.register("activate", featureInfo3, function() { toggleQueryMode3(); });
featureInfo3.events.register("deactivate", featureInfo3, function() { toggleQueryMode3(); });
// build the cross functionality
featureInfo4 = new OpenLayers.Control({
displayClass: "olControlFeatureInfo4",
title: "Elevation point"
});
// register events to the cross tool
featureInfo4.events.register("activate", featureInfo4, function() { toggleQueryMode4(); });
featureInfo4.events.register("deactivate", featureInfo4, function() { toggleQueryMode4(); });
zoomToContextExtent = new OpenLayers.Control.Button({
title: "Full scale", displayClass: "olControlZoomToMaxExtent", trigger: function(){ map.zoomToExtent(maxextent); }
});
// build the measure controls
var optionsLine = {
handlerOptions: {
persist: true
},
displayClass: "olControlMeasureDistance",
title: "Measure Distance"
};
var optionsPolygon = {
handlerOptions: {
persist: true
},
displayClass: "olControlMeasureArea",
title: "Measure Area"
};
measureControls = {
line: new OpenLayers.Control.Measure(
OpenLayers.Handler.Path,
optionsLine
),
polygon: new OpenLayers.Control.Measure(
OpenLayers.Handler.Polygon,
optionsPolygon
)
};
for(var key in measureControls) {
control = measureControls[key];
control.geodesic = true; // set true to use geodesic coordinates
//control.setImmediate(true); // set true to immediately compute the area/length as soon as the mouse is moved
control.events.on({
"measure": handleMeasurements,
"measurepartial": handleMeasurements
});
}
// create a new event handler for single click query
queryEventHandler1 = new OpenLayers.Handler.Click({ 'map': map }, { 'click': function(e){
fire(e);
}});
queryEventHandler2 = new OpenLayers.Handler.Click({ 'map': map }, { 'click': function(e){
fire2(e);
}});
queryEventHandler3 = new OpenLayers.Handler.Click({ 'map': map }, { 'click': function(e){
fire3(e);
}});
queryEventHandler4 = new OpenLayers.Handler.Click({ 'map': map }, { 'click': function(e){
fire4(e);
}});
function fire(e)
{
// draw spectra
var lonlat = map.getLonLatFromPixel(e.xy);
var lon = lonlat.lon;
var lat = lonlat.lat;
//vector_layer2.destroyFeatures(); // destroy the points from spectral ratio
if(getxspectrum(lon,lat))
{
var origin = {x:lon, y:lat};
var circleout = new OpenLayers.Geometry.Polygon.createRegularPolygon(origin, pointsize, 50);
var circle = new OpenLayers.Feature.Vector(circleout, {fcolor: colors[pos]});
vector_layer.addFeatures(circle);
pos++;
if (pos == nrclicks) {
pos = 0; // wrap around
}
}
}
function fire2(e)
{
// ratio
var lonlat = map.getLonLatFromPixel(e.xy);
var lon = lonlat.lon;
var lat = lonlat.lat;
vector_layer2.destroyFeatures(); // destroy the points from the series
if(getyspectrum(lon,lat))
{
var origin = {x:lon, y:lat};
var circleout = new OpenLayers.Geometry.Polygon.createRegularPolygon(origin, pointsize, 50);
vector_layer2.addFeatures(new OpenLayers.Feature.Vector(circleout));
}
}
function fire3(e)
{
// destroy the points from other functions
vector_layer.destroyFeatures();
vector_layer2.destroyFeatures();
vector_layer4.destroyFeatures();
var lonlat = map.getLonLatFromPixel(e.xy);
var xmin = dtmdataset.xmin;
var xmax = dtmdataset.xmax;
var ymin = dtmdataset.ymin;
var ymax = dtmdataset.ymax;
// if you click within the extent of the imagedtm layer:
if((lonlat.lon >= xmin) && (lonlat.lon <= xmax) && (lonlat.lat >= ymin) && (lonlat.lat <= ymax))
{
var origin = {x:lonlat.lon, y:lonlat.lat};
var circleout = new OpenLayers.Geometry.Polygon.createRegularPolygon(origin, pointsize, 50);
vector_layer3.addFeatures(new OpenLayers.Feature.Vector(circleout));
if (crossturn == 1) { // this is our second set of data needed for the cross
// add a line joining the two points
var points = new Array(
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat),
new OpenLayers.Geometry.Point(dtmdataset.templonlat.lon, dtmdataset.templonlat.lat)
);
var line = new OpenLayers.Geometry.LineString(points);
vector_layer3.addFeatures(new OpenLayers.Feature.Vector(line));
var lon1 = dtmdataset.templonlat.lon;
var lat1 = dtmdataset.templonlat.lat;
var lon2 = lonlat.lon;
var lat2 = lonlat.lat;
$('#loader').show();
crosssection(lon1,lat1,lon2,lat2);
crossturn = 0; // reset turn to 0
}
else { // crossturn is equal to 0
crossturn++; // increase turn count
dtmdataset.templonlat = lonlat; // to keep track of the first set of data
}
return true;
}
else
{
return false;
}
}
function fire4(e)
{
// destroy the points from other functions
//vector_layer.destroyFeatures();
//vector_layer2.destroyFeatures();
//vector_layer3.destroyFeatures();
var lonlat = map.getLonLatFromPixel(e.xy);
var xmin = dtmdataset.xmin;
var xmax = dtmdataset.xmax;
var ymin = dtmdataset.ymin;
var ymax = dtmdataset.ymax;
// if you click within the extent of the imagedtm layer:
if((lonlat.lon >= xmin) && (lonlat.lon <= xmax) && (lonlat.lat >= ymin) && (lonlat.lat <= ymax))
{
//var origin = {x:lonlat.lon, y:lonlat.lat};
//var circleout = new OpenLayers.Geometry.Polygon.createRegularPolygon(origin, pointsize, 50);
//vector_layer4.addFeatures(new OpenLayers.Feature.Vector(circleout));
//$('#loader').show();
alert(getz(lonlat.lon,lonlat.lat));
}
}
}
function inithsmapevents()
{
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
},
});
click = new OpenLayers.Control.Click();
map.addControl(click);
click.activate();
}