source: src/webapp/webclient/js/GnuBoat.js@ 949f66d

debian/bullseye debian/jessie
Last change on this file since 949f66d was 563c04b, checked in by Joachim Langenbach <joachim.langenbach@…>, 9 years ago
  • Fixed shutdown messages
  • Added two message style class (info and error)
  • Property mode set to 100644
File size: 19.6 KB
Line 
1/*
2
3 Copyright (C) 2016 - 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 MA 02110-1301 USA.
19
20*/
21
22/** @namespace GnuBoat JavaScript namespace */
23var GnuBoat = GnuBoat || {};
24
25/**
26 * @brief Sets the webservice base url, used by any other functions
27 */
28GnuBoat.setServer = function(baseUrl)
29{
30 if(baseUrl.slice(-1) != "/")
31 baseUrl += "/";
32 GnuBoat.private.serverBaseUrl = baseUrl;
33
34 var link = document.createElement("a");
35 link.setAttribute("href", baseUrl);
36 $("#opencpnHint").empty();
37 $("<p>To connect OpenCPN with the GPSD running on this webservice, use <b>"+ link.hostname +":2947</b> and <b>"+ link.hostname +":2597</b> for the messages recieved on NMEA2000 bus.</p>").appendTo("#opencpnHint");
38}
39
40/**
41 * @brief Used to display user messages
42 */
43GnuBoat.displayMessage = function(text)
44{
45 $("#message").empty();
46 $(text).appendTo("#message");
47 location.hash = "#messages";
48}
49
50/**
51 * @brief Fetches the data shown in the display area from the webservice
52 */
53GnuBoat.displayDataGet = function()
54{
55 if(GnuBoat.private.serverBaseUrl == null){
56 GnuBoat.displayMessage("No server set/found");
57 return;
58 }
59 var gnuboatApi = GnuBoat.private.serverBaseUrl;
60 $.getJSON(gnuboatApi, GnuBoat.private.displayDataSet);
61};
62
63/**
64 * @brief Gets the metadata of all maps, provided by the tileserver
65 */
66GnuBoat.getMapInfos = function()
67{
68 if(GnuBoat.private.serverBaseUrl == null){
69 GnuBoat.displayMessage("No server set/found");
70 return;
71 }
72 $.getJSON(GnuBoat.private.serverBaseUrl +"tileserver.php?/index.json", GnuBoat.private.mapInfos);
73};
74
75/**
76 * @brief Fetches the list of available logfiles and adds them to the log file download form
77 */
78GnuBoat.logfilesLoad = function()
79{
80 if(GnuBoat.private.serverBaseUrl == null){
81 GnuBoat.displayMessage("No server set/found");
82 return;
83 }
84 $("#logfilesForm").empty();
85 $.getJSON(GnuBoat.private.serverBaseUrl +"?request=logfiles", function(data){
86 if(!Array.isArray(data) || data.length < 1){
87 $("<p>No Logfiles found!</p>").appendTo("#logfilesForm");
88 console.log(data);
89 return;
90 }
91 if(("error" in data) && data["error"] == 1){
92 alert("Failed to upload map: "+ data["errormessage"]);
93 $("#mapTileUploadProgress").hide();
94 $("#mapFileInput").show();
95 return;
96 }
97 $("<select id=\"logfilesSelect\" name=\"logfilesSelected[]\" class=\"pure-input-1\" multiple></select>").appendTo("#logfilesForm");
98 $("<input type=\"submit\" class=\"pure-button pure-button-primary\" name=\"logfilesDownload\" value=\"Download\"/>").appendTo("#logfilesForm");
99 data.forEach(function(value, index){
100 $("<option value=\""+ value +"\">"+ value +"</option>").appendTo("#logfilesSelect");
101 });
102 });
103};
104/**
105 * @brief Sends a shutdown request to the webservice
106 */
107GnuBoat.shutdown = function()
108{
109 if(GnuBoat.private.serverBaseUrl == null){
110 GnuBoat.displayMessage("No server set/found");
111 return;
112 }
113 $.getJSON(GnuBoat.private.serverBaseUrl +"?request=shutdown", function(data){
114 var shutdownTime = data["shutdownstart"];
115 var shutdownDate = Date.parse(shutdownTime);
116 var currentDate = new Date();
117 var shutdownHint = '<span class="info">Shutting down in '+ Math.floor((shutdownDate - currentDate)/1000) +"s at "+ shutdownTime.toLocaleString() +"</span>";
118 if(shutdownTime == -1){
119 shutdownHint = '<span class="error">Failed to initiate shutdown: '+ data["errormessage"] +"</span>";
120 }
121 GnuBoat.displayMessage(shutdownHint);
122 });
123};
124
125/**
126 * @brief Uploads a map and refreshes the maps metadata on success
127 */
128GnuBoat.uploadMap = function(form)
129{
130 if(GnuBoat.private.serverBaseUrl == null){
131 displayMessage("No server set/found");
132 return;
133 }
134 $("#mapFileInput").hide();
135 $("#mapTileUploadProgress").show();
136 $.ajax({
137 type: 'POST',
138 url: GnuBoat.private.serverBaseUrl +'?request=map',
139 data: new FormData($("#mapTileUpload")[0]),
140 contentType: false,
141 processData: false,
142 success: function(data){
143 if(("error" in data) && data["error"] == 1){
144 alert("Failed to upload map: "+ data["errormessage"]);
145 $("#mapTileUploadProgress").hide();
146 $("#mapFileInput").show();
147 return;
148 }
149 alert("Map upload successfully");
150 $("#mapTileUploadProgress").hide();
151 $("#mapFileInput").show();
152 GnuBoat.getMapInfos();
153 },
154 error: function(jqXHR, exception, errorThrown){
155 alert("Failed to upload map (XHR): "+ exception);
156 $("#mapTileUploadProgress").hide();
157 $("#mapFileInput").show();
158 }
159 }).progress(function(e){
160 $("#mapTileUploadProgress").attr({value: e.oloaded, max: e.total});
161 });
162};
163
164/**
165 * @brief Setups up GnuBoat to be able to start() after configured a server with setServer().
166 */
167GnuBoat.initialize = function()
168{
169 $("#mapTileUploadProgress").hide();
170 $("#logfilesReload").click(GnuBoat.logfilesLoad);
171 $("#shutdownButton").click(GnuBoat.shutdown);
172
173 $("#mapTileUpload").validate({
174 rules: {
175 mapFile: {
176 required: true
177 },
178 mapName: {
179 required: true
180 }
181 },
182 submitHandler: function(form){
183 GnuBoat.uploadMap(form);
184 }
185 });
186
187 $("#logfilesForm").validate({
188 rules: {
189 logfilesSelect: {
190 required: true
191 },
192 }
193 });
194
195 $("#rendering").empty();
196 var width = $("#rendering").width();
197 var height = $("#rendering").height();
198
199 var fieldOfView = 75;
200
201 GnuBoat.private.renderScene = new THREE.Scene();
202 GnuBoat.private.renderScene.background = new THREE.Color(0xEEEEEE);
203
204 GnuBoat.private.renderCamera = new THREE.PerspectiveCamera(75, width/height, 0.1, 1000000);
205 GnuBoat.private.renderCamera.up = new THREE.Vector3(0, 0, 1);
206 GnuBoat.private.renderCamera.position.set(-0.01, -0.01, 15000);
207 GnuBoat.private.renderCamera.lookAt(GnuBoat.private.renderScene.position);
208
209 GnuBoat.private.renderRenderer = new THREE.WebGLRenderer();
210 GnuBoat.private.renderRenderer.setSize(width, height);
211 GnuBoat.private.renderRenderer.setPixelRatio( window.devicePixelRatio );
212 document.getElementById("rendering").appendChild(GnuBoat.private.renderRenderer.domElement);
213
214 GnuBoat.private.renderControls = new THREE.OrbitControls( GnuBoat.private.renderCamera, GnuBoat.private.renderRenderer.domElement );
215 GnuBoat.private.renderControls.zoomSpeed = 2;
216
217
218
219 var deep = new THREE.Color(0x347C7C);
220 var shallow = new THREE.Color(0xBCD9D9);
221 var size = 5;
222 GnuBoat.private.renderDepthSteps = 50;
223
224 var deltaR = (Math.max(deep.r, shallow.r) - Math.min(deep.r, shallow.r))/GnuBoat.private.renderDepthSteps;
225 var deltaG = (Math.max(deep.g, shallow.g) - Math.min(deep.g, shallow.g))/GnuBoat.private.renderDepthSteps;
226 var deltaB = (Math.max(deep.b, shallow.b) - Math.min(deep.b, shallow.b))/GnuBoat.private.renderDepthSteps;
227 for(var i = 0; i < GnuBoat.private.renderDepthSteps; i++){
228 var stepColor = new THREE.Color(Math.max(deep.r, shallow.r) - i * deltaR,
229 Math.max(deep.g, shallow.g) - i * deltaG,
230 Math.max(deep.b, shallow.b) - i * deltaB);
231 GnuBoat.private.renderDepthMaterials.push(stepColor);
232 }
233 GnuBoat.private.renderDepthMaterials.push(shallow);
234}
235
236/**
237 * @brief Starts querying the webservice
238 *
239 * Call initialize() and setServer() before start()
240 */
241GnuBoat.start = function()
242{
243 if(GnuBoat.private.serverBaseUrl == null){
244 GnuBoat.displayMessage("No server set/found");
245 return;
246 }
247
248 GnuBoat.getMapInfos();
249 GnuBoat.displayDataGet();
250 if(GnuBoat.private.timerDisplay == null)
251 GnuBoat.private.timerDisplay = setInterval(GnuBoat.displayDataGet, 10000);
252 GnuBoat.logfilesLoad();
253
254 GnuBoat.private.animate();
255}
256
257/**
258 * @brief Stops querying the webservice
259 */
260GnuBoat.stop = function()
261{
262 if(GnuBoat.private.timerDisplay != null){
263 clearInterval(GnuBoat.private.timerDisplay);
264 GnuBoat.private.timerDisplay = null;
265 }
266}
267
268/**
269 * @brief Private methods and properties of GnuBoat
270 */
271GnuBoat.private = {
272 map: null,
273 mapLayerCurrent: null,
274 mapPolylines: [],
275 mapControl: null,
276 mapsMetadata: null,
277 mapBounds: null,
278 dataMappings: {
279 speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"},
280 speedoverground: {display: true, map: true, mapActive: false, titleLong: "Speed Over Ground", titleShort: "SOG", unit: "kts"},
281 waterdepth: {display: true, map: true, mapActive: true, titleLong: "Waterdepth", titleShort: "Depth", unit: "m"},
282 watertemperature: {display: true, map: true, mapActive: false, titleLong: "Watertemperature", titleShort: "Water", unit: "°C"},
283 gpsfix: {display: true, map: false, mapActive: false, titleLong: "GPS Fix", titleShort: "Fix", unit: ""},
284 },
285 serverBaseUrl: null,
286 timerDisplay: null,
287 renderScene: null,
288 renderCamera: null,
289 renderRenderer: null,
290 renderMapBounds: null,
291 renderGrid: null,
292 renderControls: null,
293 renderCloud: null,
294 renderDepthMaterials: [],
295 renderDepthSteps: null,
296
297 openLink: function(target)
298 {
299 window.location=target;
300 },
301
302 displayDataSet: function(data)
303 {
304 var keysDisplay = [];
305 for(var key in GnuBoat.private.dataMappings){
306 if(GnuBoat.private.dataMappings[key]["display"] === true)
307 keysDisplay.push(key);
308 }
309 if(!Array.isArray(data) && !(data instanceof Object)){
310 console.log("No data array returned!");
311 console.log(data);
312 return;
313 }
314 if(!("lastvalid" in data)){
315 console.log("No last valid values given!");
316 }
317 else{
318 var lastValid = data["lastvalid"];
319 for(var i = 0; i < keysDisplay.length; i++){
320 var key = keysDisplay[i];
321 var value = lastValid[key];
322 if($.isNumeric(value)){
323 var text = value.toFixed(1);
324 if(key == "watertemperature"){
325 text = value.toFixed(0);
326 }
327 $("#display #"+ key +" #value").text(text);
328 }
329 else if(key == "gpsfix"){
330 $("#display #"+ key +" #value").text(value);
331 }
332 }
333 }
334
335 if(!("track" in data)){
336 console.log("No track given!");
337 }
338 else{
339 if(GnuBoat.private.map == null){
340 console.log("No map in use");
341 }
342 else{
343 var track = data["track"];
344 var maximas = [];
345 var minimas = [];
346 var points = [];
347 var densityPoints = [];
348
349 var keysMap = [];
350 for(var key in GnuBoat.private.dataMappings){
351 if(GnuBoat.private.dataMappings[key]["map"] === true)
352 keysMap.push(key);
353 }
354 for(var i = 0; i < keysMap.length; i++){
355 if(keysMap[i] == "gpsfix")
356 continue;
357 points[keysMap[i]] = [];
358 }
359
360 // getting maximas, minimums for normalization and the tracks themselves
361 for(var time in track){
362 for(var i = 0; i < keysMap.length; i++){
363 var key = keysMap[i];
364 if(key == "gpsfix")
365 continue;
366 if(!(key in maximas))
367 maximas[key] = track[time][key]
368 else if(maximas[key] < track[time][key])
369 maximas[key] = track[time][key];
370 if(!(key in minimas))
371 minimas[key] = track[time][key]
372 else if(minimas[key] > track[time][key])
373 minimas[key] = track[time][key];
374 points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], track[time][key]));
375 densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: track[time]["waterdepth"]});
376 }
377 }
378 for(var i = 0; i < keysMap.length; i++){
379 var key = keysMap[i];
380 if(key == "gpsfix")
381 continue;
382 if(points[key].length > 0){
383 if(key in GnuBoat.private.mapPolylines)
384 GnuBoat.private.mapPolylines[key].setLatLngs(points[key]);
385 else{
386 GnuBoat.private.mapPolylines[key] = L.hotline(points[key], {weight: 3, outlineWidth: 0, min: minimas[key], max: maximas[key]});
387 if(GnuBoat.private.mapControl){
388 var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")";
389 GnuBoat.private.mapControl.addOverlay(GnuBoat.private.mapPolylines[key], name);
390 }
391 if(GnuBoat.private.dataMappings[key]["mapActive"] === true)
392 GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map);
393 }
394 }
395 }
396 GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"], minimas["waterdepth"]);
397 }
398 }
399 },
400
401 mapSetup: function ()
402 {
403 var mapMetadataIndex = $("#mapSelect").val();
404 if(GnuBoat.private.mapsMetadata == null){
405 console.log("No mapsMetadata set");
406 return;
407 }
408 if(mapMetadataIndex < 0 || mapMetadataIndex >= GnuBoat.private.mapsMetadata.length){
409 console.log("Map metadata is outside of range :"+ mapMetadataIndex.toString());
410 console.log(mapsMetadata);
411 return;
412 }
413 var mapMetadata = GnuBoat.private.mapsMetadata[mapMetadataIndex];
414
415 var latitudeTop = mapMetadata["bounds"][3];
416 var latitudeBottom = mapMetadata["bounds"][1];
417 var longitudeLeft = mapMetadata["bounds"][0];
418 var longitudeRight = mapMetadata["bounds"][2];
419
420 var mapZoomMin = mapMetadata["minzoom"];
421 var mapZoomMax = mapMetadata["maxzoom"];
422
423 var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
424 var longitudeCenter = (longitudeLeft - longitudeRight)/2 + longitudeRight;
425 var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
426
427 GnuBoat.private.mapBounds = new L.LatLngBounds(
428 new L.LatLng(latitudeBottom, longitudeLeft),
429 new L.LatLng(latitudeTop, longitudeRight));
430
431 if(GnuBoat.private.map == null){
432 // only initialize the map (viewport) once
433 GnuBoat.private.map = L.map('mapViewport');
434 }
435 GnuBoat.private.map.setView([latitudeCenter, longitudeCenter], mapZoomStart);
436
437 if(GnuBoat.private.mapLayerCurrent != null){
438 GnuBoat.private.map.removeLayer(GnuBoat.private.mapLayerCurrent);
439 if(GnuBoat.private.mapControl)
440 GnuBoat.private.mapControl.removeLayer(GnuBoat.private.mapLayerCurrent);
441 GnuBoat.private.mapLayerCurrent = null;
442 }
443 GnuBoat.private.mapLayerCurrent = L.tileLayer(mapMetadata["tiles"][0], {
444 minZoom: mapZoomMin, maxZoom: mapZoomMax,
445 bounds: GnuBoat.private.mapBounds,
446 attribution: mapMetadata["name"],
447 opacity: 0.85
448 }).addTo(GnuBoat.private.map);
449 if(GnuBoat.private.mapControl != null)
450 GnuBoat.private.mapControl.addBaseLayer(GnuBoat.private.mapLayerCurrent, "Map");
451 else{
452 GnuBoat.private.mapControl = L.control.layers({"Map": GnuBoat.private.mapLayerCurrent}, GnuBoat.private.mapOverlaysToList(), {hideSingleBase: true, sortLayers: true, }).addTo(GnuBoat.private.map);
453 }
454
455 // configure render scene for new map
456 GnuBoat.private.renderSetupMap();
457 },
458
459 mapInfos: function(data)
460 {
461 GnuBoat.private.mapsMetadata = data;
462
463 $("#mapSelect").empty();
464 var selected = "selected";
465 data.forEach(function(value, index){
466 $("<option value=\""+ index.toString() +"\" "+ selected +">"+ value["name"] +"</option>").appendTo("#mapSelect");
467 selected = "";
468 });
469
470 GnuBoat.private.mapSetup();
471 $("#mapSelect").change(function(){ GnuBoat.private.mapSetup(); });
472 },
473
474 mapOverlaysToList: function()
475 {
476 var overlays = {};
477 for(var key in GnuBoat.private.mapPolylines){
478 overlays[key] = GnuBoat.private.mapPolylines[key];
479 }
480 return overlays;
481 },
482
483 renderSetupMap: function()
484 {
485 if(GnuBoat.private.mapBounds == null)
486 return;
487
488 // add map bounds
489 if(GnuBoat.private.renderMapBounds != null)
490 GnuBoat.private.renderScene.remove(GnuBoat.private.renderMapBounds);
491 var m1 = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getSouth(), GnuBoat.private.mapBounds.getWest());
492 var m2 = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getSouth(), GnuBoat.private.mapBounds.getEast());
493 var m3 = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getNorth(), GnuBoat.private.mapBounds.getEast());
494 var m4 = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getNorth(), GnuBoat.private.mapBounds.getWest());
495 var geometryMapBounds = new THREE.Geometry();
496 var materialMapBounds = new THREE.LineBasicMaterial({color: 0x66BD66, linewidth: 1});
497 // z is greator 0, to draw the map boundings over the grid
498 var vertex = new THREE.Vector3(0, 0, 2);
499 geometryMapBounds.vertices.push(vertex);
500 vertex = new THREE.Vector3(m2.x - m1.x, m2.y - m1.y, 2);
501 geometryMapBounds.vertices.push(vertex);
502 vertex = new THREE.Vector3(m3.x - m1.x, m3.y - m1.y, 2);
503 geometryMapBounds.vertices.push(vertex);
504 vertex = new THREE.Vector3(m4.x - m1.x, m4.y - m1.y, 2);
505 geometryMapBounds.vertices.push(vertex);
506 GnuBoat.private.renderMapBounds = new THREE.LineLoop(geometryMapBounds, materialMapBounds);
507 GnuBoat.private.renderScene.add(GnuBoat.private.renderMapBounds);
508
509 // add 500m grid
510 if(GnuBoat.private.renderGrid != null)
511 GnuBoat.private.renderScene.remove(GnuBoat.private.renderGrid);
512 geometryMapBounds.computeBoundingBox();
513 var maxLength = Math.max(geometryMapBounds.boundingBox.getSize().x, geometryMapBounds.boundingBox.getSize().y);
514 GnuBoat.private.renderGrid = new THREE.GridHelper(maxLength, Math.round(maxLength / 500.0), 0xCCCCCC, 0xCCCCCC);
515 GnuBoat.private.renderGrid.geometry.rotateX( Math.PI / 2 );
516 GnuBoat.private.renderGrid.translateX(maxLength / 2.0);
517 GnuBoat.private.renderGrid.translateY(maxLength / 2.0);
518 GnuBoat.private.renderScene.add(GnuBoat.private.renderGrid);
519
520 var distance = 150;
521 var fieldOfView = 2 * Math.atan(maxLength / (2.0 * distance) ) * 180.0 / Math.PI;
522 GnuBoat.private.renderCamera.position.set(-10, -5, 100);
523 GnuBoat.private.renderCamera.fov = fieldOfView;
524 GnuBoat.private.renderCamera.lookAt(GnuBoat.private.renderScene.position);
525 GnuBoat.private.renderCamera.zoom = 5;
526 GnuBoat.private.renderCamera.updateProjectionMatrix();
527 },
528
529 drawDensityEstimation: function(densityPoints, maximum, minimum)
530 {
531 var material = new THREE.PointsMaterial({vertexColors: THREE.VertexColors, size: 5});
532 var geometry = new THREE.Geometry();
533 var mercatorSouthWest = {x: 0, y: 0};
534 if(GnuBoat.private.mapBounds != null)
535 mercatorSouthWest = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getSouth(), GnuBoat.private.mapBounds.getWest());
536
537 for(var i = 0; i < densityPoints.length; i++){
538 var mercator = GnuBoat.private.mercator(densityPoints[i].latitude, densityPoints[i].longitude);
539 var vertex = new THREE.Vector3(mercator.x - mercatorSouthWest.x, mercator.y - mercatorSouthWest.y, (densityPoints[i].depth * -1) + maximum);
540 var color = new THREE.Color(0x000000);
541 if(GnuBoat.private.renderDepthSteps != null){
542 var step = Math.floor((densityPoints[i].depth - minimum)/((maximum-minimum)/GnuBoat.private.renderDepthSteps));
543 if(step >= 0 && step < GnuBoat.private.renderDepthMaterials.length)
544 color = GnuBoat.private.renderDepthMaterials[step];
545 }
546 geometry.vertices.push(vertex);
547 geometry.colors.push(color);
548 }
549 // point cloud
550 if(GnuBoat.private.renderCloud != null)
551 GnuBoat.private.renderScene.remove(GnuBoat.private.renderCloud);
552 GnuBoat.private.renderCloud = new THREE.Points(geometry, material);
553 GnuBoat.private.renderScene.add(GnuBoat.private.renderCloud);
554 },
555
556 animate: function()
557 {
558 requestAnimationFrame(GnuBoat.private.animate);
559 if(GnuBoat.private.renderCloud != null){
560 var scaleZ = $("#renderScaleZ").val();
561 if(GnuBoat.private.renderCloud.scale.z != scaleZ)
562 GnuBoat.private.renderCloud.scale.set(1, 1, scaleZ);
563 }
564
565 GnuBoat.private.renderControls.update();
566 GnuBoat.private.renderRenderer.render(GnuBoat.private.renderScene, GnuBoat.private.renderCamera);
567 },
568
569 mercator: function(latitude, longitude)
570 {
571 var result = {};
572
573 var earthRadius = 6378137.0;
574
575 result["x"] = longitude / 180.0 * Math.PI * earthRadius;
576 result["y"] = Math.log(Math.tan(latitude / 180.0 * Math.PI / 2.0 + Math.PI / 4.0)) * earthRadius;
577
578 return result;
579 },
580};
Note: See TracBrowser for help on using the repository browser.