diff --git a/controllers/IndexController.php b/controllers/IndexController.php index 01d5b24..cd76f3b 100644 --- a/controllers/IndexController.php +++ b/controllers/IndexController.php @@ -3,6 +3,78 @@ class IndexController extends Controller { + static function actionTest() + { +// $gpxObject = simplexml_load_file('/tmp/doc2.gpx'); + $gpxObject = simplexml_load_file('/tmp/doc(gpsvisualizer.com).gpx'); +// $gpxObject = simplexml_load_file('/tmp/1100.gpx'); + + $trip = array( + 'name' => isset($gpxObject->metadata->name) ? (string) $gpxObject->metadata->name : 'Track', + 'time' => isset($gpxObject->metadata->time) ? strtotime($gpxObject->metadata->time) : '', + ); + + $wayPoints = array(); + $tracks = array(); + $latlngs = array(); + + foreach ($gpxObject as $key => $block) { + if ($key == 'wpt') { + if (empty($block)) { + continue; + } + + $wayPoints[] = array( + 'lat' => floatval($block['lat']), + 'lng' => floatval($block['lon']), + 'time' => strtotime($block->time), + 'name' => (string) $block->name, + 'desc' => (string) $block->desc, + ); + } + + if ($key == 'trk') { +// print_r($block);die; + if (empty($block->trkseg)) { + continue; + } + + foreach ($block->trkseg as $trkpt) { + if ($trkpt) { + $trackPoints = array(); + $latlngs = array(); + foreach ($trkpt as $tpt) { +// $trackPoints[] = array( +// 'lat' => floatval($tpt['lat']), +// 'lng' => floatval($tpt['lon']), +// 'time' => isset($tpt->time) ? strtotime($tpt->time) : 0, +// 'ele' => isset($tpt->ele) ? floatval($tpt->ele) : 0, +// ); + $latlngs[] = array( + 'lat' => floatval($tpt['lat']), + 'lng' => floatval($tpt['lon']), + ); + } + } + } +// $tracks[] = $trackPoints; + $tracks[] = array( + 'name' => (string)$block->name, + 'length' => 0, + 'latlngs' => $latlngs + ); + } + } + + $trip['tracks'] = $tracks; +// $trip['latlngs'] = $latlngs; + + $trip['wayPoints'] = $wayPoints; + + + self::renderPartial('json.php', $trip); + } + /** * Действие по умолчанию */ diff --git a/public/ico/marker.png b/public/ico/marker.png new file mode 100644 index 0000000..4503353 Binary files /dev/null and b/public/ico/marker.png differ diff --git a/public/js/map.js b/public/js/map.js index b9e49cf..905eadf 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -37,6 +37,13 @@ categories.simplepoint = L.icon({ popupAnchor: [7, 7] }); +categories.marker = L.icon({ + iconUrl: '/ico/marker.png', + iconSize: [32, 37], + iconAnchor: [16, 37], + popupAnchor: [0, 1] +}); + // ----------------------------------------------------------------------------- if (pointLat == pointLng) { @@ -569,3 +576,31 @@ function onLocationFound(e) { function onLocationError(e) { alert('Ошибка при определении координат: ' + e.message); } + +function drawTrek() +{ + colors = ['red', 'green', 'blue']; + track = new Array(); + $.ajax({ + url: "/index/test/", + success: function (data) { + if (typeof (data.tracks) != 'undefined') { + for (var i = 0; i < data.tracks.length; i++) { + color = colors[Math.floor(Math.random() * colors.length)] +// console.log(color); + track[i] = L.polyline(data.tracks[i].latlngs, {color: color, width: 4, opacity: 0.8}); + track[i].addTo(myMap); + track[i].bindPopup(data.tracks[i].name); + } +// myMap.fitBounds(track[i].getBounds()); + } + + if (typeof (data.wayPoints) != 'undefined') { + for (var i = 0; i < data.wayPoints.length; i++) { +// console.log(data.wayPoints[i]); + L.marker([data.wayPoints[i]['lat'], data.wayPoints[i]['lng']], {icon: categories.marker, title: data.wayPoints[i]['name']}).addTo(myMap); + } + } + } + }); +}