ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilOpenLayersMapGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 protected string $css_row;
27 protected string $tile_server;
28 protected ?string $geolocation_server;
29
30 public function __construct()
31 {
33
34 $this->css_row = "";
35 $this->tile_server = "";
36 $this->geolocation_server = "";
37 }
38
39 public function getTileServers(): string
40 {
41 return $this->tile_server;
42 }
43
44 public function setTileServers(string $tile): ilOpenLayersMapGUI
45 {
46 $this->tile_server = $tile;
47 return $this;
48 }
49
50 public function getGeolocationServer(): ?string
51 {
53 }
54
55 public function setGeolocationServer(?string $geolocation): ilOpenLayersMapGUI
56 {
57 $this->geolocation_server = $geolocation;
58 return $this;
59 }
60
61 public function getHtml(): string
62 {
63 $html_tpl = new ilTemplate(
64 "tpl.openlayers_map.html",
65 true,
66 true,
67 "components/ILIAS/Maps"
68 );
69
70 $js_tpl = new ilTemplate(
71 "tpl.openlayers_map.js",
72 true,
73 true,
74 "components/ILIAS/Maps"
75 );
76
77 $this->lng->loadLanguageModule("maps");
78 $this->tpl->addCss("components/ILIAS/Maps/css/service_openlayers.css");
79 $this->tpl->addJavaScript("assets/js/ServiceOpenLayers.js");
80
81 // add user markers
82 $cnt = 0;
83 foreach ($this->user_marker as $user_id) {
85 $user = new ilObjUser($user_id);
86 if ($user->getLatitude() != 0 && $user->getLongitude() != 0 &&
87 $user->getPref("public_location") == "y") {
88 $js_tpl->setCurrentBlock("user_marker");
89 $js_tpl->setVariable(
90 "UMAP_ID",
91 $this->getMapId()
92 );
93 $js_tpl->setVariable("CNT", $cnt);
94
95 $js_tpl->setVariable("ULAT", htmlspecialchars($user->getLatitude()));
96 $js_tpl->setVariable("ULONG", htmlspecialchars($user->getLongitude()));
97 $info = htmlspecialchars($user->getFirstName() . " " . $user->getLastName());
98 $delim = "<br />";
99 if ($user->getPref("public_institution") == "y") {
100 $info .= $delim . htmlspecialchars($user->getInstitution());
101 $delim = ", ";
102 }
103 if ($user->getPref("public_department") == "y") {
104 $info .= $delim . htmlspecialchars($user->getDepartment());
105 }
106 $delim = "<br />";
107 if ($user->getPref("public_street") == "y") {
108 $info .= $delim . htmlspecialchars($user->getStreet());
109 }
110 if ($user->getPref("public_zip") == "y") {
111 $info .= $delim . htmlspecialchars($user->getZipcode());
112 $delim = " ";
113 }
114 if ($user->getPref("public_city") == "y") {
115 $info .= $delim . htmlspecialchars($user->getCity());
116 }
117 $delim = "<br />";
118 if ($user->getPref("public_country") == "y") {
119 $info .= $delim . htmlspecialchars($user->getCountry());
120 }
121 $js_tpl->setVariable(
122 "USER_INFO",
123 $info
124 );
125 $js_tpl->setVariable(
126 "IMG_USER",
127 $user->getPersonalPicturePath("xsmall")
128 );
129 $js_tpl->parseCurrentBlock();
130 $cnt++;
131 }
132 }
133 }
134
135 $html_tpl->setVariable("MAP_ID", $this->getMapId());
136 $html_tpl->setVariable("WIDTH", $this->getWidth());
137 $html_tpl->setVariable("HEIGHT", $this->getHeight());
138
139 $js_tpl->setVariable("MAP_ID", $this->getMapId());
140 $js_tpl->setVariable("LAT", $this->getLatitude());
141 $js_tpl->setVariable("LONG", $this->getLongitude());
142 $js_tpl->setVariable("ZOOM", (int) $this->getZoom());
143
144 $nav_control = $this->getEnableNavigationControl()
145 ? "true"
146 : "false";
147 $js_tpl->setVariable("NAV_CONTROL", $nav_control);
149 ? "true"
150 : "false";
151 $js_tpl->setVariable("CENTRAL_MARKER", $central_marker);
152 $replace_marker = $this->getEnableUpdateListener()
153 ? "true"
154 : "false";
155 $js_tpl->setVariable("REPLACE_MARKER", $replace_marker);
156
157 $tile_servers = $this->getTileServers();
158 $tile_servers = explode(" ", $tile_servers);
159 array_walk($tile_servers, function (&$string) {
160 $string = '"' . $string . '"';
161 });
162 $tile_servers = '[' . implode(', ', $tile_servers) . ']';
163
164 $js_tpl->setVariable("TILES", $tile_servers);
165 $js_tpl->setVariable("GEOLOCATION", $this->getGeolocationServer());
166 $js_tpl->setVariable("INVALID_ADDRESS_STRING", $this->lng->txt("invalid_address"));
167
168 $this->tpl->addOnLoadCode($js_tpl->get());
169
170 return $html_tpl->get();
171 }
172
176 public function getUserListHtml(): string
177 {
178 $list_tpl = new ilTemplate(
179 "tpl.openlayers_map_user_list.html",
180 true,
181 true,
182 "components/ILIAS/Maps"
183 );
184
185 $cnt = 0;
186 foreach ($this->user_marker as $user_id) {
188 $user = new ilObjUser($user_id);
189 $this->css_row = ($this->css_row != "tblrow1_mo")
190 ? "tblrow1_mo"
191 : "tblrow2_mo";
192 if ($user->getLatitude() != 0 && $user->getLongitude() != 0
193 && $user->getPref("public_location") == "y") {
194 $list_tpl->setCurrentBlock("item");
195 $list_tpl->setVariable("MARKER_CNT", $cnt);
196 $list_tpl->setVariable("MAP_ID", $this->getMapId());
197 $cnt++;
198 } else {
199 $list_tpl->setCurrentBlock("item_no_link");
200 }
201 $list_tpl->setVariable("CSS_ROW", $this->css_row);
202 $list_tpl->setVariable("TXT_USER", $user->getLogin());
203 $list_tpl->setVariable(
204 "IMG_USER",
205 $user->getPersonalPicturePath("xxsmall")
206 );
207 $list_tpl->parseCurrentBlock();
208 $list_tpl->touchBlock("row");
209 }
210 }
211
212 return $list_tpl->get();
213 }
214}
User interface class for maps.
getEnableCentralMarker()
getEnableNavigationControl()
bool $central_marker
getEnableUpdateListener()
User class.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
User interface class for OpenLayers maps.
getUserListHtml()
Get User List HTML (to be displayed besides the map)
setGeolocationServer(?string $geolocation)
special template class to simplify handling of ITX/PEAR
$info
Definition: entry_point.php:21
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc