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