1: <?php
2:
3: namespace Mapbender\CoreBundle\Element;
4:
5: use Mapbender\CoreBundle\Component\Element;
6:
7: 8: 9: 10: 11:
12: class Map extends Element
13: {
14:
15: 16: 17:
18: static public function getClassTitle()
19: {
20: return "Map";
21: }
22:
23: 24: 25:
26: static public function getClassDescription()
27: {
28: return "MapQuery/OpenLayers based map";
29: }
30:
31: 32: 33:
34: static public function getClassTags()
35: {
36: return array('Map', 'MapQuery', 'OpenLayers');
37: }
38:
39: 40: 41:
42: public static function getDefaultConfiguration()
43: {
44: return array(
45: 'layerset' => null,
46: 'dpi' => 72,
47: 'srs' => 'EPSG:4326',
48: 'otherSrs' => array("EPSG:31466","EPSG:31467"),
49: 'units' => 'degrees',
50: 'extents' => array(
51: 'max' => array(0, 40, 20, 60),
52: 'start' => array(5, 45, 15, 55)),
53: 'maxResolution' => 'auto',
54: "scales" => array(25000000,10000000,5000000,1000000,500000),
55: 'imgPath' => 'bundles/mapbendercore/mapquery/lib/openlayers/img');
56: }
57:
58: 59: 60:
61: public function getWidgetName()
62: {
63: return 'mapbender.mbMap';
64: }
65:
66: 67: 68:
69: public function getAssets()
70: {
71: return array(
72: 'js' => array(
73: 'mapquery/lib/openlayers/OpenLayers.js',
74: 'mapquery/lib/jquery/jquery.tmpl.js',
75: 'mapquery/src/jquery.mapquery.core.js',
76: 'proj4js/proj4js-compressed.js',
77: 'mapbender.element.map.js'),
78: 'css' => array());
79: }
80:
81: 82: 83:
84: public function getConfiguration()
85: {
86: $configuration = parent::getConfiguration();
87:
88: if(isset($configuration["scales"]))
89: {
90: $scales = array();
91: if(is_string($configuration["scales"]))
92: {
93: $scales = preg_split("/\s?,\s?/", $configuration["scales"]);
94: } else if(is_array($configuration["scales"]))
95: {
96: $scales = $configuration["scales"];
97: }
98:
99: $scales = array_map(
100: create_function('$value', 'return (int)$value;'), $scales);
101: arsort($scales, SORT_NUMERIC);
102: $configuration["scales"] = $scales;
103: }
104:
105: $extra = array();
106:
107:
108: $configuration = array_merge(array('extra' => $extra), $configuration);
109: $allsrs = array();
110: if(is_int(stripos($configuration["srs"], "|"))){
111: $srsHlp = explode("|", $configuration["srs"]);
112: $configuration["srs"] = $srsHlp[0];
113: $allsrs[$srsHlp[0]] = $srsHlp[1];
114: } else {
115: $allsrs[$configuration["srs"]] = "";
116: }
117:
118: if(isset($configuration["otherSrs"]))
119: {
120: if(is_array($configuration["otherSrs"]))
121: {
122: $otherSrs = $configuration["otherSrs"];
123: } else if(is_string($configuration["otherSrs"])
124: && strlen(trim($configuration["otherSrs"])) > 0)
125: {
126: $otherSrs = preg_split("/\s?,\s?/",
127: $configuration["otherSrs"]);
128: }
129: foreach($otherSrs as $srs){
130: if(is_int(stripos($srs, "|"))){
131: $srsHlp = explode("|", $configuration["srs"]);
132: $allsrs[trim($srsHlp[0])] = trim($srsHlp[1]);
133: } else {
134: $allsrs[trim($srs)] = "";
135: }
136: }
137: }
138: unset($configuration['otherSrs']);
139: $em = $this->container->get("doctrine")->getEntityManager();
140: $query = $em->createQuery("SELECT srs FROM MapbenderCoreBundle:SRS srs"
141: . " Where srs.name IN (:name) ORDER BY srs.id ASC")
142: ->setParameter('name', array_keys($allsrs));
143: $srses = $query->getResult();
144:
145: $ressrses = array();
146: foreach($srses as $srsTemp)
147: {
148: $ressrses[$srsTemp->getName()] = array(
149: "name" => $srsTemp->getName(),
150: "title" => $allsrs[$srsTemp->getName()] !== "" ? $allsrs[$srsTemp->getName()] : $srsTemp->getTitle(),
151: "definition" => $srsTemp->getDefinition());
152: }
153:
154: foreach($allsrs as $key => $value)
155: {
156: if(isset($ressrses[$key])){
157: $configuration["srsDefs"][] = $ressrses[$key];
158: }
159: }
160:
161: $srs_req = $this->container->get('request')->get('srs');
162: if($srs_req)
163: {
164: if(!isset($ressrses[$srs]))
165: {
166: throw new \RuntimeException('The srs: "' . $srs_req
167: . '" does not supported.');
168: }
169: $configuration = array_merge($configuration,
170: array('targetsrs' => $srs_req));
171: }
172:
173: $pois = $this->container->get('request')->get('poi');
174: if($pois) {
175: $extra['pois'] = array();
176: if(array_key_exists('point', $pois)) {
177: $pois = array($pois);
178: }
179: foreach($pois as $poi) {
180: $point = explode(',', $poi['point']);
181: $extra['pois'][] = array(
182: 'x' => floatval($point[0]),
183: 'y' => floatval($point[1]),
184: 'label' => isset($poi['label']) ? $poi['label'] : null,
185: 'scale' => isset($poi['scale']) ? intval($poi['scale']) : null
186: );
187: }
188: }
189:
190: $bbox = $this->container->get('request')->get('bbox');
191: if($bbox) {
192: $bbox = explode(',', $bbox);
193: if(count($bbox) === 4)
194: {
195: $extra['bbox'] = array(
196: floatval($bbox[0]),
197: floatval($bbox[1]),
198: floatval($bbox[2]),
199: floatval($bbox[3])
200: );
201: }
202: }
203:
204: $configuration['extra'] = $extra;
205:
206: if(!isset($configuration['scales']))
207: {
208: throw new \RuntimeException('The scales does not defined.');
209: } else if(is_string($configuration['scales']))
210: {
211: $configuration['scales'] = preg_split(
212: "/\s?,\s?/", $configuration['scales']);
213: }
214: return $configuration;
215: }
216:
217: 218: 219:
220: public function render()
221: {
222: return $this->container->get('templating')
223: ->render('MapbenderCoreBundle:Element:map.html.twig',
224: array(
225: 'id' => $this->getId()));
226: }
227:
228: 229: 230:
231: public static function getType()
232: {
233: return 'Mapbender\CoreBundle\Element\Type\MapAdminType';
234: }
235:
236: 237: 238:
239: public static function getFormTemplate()
240: {
241: return 'MapbenderManagerBundle:Element:map.html.twig';
242: }
243: }
244:
245: