Esempio n. 1
0
 /**
  * returns a GPX, KML or GeoJSON version of the document geometry with some useful additional informations in best possible lang
  */
 protected function Export($module, $id, $lang, $format, $version = null)
 {
     if (!$id) {
         $this->setErrorAndRedirect('Could not understand your request', "@default_index?module={$module}");
     }
     if (!empty($version)) {
         $document = $this->getDocument($id, $lang, $version);
     }
     if (empty($document)) {
         $document = Document::find('Document', $id, array('module', 'geom_wkt'));
     }
     if (!$document || $document->get('module') != $module) {
         $this->setErrorAndRedirect('Document does not exist', "@default_index?module={$module}");
     }
     if ($document->get('geom_wkt')) {
         sfLoader::loadHelpers(array('General'));
         $doc = DocumentI18n::findNameDescription($id, $lang);
         // document can exist (id) but not in required lang (id, lang)
         if ($doc) {
             $this->name = $doc->get('name');
             $this->description = $doc->get('description');
             $this->slug = get_slug($doc);
         } else {
             $this->name = 'C2C::' . ucfirst(substr($module, 0, strlen($module) - 1)) . " {$id}";
             $this->description = "";
             $this->slug = "";
         }
         $response = $this->getResponse();
         switch ($format) {
             case 'gpx':
                 $this->points = gisQuery::getEWKT($id, true, $module, $version);
                 $this->setTemplate('../../documents/templates/exportgpx');
                 $response->setContentType('application/gpx+xml');
                 break;
             case 'kml':
                 $this->points = gisQuery::getEWKT($id, true, $module, $version);
                 $this->setTemplate('../../documents/templates/exportkml');
                 $response->setContentType('application/vnd.google-earth.kml+xml');
                 break;
             case 'json':
                 $this->geojson = gisQuery::getGeoJSON($id, $module, $version, 6);
                 $this->setTemplate('../../documents/templates/exportjson');
                 $response->setContentType('application/json');
                 break;
         }
         $this->setLayout(false);
     } else {
         sfLoader::loadHelpers('General');
         $this->setErrorAndRedirect('This document has no geometry', "@document_by_id_lang_slug?module={$module}&id={$id}&lang={$lang}&slug=" . get_slug($document));
     }
 }
 $map_url = '//maps.googleapis.com/maps/api/staticmap?size=310x310&maptype=terrain&mobile=true&sensor=false&key=' . sfConfig::get('app_google_api_key') . '&';
 $map_options = array();
 $module = $document->module;
 if ($module == 'summits' || $module == 'parkings' || $module == 'sites' || $module == 'huts' || $module == 'products' || $module == 'users' || $module == 'images') {
     $map_options[] = 'markers=shadow:false|icon:' . _marker_url($module) . '|' . $document['lat'] . ',' . $document['lon'];
     $map_options[] = 'zoom=12';
 } elseif ($document->get('geom_wkt') && ($module == 'outings' || $module == 'routes')) {
     $tolerance = _compute_tolerance(gisQuery::getBox2d($document->id, $module), true);
     $geoms = explode('),(', gisQuery::getEWKT($document->id, true, $module, null, $tolerance));
     foreach ($geoms as $geom) {
         $map_options[] = 'path=weight:2|color:0xffff00cc|enc:' . _polyline_encode(str_replace(array('(', ')'), '', $geom));
     }
 } elseif ($document->get('geom_wkt') && ($module == 'maps' || $module == 'areas')) {
     // we cannot use donut geometries, so we instead create multiple lines
     $tolerance = _compute_tolerance(gisQuery::getBox2d($document->id, $module));
     $geoms = gisQuery::getEWKT($document->id, true, $module, null, $tolerance);
     $geoms = explode('),(', $geoms);
     foreach ($geoms as $geom) {
         $map_options[] = 'path=weight:2|color:0xff0000cc|enc:' . _polyline_encode(str_replace(array('(', ')'), '', $geom));
     }
 }
 // display linked summits, parkings and huts, if any
 $markers = array();
 $nb_printed_docs = 0;
 foreach (array('parkings', 'summits', 'huts') as $type) {
     if (!isset($document->{$type})) {
         continue;
     }
     foreach ($document->{$type} as $doc) {
         if (!empty($doc['pointwkt'])) {
             switch ($doc['module']) {