Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| OlzLocationMap | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
30 | |||
| getNonce | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Common\Components\OlzLocationMap; |
| 4 | |
| 5 | use Olz\Common\Components\OlzComponent; |
| 6 | |
| 7 | /** @extends OlzComponent<array<string, mixed>> */ |
| 8 | class OlzLocationMap extends OlzComponent { |
| 9 | public static int $nonce = 0; |
| 10 | |
| 11 | public function getHtml(mixed $args): string { |
| 12 | $xkoord = $args['xkoord'] ?? null; |
| 13 | $ykoord = $args['ykoord'] ?? null; |
| 14 | $latitude = $args['latitude'] ?? null; |
| 15 | $longitude = $args['longitude'] ?? null; |
| 16 | $zoom = $args['zoom'] ?? 13; |
| 17 | $name = $args['name'] ?? ''; |
| 18 | |
| 19 | $lat = null; |
| 20 | $lng = null; |
| 21 | if ($latitude !== null && $longitude !== null) { |
| 22 | $lat = number_format($latitude, 6, '.', ''); |
| 23 | $lng = number_format($longitude, 6, '.', ''); |
| 24 | $xkoord = $this->mapUtils()->WGStoCHy($latitude, $longitude); |
| 25 | $ykoord = $this->mapUtils()->WGStoCHx($latitude, $longitude); |
| 26 | } elseif ($xkoord !== null && $ykoord !== null) { |
| 27 | $lat = number_format($this->mapUtils()->CHtoWGSlat($xkoord, $ykoord), 6, '.', ''); |
| 28 | $lng = number_format($this->mapUtils()->CHtoWGSlng($xkoord, $ykoord), 6, '.', ''); |
| 29 | } else { |
| 30 | throw new \Exception("Either xkoord/ykoord or latitude/longitude must be set in OlzLocationMap"); |
| 31 | } |
| 32 | |
| 33 | $hash = md5("{$this->getNonce()}"); |
| 34 | $enc_hash = json_encode($hash); |
| 35 | $enc_name = json_encode($name); |
| 36 | $enc_lat = json_encode($lat); |
| 37 | $enc_lng = json_encode($lng); |
| 38 | $enc_zoom = json_encode($zoom); |
| 39 | |
| 40 | $lv95_e = $xkoord + 2000000; |
| 41 | $lv95_n = $ykoord + 1000000; |
| 42 | $zoom_swisstopo = $zoom - 5; |
| 43 | $swisstopo_url = "https://map.geo.admin.ch/?lang=de&bgLayer=ch.swisstopo.pixelkarte-farbe&layers=ch.bav.haltestellen-oev&E={$lv95_e}&N={$lv95_n}&zoom={$zoom_swisstopo}&crosshair=marker"; |
| 44 | return <<<ZZZZZZZZZZ |
| 45 | <a |
| 46 | href='{$swisstopo_url}' |
| 47 | target='_blank' |
| 48 | class='olz-location-map-link' |
| 49 | > |
| 50 | <div |
| 51 | id='olz-location-map-render-{$hash}' |
| 52 | class='olz-location-map-render test-flaky' |
| 53 | > |
| 54 | </div> |
| 55 | <script> |
| 56 | olz.olzLocationMapRender({$enc_hash}, {$enc_name}, {$enc_lat}, {$enc_lng}, {$enc_zoom}); |
| 57 | </script> |
| 58 | </a> |
| 59 | ZZZZZZZZZZ; |
| 60 | } |
| 61 | |
| 62 | protected function getNonce(): int { |
| 63 | return self::$nonce++; |
| 64 | } |
| 65 | } |