Overview

Namespaces

  • Mapbender
    • Component
      • HTTP
    • CoreBundle
      • Command
      • Component
        • Exception
      • Controller
      • DataFixtures
        • ORM
      • DependencyInjection
      • Element
        • Type
      • Entity
      • EventListener
      • Extension
      • Form
        • DataTransformer
        • EventListener
        • Type
      • Security
      • Template
    • 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
        • Type
    • WmsBundle
      • Component
        • Exception
      • Controller
      • DependencyInjection
      • Element
        • Type
      • Entity
      • Event
      • Form
        • EventListener
        • Type
    • WmtsBundle
      • Component
        • Exception
      • Controller
      • Entity
      • Form
        • Type
  • None
  • PHP

Classes

  • WmsInstance
  • WmsInstanceLayer
  • WmsLayerSource
  • WmsSource
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: 
  3: namespace Mapbender\WmsBundle\Entity;
  4: 
  5: use Doctrine\Common\Collections\ArrayCollection;
  6: use Doctrine\ORM\EntityManager;
  7: use Doctrine\ORM\Mapping as ORM;
  8: use Mapbender\WmsBundle\Component\WmsInstanceConfiguration;
  9: use Mapbender\WmsBundle\Component\WmsInstanceConfigurationOptions;
 10: use Mapbender\CoreBundle\Entity\SourceInstance;
 11: use Mapbender\WmsBundle\Entity\WmsInstanceLayer;
 12: use Mapbender\WmsBundle\Entity\WmsSource;
 13: use Mapbender\WmsBundle\Component\Style;
 14: use Mapbender\WmsBundle\Component\OnlineResource;
 15: use Mapbender\WmsBundle\Component\LegendUrl;
 16: 
 17: /**
 18:  * WmsInstance class
 19:  *
 20:  * @author Paul Schmidt
 21:  *
 22:  * @ORM\Entity
 23:  * @ORM\Table(name="mb_wms_wmsinstance")
 24:  * ORM\DiscriminatorMap({"mb_wms_wmssourceinstance" = "WmsSourceInstance"})
 25:  */
 26: class WmsInstance extends SourceInstance
 27: {
 28: 
 29:     /**
 30:      * @var array $configuration The instance configuration
 31:      * @ORM\Column(type="array", nullable=true)
 32:      */
 33:     protected $configuration;
 34: 
 35:     /**
 36:      * @ORM\ManyToOne(targetEntity="WmsSource", inversedBy="wmsinstance", cascade={"refresh"})
 37:      * @ORM\JoinColumn(name="wmssource", referencedColumnName="id")
 38:      */
 39:     protected $source;
 40: 
 41:     /**
 42:      * @ORM\OneToMany(targetEntity="WmsInstanceLayer", mappedBy="wmsinstance", cascade={"refresh", "persist", "remove"})
 43:      * @ORM\JoinColumn(name="layers", referencedColumnName="id")
 44:      * @ORM\OrderBy({"priority" = "asc"})
 45:      */
 46:     protected $layers; //{ name: 1,   title: Webatlas,   visible: true }
 47: 
 48:     /**
 49:      * @ORM\Column(type="string", nullable=true)
 50:      */
 51:     protected $srs;
 52: 
 53:     /**
 54:      * @ORM\Column(type="string", nullable=true)
 55:      */
 56:     protected $format;
 57: 
 58:     /**
 59:      * @ORM\Column(type="string", nullable=true)
 60:      */
 61:     protected $infoformat;
 62: 
 63:     /**
 64:      * @ORM\Column(type="string", nullable=true)
 65:      */
 66:     protected $exceptionformat = null;
 67: 
 68:     /**
 69:      * @ORM\Column(type="boolean", nullable=true)
 70:      */
 71:     protected $transparency = true;
 72: 
 73:     /**
 74:      * @ORM\Column(type="boolean", nullable=true)
 75:      */
 76:     protected $visible = true;
 77: 
 78:     /**
 79:      * @ORM\Column(type="integer", nullable=true)
 80:      */
 81:     protected $opacity = 100;
 82: 
 83:     /**
 84:      * @ORM\Column(type="boolean", nullable=true)
 85:      */
 86:     protected $proxy = false;
 87: 
 88:     /**
 89:      * @ORM\Column(type="boolean", nullable=true)
 90:      */
 91:     protected $tiled = false;
 92: 
 93:     public function __construct()
 94:     {
 95:         $this->layers = new ArrayCollection();
 96:     }
 97: 
 98:     /**
 99:      * Set id
100:      * @param integer $id
101:      * @return WmsInstance
102:      */
103:     public function setId($id)
104:     {
105:         $this->id = $id;
106: 
107:         return $this;
108:     }
109: 
110:     /**
111:      * Get id
112:      *
113:      * @return integer
114:      */
115:     public function getId()
116:     {
117:         return $this->id;
118:     }
119: 
120:     /**
121:      * Set configuration
122:      *
123:      * @param array $configuration
124:      */
125:     public function setConfiguration($configuration)
126:     {
127:         $this->configuration = $configuration;
128:         return $this;
129:     }
130: 
131:     /**
132:      * Get an Instance Configuration.
133:      * 
134:      * @return array $configuration
135:      */
136:     public function getConfiguration()
137:     {
138:         if($this->getSource() === null)
139:         { // from yaml
140:             $this->generateYmlConfiguration();
141:         } else
142:         {
143:             if($this->configuration === null)
144:             {
145:                 $this->generateConfiguration();
146:             }
147:         }
148:         return $this->configuration;
149:     }
150: 
151:     /**
152:      * Generates a configuration from an yml file
153:      */
154:     public function generateYmlConfiguration()
155:     {
156:         $this->setSource(new WmsSource());
157:         $wmsconf = new WmsInstanceConfiguration();
158:         $wmsconf->setType(strtolower($this->getType()));
159:         $wmsconf->setTitle($this->title);
160:         $wmsconf->setIsBaseSource(true);
161:         
162:         $options = new WmsInstanceConfigurationOptions();
163:         $options->setUrl($this->configuration["url"])
164:                 ->setProxy($this->proxy)
165:                 ->setVisible($this->visible)
166:                 ->setFormat($this->getFormat())
167:                 ->setInfoformat($this->infoformat)
168:                 ->setTransparency($this->transparency)
169:                 ->setOpacity($this->opacity / 100)
170:                 ->setTiled($this->tiled);
171:         $wmsconf->setOptions($options);
172:         
173:         if(!key_exists("children", $this->configuration))
174:         {
175:             $num = 0;
176:             $rootlayer = new WmsInstanceLayer();
177:             $rootlayer->setTitle($this->title)
178:                     ->setId($num)
179:                     ->setPriority($num)
180:                     ->setWmslayersource(new WmsLayerSource())
181:                     ->setWmsInstance($this);
182:             $rootlayer->setToggle(false);
183:             $rootlayer->setAllowtoggle(true);
184:             $this->addLayer($rootlayer);
185:             foreach($this->configuration["layers"] as $layerDef)
186:             {
187:                 $num++;
188:                 $layer = new WmsInstanceLayer();
189:                 $layersource = new WmsLayerSource();
190:                 $layersource->setName($layerDef["name"]);
191:                 if(isset($layerDef["legendurl"])){
192:                     $style = new Style();
193:                     $style->setName(null);
194:                     $style->setTitle(null);
195:                     $style->setAbstract(null);
196:                     $legendUrl = new LegendUrl();
197:                     $legendUrl->setWidth(null);
198:                     $legendUrl->setHeight(null);
199:                     $onlineResource = new OnlineResource();
200:                     $onlineResource->setFormat(null);
201:                     $onlineResource->setHref($layerDef["legendurl"]);
202:                     $legendUrl->setOnlineResource($onlineResource);
203:                     $style->setLegendUrl($legendUrl);
204:                     $layersource->addStyle($style);
205:                 }
206:                 $layer->setTitle($layerDef["title"])
207:                         ->setId($this->getId() . '-' . $num)
208:                         ->setSelected(!isset($layerDef["visible"]) ? false : $layerDef["visible"])
209:                         ->setInfo(!isset($layerDef["queryable"]) ? false : $layerDef["queryable"])
210:                         ->setParent($rootlayer)
211:                         ->setWmslayersource($layersource)
212:                         ->setWmsInstance($this);
213:                 $layer->setAllowinfo($layer->getInfo() !== null && $layer->getInfo() ? true : false);
214:                 $rootlayer->addSublayer($layer);
215:                 $this->addLayer($layer);
216:             }
217:             $children = array($this->generateLayersConfiguration($rootlayer));
218:             $wmsconf->setChildren($children);
219:         } else
220:         {
221:             $wmsconf->setChildren($this->configuration["children"]);
222:         }
223:         $this->configuration = $wmsconf->toArray();
224:     }
225: 
226:     /**
227:      * Generates a configuration
228:      */
229:     public function generateConfiguration()
230:     {
231:         $rootlayer = $this->getRootlayer();
232:         $llbbox = $rootlayer->getWmslayersource()->getLatlonBounds();
233:         $srses = array(
234:             $llbbox->getSrs() => array(
235:                 floatval($llbbox->getMinx()),
236:                 floatval($llbbox->getMiny()),
237:                 floatval($llbbox->getMaxx()),
238:                 floatval($llbbox->getMaxy())
239:             )
240:         );
241:         foreach($rootlayer->getWmslayersource()->getBoundingBoxes() as $bbox)
242:         {
243:             $srses = array_merge($srses,
244:                                  array($bbox->getSrs() => array(
245:                     floatval($bbox->getMinx()),
246:                     floatval($bbox->getMiny()),
247:                     floatval($bbox->getMaxx()),
248:                     floatval($bbox->getMaxy()))));
249:         }
250:         $wmsconf = new WmsInstanceConfiguration();
251:         $wmsconf->setType(strtolower($this->getType()));
252:         $wmsconf->setTitle($this->title);
253:         $wmsconf->setIsBaseSource(true);
254:         
255:         $options = new WmsInstanceConfigurationOptions();
256:         $options->setUrl($this->source->getGetMap()->getHttpGet())
257:                 ->setProxy($this->getProxy())
258:                 ->setVisible($this->getVisible())
259:                 ->setFormat($this->getFormat())
260:                 ->setInfoformat($this->getInfoformat())
261:                 ->setTransparency($this->transparency)
262:                 ->setOpacity($this->opacity / 100)
263:                 ->setTiled($this->tiled)
264:                 ->setBbox($srses);
265:         $wmsconf->setOptions($options);
266:         $wmsconf->setChildren(array($this->generateLayersConfiguration($rootlayer)));
267:         $this->configuration = $wmsconf->toArray();
268:     }
269: 
270:     /**
271:      * Generates a configuration for layers
272:      * 
273:      * @param WmsInstanceLayer $layer
274:      * @param array $configuration
275:      * @return array 
276:      */
277:     private function generateLayersConfiguration(WmsInstanceLayer $layer,
278:             $configuration = array())
279:     {
280:         if($layer->getActive() === true)
281:         {
282:             $children = array();
283:             foreach($layer->getSublayer() as $sublayer)
284:             {
285:                 $configurationTemp = $this->generateLayersConfiguration($sublayer);
286:                 if(count($configurationTemp) > 0){
287:                     $children[] = $configurationTemp;
288:                 }
289:             }
290:             $layerConf = $layer->getConfiguration();
291:             $configuration = array(
292:                 "options" => $layerConf,
293:                 "state" => array(
294:                     "visibility" => null,
295:                     "info" => null,
296:                     "outOfScale" => null,
297:                     "outOfBounds" => null),);
298:             if(count($children) > 0)
299:             {
300:                 $configuration["children"] = $children;
301:             }
302:         }
303:         return $configuration;
304:     }
305: 
306:     /**
307:      * Set layers
308:      *
309:      * @param array $layers
310:      * @return WmsInstance
311:      */
312:     public function setLayers($layers)
313:     {
314:         $this->layers = $layers;
315: 
316:         return $this;
317:     }
318: 
319:     /**
320:      * Get layers
321:      *
322:      * @return array
323:      */
324:     public function getLayers()
325:     {
326:         return $this->layers;
327:     }
328: 
329:     /**
330:      * Get root layer
331:      *
332:      * @return WmsInstanceLayer 
333:      */
334:     public function getRootlayer()
335:     {
336:         foreach($this->layers as $layer)
337:         {
338:             if($layer->getParent() === null)
339:             {
340:                 return $layer;
341:             }
342:         }
343:         return null;
344:     }
345: 
346:     /**
347:      * Set title
348:      *
349:      * @param string $title
350:      * @return WmsInstance
351:      */
352:     public function setTitle($title)
353:     {
354:         $this->title = $title;
355: 
356:         return $this;
357:     }
358: 
359:     /**
360:      * Get title
361:      *
362:      * @return string
363:      */
364:     public function getTitle()
365:     {
366:         return $this->title;
367:     }
368: 
369:     /**
370:      * Set srs
371:      *
372:      * @param array $srs
373:      * @return WmsInstance
374:      */
375:     public function setSrs($srs)
376:     {
377:         $this->srs = $srs;
378: 
379:         return $this;
380:     }
381: 
382:     /**
383:      * Get srs
384:      *
385:      * @return array
386:      */
387:     public function getSrs()
388:     {
389:         return $this->srs;
390:     }
391: 
392:     /**
393:      * Set format
394:      *
395:      * @param string $format
396:      * @return WmsInstance
397:      */
398:     public function setFormat($format)
399:     {
400:         $this->format = $format;
401: 
402:         return $this;
403:     }
404: 
405:     /**
406:      * Get format
407:      *
408:      * @return string
409:      */
410:     public function getFormat()
411:     {
412:         return $this->format !== null ? $this->format : 'image/png';
413:     }
414: 
415:     /**
416:      * Set infoformat
417:      *
418:      * @param string $infoformat
419:      * @return WmsInstance
420:      */
421:     public function setInfoformat($infoformat)
422:     {
423:         $this->infoformat = $infoformat;
424: 
425:         return $this;
426:     }
427: 
428:     /**
429:      * Get infoformat
430:      *
431:      * @return string
432:      */
433:     public function getInfoformat()
434:     {
435:         return $this->infoformat;
436:     }
437: 
438:     /**
439:      * Set exceptionformat
440:      *
441:      * @param string $exceptionformat
442:      * @return WmsInstance
443:      */
444:     public function setExceptionformat($exceptionformat)
445:     {
446:         $this->exceptionformat = $exceptionformat;
447: 
448:         return $this;
449:     }
450: 
451:     /**
452:      * Get exceptionformat
453:      *
454:      * @return string
455:      */
456:     public function getExceptionformat()
457:     {
458:         return $this->exceptionformat;
459:     }
460: 
461:     /**
462:      * Set transparency
463:      *
464:      * @param boolean $transparency
465:      * @return WmsInstance
466:      */
467:     public function setTransparency($transparency)
468:     {
469:         $this->transparency = $transparency;
470: 
471:         return $this;
472:     }
473: 
474:     /**
475:      * Get transparency
476:      *
477:      * @return boolean
478:      */
479:     public function getTransparency()
480:     {
481:         return $this->transparency;
482:     }
483: 
484:     /**
485:      * Set visible
486:      *
487:      * @param boolean $visible
488:      * @return WmsInstance
489:      */
490:     public function setVisible($visible)
491:     {
492:         $this->visible = $visible;
493: 
494:         return $this;
495:     }
496: 
497:     /**
498:      * Get visible
499:      *
500:      * @return boolean
501:      */
502:     public function getVisible()
503:     {
504:         return $this->visible;
505:     }
506: 
507:     /**
508:      * Set opacity
509:      *
510:      * @param integer $opacity
511:      * @return WmsInstance
512:      */
513:     public function setOpacity($opacity)
514:     {
515:         $this->opacity = $opacity;
516: 
517:         return $this;
518:     }
519: 
520:     /**
521:      * Get opacity
522:      *
523:      * @return integer
524:      */
525:     public function getOpacity()
526:     {
527:         return $this->opacity;
528:     }
529: 
530:     /**
531:      * Set proxy
532:      *
533:      * @param boolean $proxy
534:      * @return WmsInstance
535:      */
536:     public function setProxy($proxy)
537:     {
538:         $this->proxy = $proxy;
539: 
540:         return $this;
541:     }
542: 
543:     /**
544:      * Get proxy
545:      *
546:      * @return boolean
547:      */
548:     public function getProxy()
549:     {
550:         return $this->proxy;
551:     }
552: 
553:     /**
554:      * Set tiled
555:      *
556:      * @param boolean $tiled
557:      * @return WmsInstance
558:      */
559:     public function setTiled($tiled)
560:     {
561:         $this->tiled = $tiled;
562: 
563:         return $this;
564:     }
565: 
566:     /**
567:      * Get tiled
568:      *
569:      * @return boolean
570:      */
571:     public function getTiled()
572:     {
573:         return $this->tiled;
574:     }
575: 
576:     /**
577:      * Set wmssource
578:      *
579:      * @param WmsSource $wmssource
580:      * @return WmsInstance
581:      */
582:     public function setSource(WmsSource $wmssource = null)
583:     {
584:         $this->source = $wmssource;
585: 
586:         return $this;
587:     }
588: 
589:     /**
590:      * Get wmssource
591:      *
592:      * @return WmsSource
593:      */
594:     public function getSource()
595:     {
596:         return $this->source;
597:     }
598: 
599:     /**
600:      * Add layers
601:      *
602:      * @param WmsInstanceLayer $layers
603:      * @return WmsInstance
604:      */
605:     public function addLayer(WmsInstanceLayer $layer)
606:     {
607:         $this->layers->add($layer);
608: 
609:         return $this;
610:     }
611: 
612:     /**
613:      * Remove layers
614:      *
615:      * @param WmsInstanceLayer $layers
616:      */
617:     public function removeLayer(WmsInstanceLayer $layers)
618:     {
619:         $this->layers->removeElement($layers);
620:     }
621: 
622:     /**
623:      * @inheritdoc
624:      */
625:     public function getType()
626:     {
627:         return "wms";
628:     }
629: 
630:     /**
631:      * @inheritdoc
632:      */
633:     public function getManagerType()
634:     {
635:         return "wms";
636:     }
637: 
638:     /**
639:      * @inheritdoc
640:      */
641:     public function getAssets()
642:     {
643:         return array(
644:             'js' => array(
645:                 '@MapbenderWmsBundle/Resources/public/mapbender.source.wms.js'),
646:             'css' => array());
647:     }
648: 
649:     /**
650:      * @inheritdoc
651:      */
652:     public function getLayerset()
653:     {
654:         parent::getLayerset();
655:     }
656: 
657:     /**
658:      * @inheritdoc
659:      */
660:     public function remove(EntityManager $em)
661:     {
662:         $this->removeLayerRecursive($em, $this->getRootlayer());
663:         $em->remove($this);
664:     }
665: 
666:     /**
667:      * Recursively remove a nested Layerstructure
668:      * @param EntityManager $em
669:      * @param WmsInstanceLayer $instLayer
670:      */
671:     private function removeLayerRecursive(EntityManager $em,
672:             WmsInstanceLayer $instLayer)
673:     {
674:         foreach($instLayer->getSublayer() as $sublayer)
675:         {
676:             $this->removeLayerRecursive($em, $sublayer);
677:         }
678:         $em->remove($instLayer);
679:         $em->flush();
680:     }
681: 
682: }
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0