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

  • MapbenderWMC
  • WmcParser
  • WmcParser110
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: 
  3: namespace Mapbender\WmcBundle\Component;
  4: 
  5: use Mapbender\CoreBundle\Component\BoundingBox;
  6: use Mapbender\CoreBundle\Component\Size;
  7: use Mapbender\CoreBundle\Component\StateHandler;
  8: use Mapbender\WmcBundle\Entity\Wmc;
  9: use Mapbender\WmsBundle\Component\LegendUrl;
 10: use Mapbender\WmsBundle\Component\MinMax;
 11: use Mapbender\WmsBundle\Component\OnlineResource;
 12: use Mapbender\WmsBundle\Component\RequestInformation;
 13: use Mapbender\WmsBundle\Component\Style;
 14: use Mapbender\WmsBundle\Component\WmsInstanceConfiguration;
 15: use Mapbender\WmsBundle\Component\WmsInstanceConfigurationOptions;
 16: use Mapbender\WmsBundle\Entity\WmsInstance;
 17: use Mapbender\WmsBundle\Entity\WmsInstanceLayer;
 18: use Mapbender\WmsBundle\Entity\WmsLayerSource;
 19: use Mapbender\WmsBundle\Entity\WmsSource;
 20: 
 21: /**
 22:  * Class that Parses WMC 1.1.0 WMC Document 
 23:  * @package Mapbender
 24:  * @author Paul Schmidt
 25:  */
 26: class WmcParser110 extends WmcParser
 27: {
 28: 
 29:     /**
 30:      * @inheritdoc
 31:      */
 32:     public function __construct(\DOMDocument $doc)
 33:     {
 34:         parent::__construct($doc);
 35:         $this->xpath->registerNamespace("cntxt",
 36:                 "http://www.opengis.net/context");
 37:         $this->xpath->registerNamespace("sld", "http://www.opengis.net/sld");
 38:         $this->xpath->registerNamespace("mb3",
 39:                 "http://mapbender3.org/schema/wmc");
 40:     }
 41: 
 42:     /**
 43:      * @inheritdoc
 44:      */
 45:     public function parse($infoFormat = "text/html")
 46:     {
 47:         $wmc          = new Wmc();
 48:         $stateHandler = new StateHandler();
 49:         $root         = $this->doc->documentElement;
 50:         $id           = $this->getValue("./@id", $root);
 51:         $wmc->setWmcid($this->getValue("./@id", $root));
 52:         $wmc->setVersion($this->getValue("./@version", $root));
 53:         $genEl        = $this->getValue("./cntxt:General", $root);
 54:         $stateHandler->setWindow(new Size(
 55:                 intval($this->getValue("./cntxt:Window/@width", $genEl)),
 56:                 intval($this->getValue("./cntxt:Window/@height", $genEl))));
 57:         $stateHandler->setExtent($this->getBoundingBox(array("./cntxt:BoundingBox"),
 58:                         $genEl, null));
 59: 
 60:         $stateHandler->setName($this->getValue("./cntxt:Title/text()", $genEl));
 61:         $keywordList = $this->xpath->query("./cntxt:KeywordList/cntxt:Keyword",
 62:                 $genEl);
 63:         if ($keywordList !== null && $keywordList->length > 0)
 64:         {
 65:             $keywords = array();
 66:             foreach ($keywordList as $keywordElt)
 67:             {
 68:                 $keywords[] = $this->getValue("./text()", $keywordElt);
 69:             }
 70:             $wmc->setKeywords($keywords);
 71:         }
 72:         if ($this->getValue("./cntxt:Abstract", $genEl) !== null)
 73:         {
 74:             $wmc->setAbstract($this->getValue("./cntxt:Abstract/text()", $genEl));
 75:         }
 76:         $logoEl = $this->getValue("./cntxt:LogoURL", $genEl);
 77:         if ($logoEl !== null)
 78:         {
 79:             $wmc->setLogourl(new LegendUrl(
 80:                     new OnlineResource(
 81:                     $this->getValue("./@format", $logoEl),
 82:                     $this->getValue("./cntxt:OnlineResource/@xlink:href",
 83:                             $logoEl)),
 84:                     intval($this->getValue("./@width", $logoEl)),
 85:                     intval($this->getValue("./@height", $logoEl))));
 86:         }
 87:         $descrEl = $this->getValue("./cntxt:DescriptionURL", $genEl);
 88:         if ($descrEl !== null)
 89:         {
 90:             $wmc->setDescriptionurl(new OnlineResource(
 91:                     $this->getValue("./@format)", $descrEl),
 92:                     $this->getValue("./cntxt:OnlineResource/@xlink:href",
 93:                             $descrEl)));
 94:         }
 95:         $contactEl = $this->getValue("./cntxt:ContactInformation", $genEl);
 96:         if ($contactEl !== null)
 97:         {
 98:             $contact = new Contact();
 99:             $contact->setPerson($this->getValue(
100:                             "./cntxt:ContactPersonPrimary/cntxt:ContactPerson/text()",
101:                             $contactEl));
102:             $contact->setOrganization($this->getValue(
103:                             "./cntxt:ContactPersonPrimary/cntxt:ContactOrganization/text()",
104:                             $contactEl));
105:             $contact->setPosition($this->getValue(
106:                             "../cntxt:ContactPosition/text()", $contactEl));
107: 
108:             $addrEl = $this->getValue("./cntxt:ContactAddress", $contactEl);
109:             if ($addrEl !== null)
110:             {
111:                 $contact->setAddressType($this->getValue(
112:                                 "./cntxt:AddressType/text()", $addrEl));
113:                 $contact->setAddress($this->getValue(
114:                                 "./cntxt:Address/text()", $addrEl));
115:                 $contact->setAddressCity($this->getValue(
116:                                 "./cntxt:City/text()", $addrEl));
117:                 $contact->setAddressStateOrProvince($this->getValue(
118:                                 "./cntxt:StateOrProvince/text()", $addrEl));
119:                 $contact->setAddressPostCode($this->getValue(
120:                                 "./cntxt:PostCode/text()", $addrEl));
121:                 $contact->setAddressCountry($this->getValue(
122:                                 "./cntxt:Country/text()", $addrEl));
123:             }
124: 
125:             $contact->setVoiceTelephone($this->getValue(
126:                             "./cntxt:ContactVoiceTelephone/text()", $contactEl));
127:             $contact->setFacsimileTelephone($this->getValue(
128:                             "./cntxt:ContactFacsimileTelephone/text()",
129:                             $contactEl));
130:             $contact->setElectronicMailAddress($this->getValue(
131:                             "./cntxt:ContactElectronicMailAddress/text()",
132:                             $contactEl));
133: 
134:             $wmc->setContact($contact);
135:         }
136:         $extensionEl = $this->getValue("./cntxt:Extension", $genEl);
137:         if ($extensionEl !== null)
138:         {
139:             $stateHandler->setMaxextent($this->getBoundingBox(
140:                             array("./mb3:maxExtent"), $extensionEl,
141:                             $stateHandler->getExtent()->srs));
142:             //@ TODO other elements
143:         }
144:         $layerList   = $this->xpath->query("./cntxt:LayerList/cntxt:Layer",
145:                 $root);
146:         $sourcesTemp = array();
147:         foreach ($layerList as $layerElm)
148:         {
149:             $sourcesTemp[] = $this->parseLayer($layerElm,
150:                     $stateHandler->getExtent()->srs, $infoFormat);
151:         }
152:         $groupSources = false;
153:         if ($groupSources)
154:         {
155:             foreach ($sourcesTemp as $sourcetmp)
156:             {
157:                 $stateHandler->addSource($sourcetmp);
158:             }
159:         }
160:         else
161:         {
162:             foreach ($sourcesTemp as $sourcetmp)
163:             {
164:                 $stateHandler->addSource($sourcetmp);
165:             }
166:         }
167:         $wmc->setState($stateHandler->generateState());
168:         return $wmc;
169:     }
170: 
171:     /**
172:      * Parses a layer form a WMC document LayerList
173:      * 
174:      * @param \DOMElement $layerElm layer element
175:      * (xpath: '/ViewContext/LayerList/Layer')
176:      * @param string $srs wmc srs (srs from WMC document xpath:
177:      * '/ViewContext/General/BoundingBox/@SRS')
178:      * @return array layer configuration as array
179:      */
180:     private function parseLayer(\DOMElement $layerElm, $srs, $infoFormat)
181:     {
182:         $wmsinst    = new WmsInstance();
183:         $wms        = new WmsSource();
184:         $id         = round(microtime(true) * 1000);
185:         $queryable  = $this->getValue("./@queryable", $layerElm);
186:         $wmsinst->setVisible(!(bool) $this->getValue("./@hidden", $layerElm));
187:         $wmsinst->setInfoformat($infoFormat);
188:         $formats    = array();
189:         $formatList = $this->xpath->query("./cntxt:FormatList/cntxt:Format",
190:                 $layerElm);
191:         foreach ($formatList as $formatElm)
192:         {
193:             $formats[] = $this->getValue("./text()", $formatElm);
194:             $current   = (bool) $this->getValue("./@current", $formatElm);
195:             if ($current)
196:                     $wmsinst->setFormat($this->getValue("./text()", $formatElm));
197:         }
198:         $wms->setVersion($this->getValue("./cntxt:Server/@version", $layerElm));
199:         $wms->setGetMap(new RequestInformation(
200:                 $this->getValue("./cntxt:Server/cntxt:OnlineResource/@xlink:href",
201:                         $layerElm), null, $formats));
202:         $serverTitle = $this->getValue("./cntxt:Server/@xtitle", $layerElm);
203:         $serverTitle = $serverTitle === null ? $this->getValue("./cntxt:Title/text()",
204:                         $layerElm) : $serverTitle;
205:         $wms->setTitle($serverTitle);
206:         $srsList     = $this->xpath->query("./cntxt:SRS", $layerElm);
207:         $srses       = array();
208:         foreach ($srsList as $srsElm)
209:         {
210:             $srses[] = $this->getValue("./text()", $srsElm);
211:         }
212: 
213:         $styleList = $this->xpath->query("./cntxt:StyleList/cntxt:Style",
214:                 $layerElm);
215:         $styles    = array();
216:         foreach ($styleList as $styleElm)
217:         {
218:             $current = (bool) $this->getValue("./@current", $styleElm);
219:             if ($current)
220:             {
221:                 
222:             }
223:             $style       = new Style();
224:             $style->setName($this->getValue("./cntxt:Name/text()", $styleElm));
225:             $style->setTitle($this->getValue("./cntxt:Title/text()", $styleElm));
226:             $style->setAbstract($this->getValue("./cntxt:Abstract/text()",
227:                             $styleElm));
228:             $legendUrlEl = $this->getValue("./cntxt:LegendURL", $styleElm);
229:             if ($legendUrlEl !== null)
230:             {
231:                 $legendUrl      = new LegendUrl();
232:                 $legendUrl->setWidth($this->getValue("./@width", $legendUrlEl));
233:                 $legendUrl->setHeight($this->getValue("./@height", $legendUrlEl));
234:                 $onlineResource = new OnlineResource();
235:                 $onlineResource->setFormat($this->getValue("./format",
236:                                 $legendUrlEl));
237:                 $onlineResource->setHref($this->getValue("./cntxt:OnlineResource/@xlink:href",
238:                                 $legendUrlEl));
239:                 $legendUrl->setOnlineResource($onlineResource);
240:                 $style->setLegendUrl($legendUrl);
241:             }
242:             //@ TODO cntxt:Style/cntxt:SLD
243:             $styles[] = $style;
244:         }
245: 
246: 
247:         $minScaleEl = $this->getValue("./sld:MinScaleDenominator", $layerElm);
248:         $maxScaleEl = $this->getValue("./sld:MaxScaleDenominator", $layerElm);
249:         $scale      = null;
250:         if ($minScaleEl !== null || $maxScaleEl !== null)
251:         {
252:             $scale = new MinMax();
253:             $min   = $this->getValue("./sld:MinScaleDenominator/text()",
254:                     $layerElm);
255:             $scale->setMin($min !== null ? floatval($min) : null);
256:             $max   = $this->getValue("./sld:MaxScaleDenominator/text()",
257:                     $layerElm);
258:             $scale->setMax($max !== null ? floatval($max) : null);
259:         }
260:         $wmsinst->setId(intval($id))
261:                 ->setTitle($wms->getTitle())
262:                 ->setSource($wms);
263:         $wmsconf = new WmsInstanceConfiguration();
264:         $wmsconf->setType(strtolower($wmsinst->getType()));
265:         $wmsconf->setTitle($wmsinst->getTitle());
266:         $wmsconf->setIsBaseSource(false);
267:         $options = new WmsInstanceConfigurationOptions();
268:         $options->setUrl($wms->getGetMap()->getHttpGet())
269:                 ->setVisible($wmsinst->getVisible())
270:                 ->setFormat($wmsinst->getFormat());
271: 
272:         $extensionEl = $this->getValue("./cntxt:Extension", $layerElm);
273:         $layerList   = null;
274: 
275:         if ($extensionEl !== null)
276:         {
277:             $layerconfig              = array();
278:             $layerconfig["maxExtent"] = $this->getBoundingBox(
279:                     array("./mb3:maxExtent"),
280:                     $this->getValue("./cntxt:Extension", $extensionEl), $srs);
281:             $layerconfig["tiled"]     = $this->findFirstValue(array("./mb3wmc:tiled"),
282:                     $extensionEl);
283:             $wmsinst->setTransparency((bool) $this->findFirstValue(
284:                                     array("./mb3:transparent/text()"),
285:                                     $extensionEl, true))
286:                     ->setOpacity($this->findFirstValue(array("./mb3:opacity"), $extensionEl, 1))
287:                     ->setTiled((bool) $this->findFirstValue(array("./mb3:tiled"),
288:                                     $extensionEl, false));
289:             $layerList                = $this->findFirstList(array("./mb3:layers/mb3:layer",
290:                 "./*[contains(local-name(),'layers')]/*[contains(local-name(),'layer')]"),
291:                     $extensionEl);
292: 
293:             $options->setTransparency($wmsinst->getTransparency())
294:                     ->setOpacity($wmsinst->getOpacity())
295:                     ->setTiled($wmsinst->getTiled())
296:                     ->setInfoformat($wmsinst->getInfoformat());
297:         }
298:         $wmsconf->setOptions($options);
299: 
300:         $num      = 0;
301:         $rootInst = new WmsInstanceLayer();
302:         $rootInst->setTitle($wmsinst->getTitle())
303:                 ->setId($wmsinst->getId() . "_" . $num)
304:                 ->setPriority($num)
305:                 ->setWmslayersource(new WmsLayerSource())
306:                 ->setWmsInstance($wmsinst);
307:         $rootInst->setToggle(false);
308:         $rootInst->setAllowtoggle(true);
309:         if ($layerList === null)
310:         {
311:             $layerListStr = explode(",",
312:                     $this->getValue("./cntxt:Name/text()", $layerElm));
313:             foreach ($layerListStr as $layerStr)
314:             {
315:                 $num++;
316:                 $layerInst   = new WmsInstanceLayer();
317:                 $layersource = new WmsLayerSource();
318:                 $layersource->setName($layerStr);
319:                 $layerInst->setTitle($layerStr)
320:                         ->setParent($rootInst)
321:                         ->setId($wmsinst->getId() . "_" . $num)
322:                         ->setPriority($num)
323:                         ->setWmslayersource($layersource)
324:                         ->setWmsInstance($wmsinst);
325:                 $rootInst->addSublayer($layerInst);
326:                 $wmsinst->addLayer($layerInst);
327:             }
328:             $children = array($wmsinst->generateLayersConfiguration($rootInst));
329:             $wmsconf->setChildren($children);
330:             return array(
331:                 'type'          => $wmsinst->getType(),
332:                 'title'         => $wmsinst->getTitle(),
333:                 'id'            => $wmsinst->getId(),
334:                 'configuration' => $wmsconf->toArray());
335:         }
336:         else if ($layerList->length > 0)
337:         {
338:             foreach ($layerList as $layerElmMb)
339:             {
340:                 $num++;
341:                 $layerInst   = new WmsInstanceLayer();
342:                 $layersource = new WmsLayerSource();
343:                 $layersource->setName($this->findFirstValue(
344:                                 array("./@name"), $layerElmMb, $num));
345:                 $legendurl   = $this->findFirstValue(array("./@legendUrl", "./@legend"),
346:                         $layerElmMb, null);
347:                 if ($legendurl !== null)
348:                 {
349:                     $style          = new Style();
350:                     $style->setName(null);
351:                     $style->setTitle(null);
352:                     $style->setAbstract(null);
353:                     $legendUrl      = new LegendUrl();
354:                     $legendUrl->setWidth(null);
355:                     $legendUrl->setHeight(null);
356:                     $onlineResource = new OnlineResource();
357:                     $onlineResource->setFormat(null);
358:                     $onlineResource->setHref($legendurl);
359:                     $legendUrl->setOnlineResource($onlineResource);
360:                     $style->setLegendUrl($legendUrl);
361:                     $layersource->addStyle($style);
362:                 }
363:                 $queryable = $this->findFirstValue(
364:                         array("./@queryable"), $layerElmMb, false);
365:                 $queryable = $queryable !== null && strtolower($queryable) === 'true'
366:                             ? true : null;
367:                 $layerInst->setTitle($this->findFirstValue(
368:                                         array("./@title"), $layerElmMb, $num))
369:                         ->setParent($rootInst)
370:                         ->setId($wmsinst->getId() . "_" . $num)
371:                         ->setPriority($num)
372:                         ->setInfo($queryable)
373:                         ->setWmslayersource($layersource)
374:                         ->setWmsInstance($wmsinst);
375:                 $rootInst->addSublayer($layerInst);
376:                 $wmsinst->addLayer($layerInst);
377:             }
378:             $children = array($wmsinst->generateLayersConfiguration($rootInst));
379:             $wmsconf->setChildren($children);
380:             return array(
381:                 'type'          => $wmsinst->getType(),
382:                 'title'         => $wmsinst->getTitle(),
383:                 'id'            => $wmsinst->getId(),
384:                 'configuration' => $wmsconf->toArray());
385:         }
386:         return null;
387:     }
388: 
389:     /**
390:      * Returns the BoundingBox 
391:      * 
392:      * @param type $xpathStrArr
393:      * @param type $contextElm
394:      * @param type $defSrs
395:      * @return \Mapbender\CoreBundle\Component\BoundingBox|null
396:      */
397:     private function getBoundingBox($xpathStrArr, $contextElm, $defSrs)
398:     {
399:         if ($contextElm !== null)
400:         {
401:             $extentEl = $this->findFirstValue($xpathStrArr, $contextElm);
402:             if ($extentEl !== null)
403:             {
404:                 if ($this->getValue("./@SRS", $extentEl) !== null)
405:                         $srs = $this->getValue("./@SRS", $extentEl);
406:                 else if ($this->getValue("./@srs", $extentEl) !== null)
407:                         $srs = $this->getValue("./@srs", $extentEl);
408:                 else $srs = $defSrs;
409:                 return new BoundingBox($srs,
410:                         floatval($this->getValue("./@minx", $extentEl)),
411:                         floatval($this->getValue("./@miny", $extentEl)),
412:                         floatval($this->getValue("./@maxx", $extentEl)),
413:                         floatval($this->getValue("./@maxy", $extentEl)));
414:             }
415:             return null;
416:         }
417:         return null;
418:     }
419: 
420:     /**
421:      * Returns the first found value with xpath from $xpathStrArr.
422:      * 
423:      * @param type $xpathStrArr array with xpathes
424:      * @param type $contextElm context element
425:      * @param type $defaultValue default value
426:      * @return string|\DOMElement|$defaultValue
427:      */
428:     private function findFirstValue($xpathStrArr, $contextElm,
429:             $defaultValue = null)
430:     {
431:         if ($contextElm !== null)
432:         {
433:             foreach ($xpathStrArr as $xpathStr)
434:             {
435:                 $extentEl = $this->getValue($xpathStr, $contextElm);
436:                 if ($extentEl !== null)
437:                 {
438:                     return $extentEl;
439:                 }
440:             }
441:             if ($defaultValue !== null)
442:             {
443:                 return $defaultValue;
444:             }
445:             return null;
446:         }
447:         return null;
448:     }
449: 
450:     /**
451:      * Returns the first found DOMNodeList with xpath from $xpathStrArr.
452:      * 
453:      * @param type $xpathStrArr array with xpathes
454:      * @param type $contextElm context element
455:      * @return \DOMNodeList 
456:      */
457:     private function findFirstList($xpathStrArr, $contextElm)
458:     {
459:         if ($contextElm !== null)
460:         {
461:             foreach ($xpathStrArr as $xpathStr)
462:             {
463:                 $extentList = $this->xpath->query($xpathStr, $contextElm);
464:                 if ($extentList !== null && $extentList->length > 0)
465:                 {
466:                     return $extentList;
467:                 }
468:             }
469:             return null;
470:         }
471:         return null;
472:     }
473: 
474: }
475: 
476: 
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0