From 8c9a527fdf9a54699a596e0a6579cc95fb9b4314 Mon Sep 17 00:00:00 2001 From: bfabiszewski Date: Fri, 21 Jun 2013 11:15:09 +0200 Subject: OpenLayers API --- api_openlayers.js | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100755 api_openlayers.js (limited to 'api_openlayers.js') diff --git a/api_openlayers.js b/api_openlayers.js new file mode 100755 index 0000000..434c8e6 --- /dev/null +++ b/api_openlayers.js @@ -0,0 +1,169 @@ +/* phpTrackme + * + * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * + * This is free software; you can redistribute it and/or modify it under + * the terms of the GNU Library General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +// openlayers +var map; +var layerTrack; +var layerMarkers; +var lineStyle = {strokeColor: '#FF0000', strokeOpacity: 1, strokeWidth: 2}; +var wgs84; +var mercator; +var loadedAPI = 'openlayers'; +function init() { + wgs84 = new OpenLayers.Projection('EPSG:4326'); // from WGS 1984 + mercator = new OpenLayers.Projection('EPSG:900913'); // to Mercator + var options = { controls: [ + new OpenLayers.Control.ArgParser(), // default + new OpenLayers.Control.Attribution(), // default + new OpenLayers.Control.LayerSwitcher({'ascending':false}), + new OpenLayers.Control.Navigation(), // default + new OpenLayers.Control.PanZoomBar(),// do we need it? + new OpenLayers.Control.ScaleLine() + ] + }; + map = new OpenLayers.Map('map-canvas', options); + map.addLayer(new OpenLayers.Layer.OSM()); + var position = new OpenLayers.LonLat(21.01,52.23).transform(wgs84, mercator); + var zoom = 8; + map.setCenter(position, zoom); +} +function displayTrack(xml,update) { + altitudes.length = 0; + var totalMeters = 0; + var totalSeconds = 0; + // init layer + layerTrack = new OpenLayers.Layer.Vector( 'Track' ); + layerMarkers = new OpenLayers.Layer.Markers( 'Markers' ); + var points = new Array(); + var latlngbounds = new OpenLayers.Bounds(); + var positions = xml.getElementsByTagName('position'); + var posLen = positions.length; + for (var i=0; i'+lang_user+': '+p.username.toUpperCase()+'
'+lang_track+': '+p.trackname.toUpperCase()+ + ''+ + '
'+ + '
'+lang_time+': '+p.dateoccured+'
'+ + ((p.speed != null)?''+lang_speed+': '+(p.speed.toKmH()*factor_kmh)+' '+unit_kmh+'
':'')+ + ((p.altitude != null)?''+lang_altitude+': '+(p.altitude*factor_m).toFixed()+' '+unit_m+'
':'')+'
'+ + ((latest==0)? + ('
'+lang_ttime+': '+p.totalSeconds.toHMS()+'
'+ + ''+lang_aspeed+': '+((p.totalSeconds>0)?((p.totalMeters/p.totalSeconds).toKmH()*factor_kmh).toFixed():0)+' '+unit_kmh+'
'+ + ''+lang_tdistance+': '+(p.totalMeters.toKm()*factor_km).toFixed(2)+' '+unit_km+'
'+'
'):'')+ + '
'+lang_point+' '+(i+1)+' '+lang_of+' '+(posLen)+'
'+ + '
'; + marker.events.register("mousedown", marker, (function() { + return function() { + // remove popups + if (map.popups.length>0) { + for (var i = map.popups.length-1; i>=0; i-- ) { + map.removePopup(map.popups[i]) + }; + } + // show popup + var popup = new OpenLayers.Popup.FramedCloud("id "+(i+1),lonLat,null,content,icon,true); + map.addPopup(popup); + if (document.getElementById('bottom').style.display=='block') { + chart.setSelection([{row:i,column:null}]); + } + } + })()); + +} + +function addChartEvent(chart) { + google.visualization.events.addListener(chart, 'select', function() { + var selection = chart.getSelection()[0]; + if (selection) { + var id = selection.row; + var marker = layerMarkers.markers[id]; + var url = marker.icon.url; + marker.setUrl('http://www.openstreetmap.org/openlayers/img/marker-gold.png'); + altTimeout = setTimeout(function() { marker.setUrl(url); },2000); + } + }); +} -- cgit v1.2.3