Overview

Namespaces

  • Mapbender
    • Component
      • HTTP
    • CoreBundle
      • Command
      • Component
        • Exception
      • Controller
      • DataFixtures
        • ORM
      • DependencyInjection
      • Element
        • Type
      • Entity
      • EventListener
      • Extension
      • Form
        • DataTransformer
        • EventListener
        • Type
      • Security
      • Template
    • DrupalIntegrationBundle
      • DependencyInjection
      • Security
        • Authentication
          • Provider
          • Token
        • Authorization
          • Voter
        • Factory
        • Firewall
        • User
      • Session
    • KmlBundle
      • Element
    • ManagerBundle
      • Controller
      • Form
        • DataTransformer
        • Type
    • MonitoringBundle
      • Command
      • Component
      • Controller
      • DependencyInjection
      • Entity
      • EventListener
      • Form
    • PrintBundle
      • Component
      • Controller
    • WmcBundle
      • Component
        • Exception
      • Element
        • Type
      • Entity
      • Form
        • EventListener
        • Type
    • WmsBundle
      • Component
        • Exception
      • Controller
      • DependencyInjection
      • Element
        • Type
      • Entity
      • Event
      • Form
        • EventListener
        • Type
    • WmtsBundle
      • Component
        • Exception
      • Controller
      • Entity
      • Form
        • Type
  • None
  • PHP

Classes

  • KmlExport
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: namespace Mapbender\KmlBundle\Element;
  3: 
  4: use Mapbender\CoreBundle\Component\Element;
  5: use Symfony\Component\DependencyInjection\ContainerInterface;
  6: use Symfony\Component\HttpFoundation\Response;
  7: 
  8: class KmlExport extends Element {
  9: 
 10:     public static function getClassTitle() {
 11:         return "KML export element";
 12:     }
 13: 
 14:     public static function getClassDescription() {
 15:         return "KML export element";
 16:     }
 17: 
 18:     public static function getClassTags() {
 19:         return array();
 20:     }
 21: 
 22: 
 23:     public function getWidgetName() {
 24:         return 'mapbender.mbKmlExport';
 25:     }
 26: 
 27:     public function getAssets() {
 28:         return array(
 29:             'js' => array(
 30:                 'mapbender.element.kmlexport.js'
 31:             ),
 32:             'css' => array()
 33:         );
 34:     }
 35: 
 36:     public function getConfiguration() {
 37:         $opts = array();
 38:         $opts['text'] = $this->getClassTitle();
 39:         /* // Resolve the run-time id of the target widget */
 40:         /* if(array_key_exists('target', $this->configuration)) { */
 41:         /*     $elementId = $this->configuration['target']; */
 42:         /*     $finalId = $this->application->getFinalId($elementId); */
 43:         /*     $opts = array_merge($opts, array('target' => $finalId)); */
 44:         /* } */
 45:         return array(
 46:             'options' => $opts,
 47:             'init' => 'mbKmlExport',
 48:         );
 49:     }
 50: 
 51:     public function httpAction($action) {
 52:         switch($action) {
 53:         case 'mapexport':
 54:             return $this->map2Kml();
 55:         }
 56:     }
 57: 
 58:     private function map2Kml() {
 59:         $response = new Response();
 60: 
 61:         $layers = $this->container->get('request')->get('layers');
 62:         foreach($layers as $title => &$layer) {
 63:             parse_str($layer, $layer);
 64: 
 65:             /* $layer['params']['LAYERS'] = implode(',', */
 66:             /*     $layer['options']['layers']); */
 67: 
 68:             $layer['params']['WIDTH'] = 512;
 69:             $layer['params']['HEIGHT'] = 512;
 70:             $layer['params']['SRS'] = 'EPSG:4326';
 71: 
 72:             $delimiter = strpos($layer['options']['url'], '?') === False ?
 73:                 '?' : '&';
 74:             $layer['getMap'] = $layer['options']['url'] . $delimiter
 75:                 . http_build_query($layer['params']);
 76:         }
 77: 
 78:         // IMPORTANT: THIS DEPENDS ON THE php5-mapscript EXTENSION
 79:         $extent = new \rectObj();
 80:         $extentIn = explode(',', $this->container->get('request')->get('extent'));
 81:         $extent->setExtent($extentIn[0], $extentIn[1], $extentIn[2], $extentIn[3]);
 82: 
 83:         $srs = $this->container->get('request')->get('srs');
 84:         $srsFrom = new \projectionObj($srs);
 85:         $srsTo = new \projectionObj('EPSG:4326');
 86:         $extent->project($srsFrom, $srsTo);
 87: 
 88:         $xml = $this->container->get('templating')
 89:             ->render('MapbenderKmlBundle:Element:kmlexport_map.kml.twig',
 90:                 array('layers' => $layers, 'extent' => array(
 91:                     'minx' => $extent->minx,
 92:                     'miny' => $extent->miny,
 93:                     'maxx' => $extent->maxx,
 94:                     'maxy' => $extent->maxy,
 95:                 )));
 96: 
 97:         $response->setContent($xml);
 98:         $response->headers->set('Content-Type',
 99:             'application/vnd.google-earth.kml+xml');
100:         $response->headers->set('Content-Disposition',
101:             'attachment; filename="bkg.kml"');
102:         return $response;
103:     }
104: 
105:     public function render() {
106:         return $this->container->get('templating')
107:             ->render('MapbenderKmlBundle:Element:kmlexport.html.twig', array(
108:             'id' => $this->getId(),
109:             'application' => $this->application->getSlug(),
110:             'configuration' => $this->getConfiguration(),
111:             'label' => $this->getClassTitle()));
112:     }
113: }
114: 
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0