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

  • 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($this->getId()."_".$num)
179:                     ->setMinScale(!isset($this->configuration["minScale"]) ? null : $this->configuration["minScale"])
180:                     ->setMaxScale(!isset($this->configuration["maxScale"]) ? null : $this->configuration["maxScale"])
181:                     ->setSelected(!isset($this->configuration["visible"]) ? false : $this->configuration["visible"])
182:                     ->setPriority($num)
183:                     ->setWmslayersource(new WmsLayerSource())
184:                     ->setWmsInstance($this);
185:             $rootlayer->setToggle(false);
186:             $rootlayer->setAllowtoggle(true);
187:             $this->addLayer($rootlayer);
188:             foreach($this->configuration["layers"] as $layerDef)
189:             {
190:                 $num++;
191:                 $layer = new WmsInstanceLayer();
192:                 $layersource = new WmsLayerSource();
193:                 $layersource->setName($layerDef["name"]);
194:                 if(isset($layerDef["legendurl"])){
195:                     $style = new Style();
196:                     $style->setName(null);
197:                     $style->setTitle(null);
198:                     $style->setAbstract(null);
199:                     $legendUrl = new LegendUrl();
200:                     $legendUrl->setWidth(null);
201:                     $legendUrl->setHeight(null);
202:                     $onlineResource = new OnlineResource();
203:                     $onlineResource->setFormat(null);
204:                     $onlineResource->setHref($layerDef["legendurl"]);
205:                     $legendUrl->setOnlineResource($onlineResource);
206:                     $style->setLegendUrl($legendUrl);
207:                     $layersource->addStyle($style);
208:                 }
209:                 $layer->setTitle($layerDef["title"])
210:                         ->setId($this->getId() . '-' . $num)
211:                         ->setMinScale(!isset($layerDef["minScale"]) ? null : $layerDef["minScale"])
212:                         ->setMaxScale(!isset($layerDef["maxScale"]) ? null : $layerDef["maxScale"])
213:                         ->setSelected(!isset($layerDef["visible"]) ? false : $layerDef["visible"])
214:                         ->setInfo(!isset($layerDef["queryable"]) ? false : $layerDef["queryable"])
215:                         ->setParent($rootlayer)
216:                         ->setWmslayersource($layersource)
217:                         ->setWmsInstance($this);
218:                 $layer->setAllowinfo($layer->getInfo() !== null && $layer->getInfo() ? true : false);
219:                 $rootlayer->addSublayer($layer);
220:                 $this->addLayer($layer);
221:             }
222:             $children = array($this->generateLayersConfiguration($rootlayer));
223:             $wmsconf->setChildren($children);
224:         } else
225:         {
226:             $wmsconf->setChildren($this->configuration["children"]);
227:         }
228:         $this->configuration = $wmsconf->toArray();
229:     }
230: 
231:     /**
232:      * Generates a configuration
233:      */
234:     public function generateConfiguration()
235:     {
236:         $rootlayer = $this->getRootlayer();
237:         $llbbox = $rootlayer->getWmslayersource()->getLatlonBounds();
238:         $srses = array(
239:             $llbbox->getSrs() => array(
240:                 floatval($llbbox->getMinx()),
241:                 floatval($llbbox->getMiny()),
242:                 floatval($llbbox->getMaxx()),
243:                 floatval($llbbox->getMaxy())
244:             )
245:         );
246:         foreach($rootlayer->getWmslayersource()->getBoundingBoxes() as $bbox)
247:         {
248:             $srses = array_merge($srses,
249:                                  array($bbox->getSrs() => array(
250:                     floatval($bbox->getMinx()),
251:                     floatval($bbox->getMiny()),
252:                     floatval($bbox->getMaxx()),
253:                     floatval($bbox->getMaxy()))));
254:         }
255:         $wmsconf = new WmsInstanceConfiguration();
256:         $wmsconf->setType(strtolower($this->getType()));
257:         $wmsconf->setTitle($this->title);
258:         $wmsconf->setIsBaseSource(true);
259:         
260:         $options = new WmsInstanceConfigurationOptions();
261:         $options->setUrl($this->source->getGetMap()->getHttpGet())
262:                 ->setProxy($this->getProxy())
263:                 ->setVisible($this->getVisible())
264:                 ->setFormat($this->getFormat())
265:                 ->setInfoformat($this->getInfoformat())
266:                 ->setTransparency($this->transparency)
267:                 ->setOpacity($this->opacity / 100)
268:                 ->setTiled($this->tiled)
269:                 ->setBbox($srses);
270:         $wmsconf->setOptions($options);
271:         $wmsconf->setChildren(array($this->generateLayersConfiguration($rootlayer)));
272:         $this->configuration = $wmsconf->toArray();
273:     }
274: 
275:     /**
276:      * Generates a configuration for layers
277:      * 
278:      * @param WmsInstanceLayer $layer
279:      * @param array $configuration
280:      * @return array 
281:      */
282:     public function generateLayersConfiguration(WmsInstanceLayer $layer,
283:             $configuration = array())
284:     {
285:         if($layer->getActive() === true)
286:         {
287:             $children = array();
288:             foreach($layer->getSublayer() as $sublayer)
289:             {
290:                 $configurationTemp = $this->generateLayersConfiguration($sublayer);
291:                 if(count($configurationTemp) > 0){
292:                     $children[] = $configurationTemp;
293:                 }
294:             }
295:             $layerConf = $layer->getConfiguration();
296:             $configuration = array(
297:                 "options" => $layerConf,
298:                 "state" => array(
299:                     "visibility" => null,
300:                     "info" => null,
301:                     "outOfScale" => null,
302:                     "outOfBounds" => null),);
303:             if(count($children) > 0)
304:             {
305:                 $configuration["children"] = $children;
306:             }
307:         }
308:         return $configuration;
309:     }
310: 
311:     /**
312:      * Set layers
313:      *
314:      * @param array $layers
315:      * @return WmsInstance
316:      */
317:     public function setLayers($layers)
318:     {
319:         $this->layers = $layers;
320: 
321:         return $this;
322:     }
323: 
324:     /**
325:      * Get layers
326:      *
327:      * @return array
328:      */
329:     public function getLayers()
330:     {
331:         return $this->layers;
332:     }
333: 
334:     /**
335:      * Get root layer
336:      *
337:      * @return WmsInstanceLayer 
338:      */
339:     public function getRootlayer()
340:     {
341:         foreach($this->layers as $layer)
342:         {
343:             if($layer->getParent() === null)
344:             {
345:                 return $layer;
346:             }
347:         }
348:         return null;
349:     }
350: 
351:     /**
352:      * Set title
353:      *
354:      * @param string $title
355:      * @return WmsInstance
356:      */
357:     public function setTitle($title)
358:     {
359:         $this->title = $title;
360: 
361:         return $this;
362:     }
363: 
364:     /**
365:      * Get title
366:      *
367:      * @return string
368:      */
369:     public function getTitle()
370:     {
371:         return $this->title;
372:     }
373: 
374:     /**
375:      * Set srs
376:      *
377:      * @param array $srs
378:      * @return WmsInstance
379:      */
380:     public function setSrs($srs)
381:     {
382:         $this->srs = $srs;
383: 
384:         return $this;
385:     }
386: 
387:     /**
388:      * Get srs
389:      *
390:      * @return array
391:      */
392:     public function getSrs()
393:     {
394:         return $this->srs;
395:     }
396: 
397:     /**
398:      * Set format
399:      *
400:      * @param string $format
401:      * @return WmsInstance
402:      */
403:     public function setFormat($format)
404:     {
405:         $this->format = $format;
406: 
407:         return $this;
408:     }
409: 
410:     /**
411:      * Get format
412:      *
413:      * @return string
414:      */
415:     public function getFormat()
416:     {
417:         return $this->format !== null ? $this->format : 'image/png';
418:     }
419: 
420:     /**
421:      * Set infoformat
422:      *
423:      * @param string $infoformat
424:      * @return WmsInstance
425:      */
426:     public function setInfoformat($infoformat)
427:     {
428:         $this->infoformat = $infoformat;
429: 
430:         return $this;
431:     }
432: 
433:     /**
434:      * Get infoformat
435:      *
436:      * @return string
437:      */
438:     public function getInfoformat()
439:     {
440:         return $this->infoformat;
441:     }
442: 
443:     /**
444:      * Set exceptionformat
445:      *
446:      * @param string $exceptionformat
447:      * @return WmsInstance
448:      */
449:     public function setExceptionformat($exceptionformat)
450:     {
451:         $this->exceptionformat = $exceptionformat;
452: 
453:         return $this;
454:     }
455: 
456:     /**
457:      * Get exceptionformat
458:      *
459:      * @return string
460:      */
461:     public function getExceptionformat()
462:     {
463:         return $this->exceptionformat;
464:     }
465: 
466:     /**
467:      * Set transparency
468:      *
469:      * @param boolean $transparency
470:      * @return WmsInstance
471:      */
472:     public function setTransparency($transparency)
473:     {
474:         $this->transparency = $transparency;
475: 
476:         return $this;
477:     }
478: 
479:     /**
480:      * Get transparency
481:      *
482:      * @return boolean
483:      */
484:     public function getTransparency()
485:     {
486:         return $this->transparency;
487:     }
488: 
489:     /**
490:      * Set visible
491:      *
492:      * @param boolean $visible
493:      * @return WmsInstance
494:      */
495:     public function setVisible($visible)
496:     {
497:         $this->visible = $visible;
498: 
499:         return $this;
500:     }
501: 
502:     /**
503:      * Get visible
504:      *
505:      * @return boolean
506:      */
507:     public function getVisible()
508:     {
509:         return $this->visible;
510:     }
511: 
512:     /**
513:      * Set opacity
514:      *
515:      * @param integer $opacity
516:      * @return WmsInstance
517:      */
518:     public function setOpacity($opacity)
519:     {
520:         $this->opacity = $opacity;
521: 
522:         return $this;
523:     }
524: 
525:     /**
526:      * Get opacity
527:      *
528:      * @return integer
529:      */
530:     public function getOpacity()
531:     {
532:         return $this->opacity;
533:     }
534: 
535:     /**
536:      * Set proxy
537:      *
538:      * @param boolean $proxy
539:      * @return WmsInstance
540:      */
541:     public function setProxy($proxy)
542:     {
543:         $this->proxy = $proxy;
544: 
545:         return $this;
546:     }
547: 
548:     /**
549:      * Get proxy
550:      *
551:      * @return boolean
552:      */
553:     public function getProxy()
554:     {
555:         return $this->proxy;
556:     }
557: 
558:     /**
559:      * Set tiled
560:      *
561:      * @param boolean $tiled
562:      * @return WmsInstance
563:      */
564:     public function setTiled($tiled)
565:     {
566:         $this->tiled = $tiled;
567: 
568:         return $this;
569:     }
570: 
571:     /**
572:      * Get tiled
573:      *
574:      * @return boolean
575:      */
576:     public function getTiled()
577:     {
578:         return $this->tiled;
579:     }
580: 
581:     /**
582:      * Set wmssource
583:      *
584:      * @param WmsSource $wmssource
585:      * @return WmsInstance
586:      */
587:     public function setSource(WmsSource $wmssource = null)
588:     {
589:         $this->source = $wmssource;
590: 
591:         return $this;
592:     }
593: 
594:     /**
595:      * Get wmssource
596:      *
597:      * @return WmsSource
598:      */
599:     public function getSource()
600:     {
601:         return $this->source;
602:     }
603: 
604:     /**
605:      * Add layers
606:      *
607:      * @param WmsInstanceLayer $layers
608:      * @return WmsInstance
609:      */
610:     public function addLayer(WmsInstanceLayer $layer)
611:     {
612:         $this->layers->add($layer);
613: 
614:         return $this;
615:     }
616: 
617:     /**
618:      * Remove layers
619:      *
620:      * @param WmsInstanceLayer $layers
621:      */
622:     public function removeLayer(WmsInstanceLayer $layers)
623:     {
624:         $this->layers->removeElement($layers);
625:     }
626: 
627:     /**
628:      * @inheritdoc
629:      */
630:     public function getType()
631:     {
632:         return "wms";
633:     }
634: 
635:     /**
636:      * @inheritdoc
637:      */
638:     public function getManagerType()
639:     {
640:         return "wms";
641:     }
642: 
643:     /**
644:      * @inheritdoc
645:      */
646:     public function getAssets()
647:     {
648:         return array(
649:             'js' => array(
650:                 '@MapbenderWmsBundle/Resources/public/mapbender.source.wms.js'),
651:             'css' => array());
652:     }
653: 
654:     /**
655:      * @inheritdoc
656:      */
657:     public function getLayerset()
658:     {
659:         parent::getLayerset();
660:     }
661: 
662:     /**
663:      * @inheritdoc
664:      */
665:     public function remove(EntityManager $em)
666:     {
667:         $this->removeLayerRecursive($em, $this->getRootlayer());
668:         $em->remove($this);
669:     }
670: 
671:     /**
672:      * Recursively remove a nested Layerstructure
673:      * @param EntityManager $em
674:      * @param WmsInstanceLayer $instLayer
675:      */
676:     private function removeLayerRecursive(EntityManager $em,
677:             WmsInstanceLayer $instLayer)
678:     {
679:         foreach($instLayer->getSublayer() as $sublayer)
680:         {
681:             $this->removeLayerRecursive($em, $sublayer);
682:         }
683:         $em->remove($instLayer);
684:         $em->flush();
685:     }
686: 
687: }
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0