|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Http\Controllers\API\v3\FontAwesome\v6; |
| 4 | + |
| 5 | +use App\Http\Controllers\Controller as Controller; |
| 6 | +use Illuminate\Http\Request; |
| 7 | +use Illuminate\Support\Str; |
| 8 | + |
| 9 | +class IconController extends Controller |
| 10 | +{ |
| 11 | + public function show(Request $request) |
| 12 | + { |
| 13 | + // GET ICON MARKUP |
| 14 | + try { |
| 15 | + $icon = $request->get('icon', ''); |
| 16 | + $iconPieces = explode(' ', $icon, 2); |
| 17 | + $iconSet = Str::replace('fa-', '', data_get($iconPieces, 0)) ?: 'solid'; |
| 18 | + $icon = Str::replace('fa-', '', data_get($iconPieces, 1)) ?: 'location-dot'; |
| 19 | + $iconFilePath = "icons/font-awesome-6/{$iconSet}/{$icon}.svg"; |
| 20 | + $iconMarkup = file_get_contents(resource_path($iconFilePath)); |
| 21 | + } catch (\Throwable $e) { |
| 22 | + // use default icon markup |
| 23 | + $iconMarkup = file_get_contents(resource_path('icons/font-awesome-6/solid/location-dot.svg')); |
| 24 | + } |
| 25 | + |
| 26 | + // GET ICON SIZE |
| 27 | + $size = $request->get('size', 100); |
| 28 | + |
| 29 | + // GET ICON COLOR |
| 30 | + $color = $request->get('color', '#333'); |
| 31 | + |
| 32 | + // GET LABEL |
| 33 | + $labelText = $request->get('label'); |
| 34 | + $labelTextSize = $size / 5; |
| 35 | + $labelColor = $request->get('labelColor', '#D9534F'); |
| 36 | + $labelFont = $request->get('labelFont', 'Arial'); |
| 37 | + $labelMarkup = ''; |
| 38 | + if ($labelText) { |
| 39 | + $labelMarkup = <<<EOD |
| 40 | + <!--! Icon Label --> |
| 41 | + <svg x="60%" y="60%" width="40%" height="40%" viewbox="0 0 100 100"> |
| 42 | + <circle cx="50%" cy="50%" fill="{$labelColor}" r="50%" /> |
| 43 | + <text x="50%" y="50%" fill="#fff" text-anchor="middle" dy=".3em" font-size="{$labelTextSize}" font-family="{$labelFont}">{$labelText}</text> |
| 44 | + </svg> |
| 45 | + EOD; |
| 46 | + } |
| 47 | + |
| 48 | + // COMPOSE MARKUP |
| 49 | + $mapMarkerMarkup = <<<EOD |
| 50 | + <svg fill="{$color}" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100" width="{$size}" height="{$size}"> |
| 51 | + <!--! Generated with MapMarker.io - https://mapmarker.io License - https://www.mapmarker.io/license --> |
| 52 | + {$iconMarkup} {$labelMarkup} |
| 53 | + </svg> |
| 54 | + EOD; |
| 55 | + |
| 56 | + return response($mapMarkerMarkup)->header('Content-Type', 'image/svg+xml'); |
| 57 | + } |
| 58 | +} |
0 commit comments