1: <?php
2:
3: namespace Mapbender\WmsBundle\Entity;
4:
5: use Doctrine\Common\Collections\ArrayCollection;
6: use Doctrine\ORM\Mapping as ORM;
7: use Mapbender\CoreBundle\Component\InstanceLayerIn;
8: use Mapbender\WmsBundle\Entity\WmsInstance;
9: use Mapbender\WmsBundle\Entity\WmsLayerSource;
10: use Mapbender\CoreBundle\Component\Utils;
11:
12: 13: 14: 15: 16: 17: 18: 19:
20: class WmsInstanceLayer implements InstanceLayerIn
21: {
22:
23: 24: 25: 26: 27: 28:
29: protected $id;
30:
31: 32: 33: 34:
35: protected $wmsinstance;
36:
37: 38: 39: 40:
41: protected $wmslayersource;
42:
43: 44: 45: 46:
47: protected $parent = null;
48:
49: 50: 51: 52:
53: protected $sublayer;
54:
55: 56: 57:
58: protected $title;
59:
60: 61: 62:
63: protected $active = true;
64:
65: 66: 67:
68: protected $allowselected = true;
69:
70: 71: 72:
73: protected $selected = true;
74:
75: 76: 77:
78: protected $info;
79:
80: 81: 82:
83: protected $allowinfo;
84:
85: 86: 87:
88: protected $toggle;
89:
90: 91: 92:
93: protected $allowtoggle;
94:
95: 96: 97:
98: protected $allowreorder = true;
99:
100: 101: 102:
103: protected $minScale;
104:
105: 106: 107:
108: protected $maxScale;
109:
110: 111: 112:
113: protected $style = "";
114:
115: 116: 117:
118: protected $priority;
119:
120: public function __construct()
121: {
122: $this->sublayer = new ArrayCollection();
123: $this->style = "";
124: }
125:
126: 127: 128: 129: 130:
131: public function setId($id)
132: {
133: $this->id = $id;
134: return $this;
135: }
136:
137: 138: 139: 140: 141:
142: public function getId()
143: {
144: return $this->id;
145: }
146:
147: 148: 149: 150: 151: 152:
153: public function setTitle($title)
154: {
155: $this->title = $title;
156:
157: return $this;
158: }
159:
160: 161: 162: 163: 164:
165: public function getTitle()
166: {
167: return $this->title;
168: }
169:
170: 171: 172: 173: 174: 175:
176: public function setSublayer($sublayer)
177: {
178: $this->sublayer = $sublayer;
179:
180: return $this;
181: }
182:
183: 184: 185: 186: 187: 188:
189: public function addSublayer(WmsInstanceLayer $sublayer)
190: {
191: $this->sublayer->add($sublayer);
192:
193: return $this;
194: }
195:
196: 197: 198: 199: 200:
201: public function getSublayer()
202: {
203: return $this->sublayer;
204: }
205:
206: 207: 208: 209: 210: 211:
212: public function setParent($parent)
213: {
214: $this->parent = $parent;
215:
216: return $this;
217: }
218:
219: 220: 221: 222: 223:
224: public function getParent()
225: {
226: return $this->parent;
227: }
228:
229: 230: 231: 232: 233: 234:
235: public function setActive($active)
236: {
237: $this->active = $active;
238:
239: return $this;
240: }
241:
242: 243: 244: 245: 246:
247: public function getActive()
248: {
249: return $this->active;
250: }
251:
252: 253: 254: 255: 256: 257:
258: public function setAllowselected($allowselected)
259: {
260: $this->allowselected = $allowselected;
261:
262: return $this;
263: }
264:
265: 266: 267: 268: 269:
270: public function getAllowselected()
271: {
272: return $this->allowselected;
273: }
274:
275: 276: 277: 278: 279: 280:
281: public function setSelected($selected)
282: {
283: $this->selected = $selected;
284:
285: return $this;
286: }
287:
288: 289: 290: 291: 292:
293: public function getSelected()
294: {
295: return $this->selected;
296: }
297:
298: 299: 300: 301: 302: 303:
304: public function setInfo($info)
305: {
306: $this->info = $info;
307:
308: return $this;
309: }
310:
311: 312: 313: 314: 315:
316: public function getInfo()
317: {
318: return $this->info;
319: }
320:
321: 322: 323: 324: 325:
326: public function getToggle()
327: {
328: return $this->toggle;
329: }
330:
331: 332: 333: 334: 335:
336: public function setToggle($toggle)
337: {
338: $this->toggle = $toggle;
339: return $this;
340: }
341:
342: 343: 344: 345: 346: 347:
348: public function setAllowinfo($allowinfo)
349: {
350: $this->allowinfo = $allowinfo;
351:
352: return $this;
353: }
354:
355: 356: 357: 358: 359:
360: public function getAllowinfo()
361: {
362: return $this->allowinfo;
363: }
364:
365: 366: 367: 368: 369:
370: public function getAllowtoggle()
371: {
372: return $this->allowtoggle;
373: }
374:
375: 376: 377: 378: 379:
380: public function setAllowtoggle($allowtoggle)
381: {
382: $this->allowtoggle = $allowtoggle;
383: return $this;
384: }
385:
386: 387: 388: 389: 390:
391: public function getAllowreorder()
392: {
393: return $this->allowreorder;
394: }
395:
396: 397: 398: 399: 400:
401: public function setAllowreorder($allowreorder)
402: {
403: $this->allowreorder = $allowreorder;
404: return $this;
405: }
406:
407: 408: 409: 410: 411: 412:
413: public function setMinScale($minScale)
414: {
415: $this->minScale = $minScale;
416:
417: return $this;
418: }
419:
420: 421: 422: 423: 424:
425: public function getMinScale()
426: {
427: return $this->minScale;
428: }
429:
430: 431: 432: 433: 434: 435:
436: public function setMaxScale($maxScale)
437: {
438: $this->maxScale = $maxScale;
439:
440: return $this;
441: }
442:
443: 444: 445: 446: 447:
448: public function getMaxScale()
449: {
450: return $this->maxScale;
451: }
452:
453: 454: 455: 456: 457: 458:
459: public function setStyle($style)
460: {
461: $this->style = $style;
462:
463: return $this;
464: }
465:
466: 467: 468: 469: 470:
471: public function getStyle()
472: {
473: return $this->style;
474: }
475:
476: 477: 478: 479: 480: 481:
482: public function setPriority($priority)
483: {
484: $this->priority = $priority;
485:
486: return $this;
487: }
488:
489: 490: 491: 492: 493:
494: public function getPriority()
495: {
496: return $this->priority;
497: }
498:
499: 500: 501: 502: 503: 504:
505: public function setWmsinstance(WmsInstance $wmsinstance = null)
506: {
507: $this->wmsinstance = $wmsinstance;
508:
509: return $this;
510: }
511:
512: 513: 514: 515: 516:
517: public function getWmsinstance()
518: {
519: return $this->wmsinstance;
520: }
521:
522: 523: 524: 525: 526: 527:
528: public function setWmslayersource(WmsLayerSource $wmslayersource = null)
529: {
530: $this->wmslayersource = $wmslayersource;
531:
532: return $this;
533: }
534:
535: 536: 537: 538: 539:
540: public function getWmslayersource()
541: {
542: return $this->wmslayersource;
543: }
544:
545: 546: 547:
548: public function __toString()
549: {
550: return (string) $this->getId();
551: }
552:
553: 554: 555:
556: public function getConfiguration()
557: {
558: $configuration = array(
559: "id" => $this->id,
560: "name" => $this->wmslayersource->getName() !== null ? $this->wmslayersource->getName() : "",
561: "title" => $this->title,
562: "queryable" => $this->getInfo(),
563: "style" => $this->style,
564: "minScale" => $this->minScale !== null ? floatval($this->minScale) : null,
565: "maxScale" => $this->maxScale !== null ? floatval($this->maxScale) : null
566: );
567:
568: if(count($this->wmslayersource->getStyles()) > 0)
569: {
570: $styles = $this->wmslayersource->getStyles();
571: $legendurl = $styles[0]->getLegendUrl();
572: if($legendurl !== null){
573: $configuration["legend"] = array(
574: "url" => $legendurl->getOnlineResource()->getHref(),
575: "width" => intval($legendurl->getWidth()),
576: "height" => intval($legendurl->getHeight()));
577: }
578: } else if($this->wmsinstance->getSource()->getGetLegendGraphic() !== null)
579: {
580: $legend = $this->wmsinstance->getSource()->getGetLegendGraphic();
581: $url = $legend->getHttpGet();
582: $formats = $legend->getFormats();
583: $params = "service=WMS&request=GetLegendGraphic"
584: . "&version="
585: . $this->wmsinstance->getSource()->getVersion()
586: . "&layer=" . $this->wmslayersource->getName()
587: . (count($formats) > 0 ? "&format=" . $formats[0] : "")
588: . "&sld_version=1.1.0";
589: $legendgraphic = Utils::getHttpUrl($url, $params);
590: $configuration["legend"] = array(
591: "graphic" => $legendgraphic);
592: }
593: $configuration["treeOptions"] = array(
594: "info" => $this->info,
595: "selected" => $this->selected,
596: "toggle" => $this->toggle,
597: "allow" => array(
598: "info" => $this->allowinfo,
599: "selected" => $this->allowselected,
600: "toggle" => $this->allowtoggle,
601: "reorder" => $this->allowreorder,
602: )
603: );
604: return $configuration;
605: }
606:
607: }