Skip to content

Commit

Permalink
feat(font awesome 6): implement icon pins using svgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonnx committed Nov 5, 2023
1 parent c342eef commit 6ffa574
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
65 changes: 65 additions & 0 deletions app/Http/Controllers/API/v3/FontAwesome/v6/PinController.php
@@ -0,0 +1,65 @@
<?php

namespace App\Http\Controllers\API\v3\FontAwesome\v6;

use App\Actions\FontAwesome\v6\GetIconMarkup;
use App\Actions\FontAwesome\v6\GetLabelMarkup;
use App\Http\Controllers\Controller as Controller;
use Illuminate\Http\Request;

class PinController extends Controller
{
public function show(Request $request)
{
if ($request->has('icon')) {
return $this->showIconPin($request);
} else {
return $this->showTextPin($request);
}
}

protected function showIconPin(Request $request)
{
// GET MARKER CONFIG
$markerSize = $request->get('size', 100);

// FOREGROUND ICON
$foregroundIcon = $request->get('icon') ?: null;
$foregroundIconColor = '#'.$request->get('color', '000');
$foregroundIconMarkup = GetIconMarkup::run($foregroundIcon);

// FOREGROUND ICON SHIFTING
$foregroundXShiftPercent = $request->get('hoffset', 0) / $markerSize * 100.00;
$foregroundYShiftPercent = $request->get('voffset', 0) / $markerSize * 100.00;

// FOREGROUND SIZING
$foregroundIconSize = $request->get('iconsize', $markerSize / 3);
$foregroundIconHeightPercent = $foregroundIconSize / $markerSize * 100.00;
$foregroundIconYOffset = 35 - ($foregroundIconHeightPercent / 2.00) + $foregroundYShiftPercent;
$foregroundIconXOffset = 0 + $foregroundXShiftPercent;

// BACKGROUND ICON
$backgroundIcon = 'fa-solid fa-location-pin';
$backgroundIconColor = '#'.$request->get('background', 'CCC');
$backgroundIconMarkup = GetIconMarkup::run($backgroundIcon);

// LABEL
$labelMarkup = GetLabelMarkup::run(request: $request, markerSize: $markerSize);

$mapMarkerMarkup = <<<EOD
<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100" width="{$markerSize}" height="{$markerSize}">
<!--! Generated with MapMarker.io - https://mapmarker.io License - https://www.mapmarker.io/license -->
<svg fill="{$backgroundIconColor}">
{$backgroundIconMarkup}
</svg>
<svg fill="{$foregroundIconColor}" height="{$foregroundIconHeightPercent}%" x="{$foregroundIconXOffset}%" y="{$foregroundIconYOffset}%">
{$foregroundIconMarkup}
</svg>
{$labelMarkup}
</svg>
EOD;

return response($mapMarkerMarkup)->header('Content-Type', 'image/svg+xml');
}
}
2 changes: 1 addition & 1 deletion resources/views/docs/versions.blade.php
Expand Up @@ -99,7 +99,7 @@
<td class="text-green-400">Yes</td>
<td class="text-green-400">Yes</td>
<td class="text-green-400">Yes</td>
<td class="text-orange-400">WIP</td>
<td class="text-green-400">Yes</td>
</tr>
<tr>
<td>Font-Awesome 4</td>
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Expand Up @@ -118,7 +118,7 @@
// FONT-AWESOME 6
Route::group(['prefix' => 'v6', 'namespace' => 'v6'], function () {
Route::get('icon', 'IconController@show');
// Route::get('pin', 'PinController@show');
Route::get('pin', 'PinController@show');
Route::get('icon-stack', 'IconStackController@show');
});
});
Expand Down

0 comments on commit 6ffa574

Please sign in to comment.