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