Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(font awesome 6): implement icon pins using svgs
- Loading branch information
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
app/Http/Controllers/API/v3/FontAwesome/v6/PinController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters