1: <?php
2:
3: namespace Mapbender\WmtsBundle;
4:
5: use Mapbender\CoreBundle\Component\Layer;
6: use Mapbender\WmtsBundle\Entity\WmtsInstance;
7:
8:
9: 10: 11: 12: 13:
14: class WmtsLayerLoader extends Layer {
15: protected $layerSetId;
16: protected $layerId;
17: protected $configuration;
18: protected $application;
19:
20: public function __construct($layerSetId, $layerId, array $configuration, $application) {
21: $this->layerSetId = $layerSetId;
22: $this->layerId = $layerId;
23: $this->configuration = $configuration;
24: $this->application = $application;
25: }
26:
27: public function getConfiguration(){
28: return $this->configuration;
29: }
30:
31: public function getLayerSetId(){
32: return $this->layerSetId;
33: }
34:
35: public function getLayerId(){
36: return $this->layerId;
37: }
38:
39: public function loadLayer(){
40: $em = $this->application->get("doctrine")->getEntityManager();
41: $query = $em->createQuery(
42: 'SELECT i FROM MapbenderWmtsBundle:WmtsInstance i WHERE i.layersetid = :layersetid AND i.layerid= :layerid AND i.published = true'
43: )->setParameter('layersetid', $this->layerSetId)->setParameter('layerid', $this->layerId);
44: $wmtsinstanceList = $query->getResult();
45: foreach($wmtsinstanceList as $wmtsinstance){
46: $wmts = $wmtsinstance->getService();
47: $layer = $this->application->get("doctrine")
48: ->getRepository('MapbenderWmtsBundle:WmtsLayerDetail')
49: ->find($wmtsinstance->getLayeridentifier());
50: $this->configuration["proxy"] = $wmtsinstance->getProxy();
51: $this->configuration["baselayer"] = $wmtsinstance->getBaselayer();
52: $this->configuration["visible"] = $wmtsinstance->getVisible();
53: $this->configuration["title"] = $wmtsinstance->getLayerid();
54: $this->configuration["srs"] = $wmtsinstance->getSrs();
55: $this->configuration["url"] = ($wmts->getRequestGetTileGETREST()!==null)? $wmts->getRequestGetTileGETREST() : $wmts->getRequestGetTileGETKVP();
56: $this->configuration["layer"] = $layer->getTitle();
57: $this->configuration["style"] = $wmtsinstance->getStyle();
58: $this->configuration["matrixSet"] = $wmtsinstance->getMatrixset();
59: $this->configuration["origin"] = $wmtsinstance->getTopleftcorner();
60: $this->configuration["format"] = $wmtsinstance->getFormat();
61: $this->configuration["tileSize"] = $wmtsinstance->getTilesize();
62: $this->configuration["matrixIds"] = $wmtsinstance->getMatrixids();
63: $this->configuration["tileFullExtent"] = $wmtsinstance->getCrsbound();
64: }
65: }
66:
67: public function render() {
68: return array(
69: 'id' => $this->layerId,
70: 'type' => 'wmts',
71: 'configuration' => $this->configuration,
72: );
73: }
74:
75: public function getAssets($type = null) {
76: return array(
77: 'js' => array(
78: 'mapbender.layer.wmts.js'
79: )
80: );
81: }
82: public function getType(){
83: return "wmts";
84: }
85: }
86: