Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Traineratwot committed Jan 17, 2024
1 parent 844c20e commit 035275a
Show file tree
Hide file tree
Showing 12 changed files with 4,113 additions and 23 deletions.
3,889 changes: 3,889 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
plugins: {
"postcss-import": {},
"tailwindcss/nesting": {},
tailwindcss: {},
autoprefixer: {},
},
}
1 change: 1 addition & 0 deletions resources/dist/filament-openstreetmap.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions resources/dist/filament-openstreetmap.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions resources/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import VectorSource from 'ol/source/Vector'
import VectorLayer from 'ol/layer/Vector'
import { Modify } from 'ol/interaction'

function GetPointMap(id: string, x: number = 0, y: number = 0) {
function GetPointMap(id: string, lat: number = 0, lon: number = 0) {
const projection = 'EPSG:4326'

const mousePositionControl = new MousePosition({
Expand All @@ -25,7 +25,7 @@ function GetPointMap(id: string, x: number = 0, y: number = 0) {
})
let point = new Feature({
projection: projection,
geometry: new Point(fromLonLat([x, y])),
geometry: new Point(fromLonLat([lat, lon], projection)),
})
const vectorSource = new VectorSource({
features: [point],
Expand All @@ -46,7 +46,7 @@ function GetPointMap(id: string, x: number = 0, y: number = 0) {
target:target,
view: new View({
projection: projection,
center: [x, y],
center: fromLonLat([lat, lon], projection),
zoom: 10,
}),
})
Expand Down Expand Up @@ -75,8 +75,8 @@ function GetPointMap(id: string, x: number = 0, y: number = 0) {
console.log('no mouse position')
return
}
const [x, y] = coordsText.split(',').map((s) => parseFloat(s))
point.setGeometry(new Point(fromLonLat([x, y])))
const [lat, lon] = coordsText.split(',').map((s) => parseFloat(s))
point.setGeometry(new Point(fromLonLat([lat, lon], projection)))
})

return {
Expand All @@ -89,8 +89,8 @@ function GetPointMap(id: string, x: number = 0, y: number = 0) {
geom.setProperties({
projection: projection,
})
const [x, y] = geom.getCoordinates()
callback(x, y)
const [lat, lon] = geom.getCoordinates()
callback(lat, lon)
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions resources/lang/en/openstreetmap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

// translations for Traineratwot/FilamentOpenStreetMap
return [
//
];
4 changes: 2 additions & 2 deletions resources/views/forms/components/map.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
$rows = $getRows();
$shouldAutosize = $shouldAutosize();
$statePath = $getStatePath();
$startLat = $getX();
$startLon = $getY();
$startLat = $getLatitude();
$startLon = $getLongitude();
$initialHeight = (($rows ?? 2) * 1.5) + 0.75;
@endphp
<style>
Expand Down
7 changes: 7 additions & 0 deletions src/FilamentOpenStreetMap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Traineratwot\FilamentOpenStreetMap;

class FilamentOpenStreetMap
{
}
146 changes: 146 additions & 0 deletions src/FilamentOpenStreetMapServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php /** @noinspection PhpMultipleClassDeclarationsInspection */

namespace Traineratwot\FilamentOpenStreetMap;

use Filament\Support\Assets\Asset;
use Filament\Support\Assets\Css;
use Filament\Support\Assets\Js;
use Filament\Support\Facades\FilamentAsset;
use Filament\Support\Facades\FilamentIcon;
use Illuminate\Filesystem\Filesystem;
use Livewire\Features\SupportTesting\Testable;
use ReflectionException;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Traineratwot\FilamentOpenStreetMap\Testing\TestsFilamentOpenStreetMap;

class FilamentOpenStreetMapServiceProvider extends PackageServiceProvider
{
public static string $name = 'filament-openstreetmap';

public static string $viewNamespace = 'filament-openstreetmap';

public function configurePackage(Package $package): void
{
/*
* This class is a Package Service Provider
*
* More info: https://github.com/spatie/laravel-package-tools
*/
$package->name(static::$name)
->hasCommands($this->getCommands())
->hasInstallCommand(function (InstallCommand $command) {
$command
->publishConfigFile()
->publishMigrations()
->askToRunMigrations()
->askToStarRepoOnGitHub('traineratwot/filament-openstreetmap');
});

$configFileName = $package->shortName();

if (file_exists($package->basePath("/../config/{$configFileName}.php"))) {
$package->hasConfigFile();
}

if (file_exists($package->basePath('/../database/migrations'))) {
$package->hasMigrations($this->getMigrations());
}

if (file_exists($package->basePath('/../resources/lang'))) {
$package->hasTranslations();
}

if (file_exists($package->basePath('/../resources/views'))) {
$package->hasViews(static::$viewNamespace);
}
}

public function packageRegistered(): void
{
}

/**
* @throws ReflectionException
*/
public function packageBooted(): void
{
// Asset Registration
FilamentAsset::register(
$this->getAssets(),
$this->getAssetPackageName()
);

FilamentAsset::registerScriptData(
$this->getScriptData(),
$this->getAssetPackageName()
);

// Icon Registration
FilamentIcon::register($this->getIcons());

// Testing
Testable::mixin(new TestsFilamentOpenStreetMap());
}


protected function getAssetPackageName(): ?string
{
return 'traineratwot/filament-openstreetmap';
}

/**
* @return array<Asset>
*/
protected function getAssets(): array
{
return [
// AlpineComponent::make('filament-openstreetmap', __DIR__ . '/../resources/dist/components/filament-openstreetmap.js'),
Css::make('filament-openstreetmap-styles', __DIR__ . '/../resources/dist/filament-openstreetmap.css'),
Js::make('filament-openstreetmap-scripts', __DIR__ . '/../resources/dist/filament-openstreetmap.js'),
];
}

/**
* @return array<class-string>
*/
protected function getCommands(): array
{
return [];
}

/**
* @return array<string>
*/
protected function getIcons(): array
{
return [];
}

/**
* @return array<string>
*/
protected function getRoutes(): array
{
return [];
}

/**
* @return array<string, mixed>
*/
protected function getScriptData(): array
{
return [];
}

/**
* @return array<string>
*/
protected function getMigrations(): array
{
return [
'create_filament-openstreetmap_table',
];
}
}
28 changes: 14 additions & 14 deletions src/Forms/Components/MapInput.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection ClassMethodNameMatchesFieldNameInspection */

namespace Traineratwot\FilamentOpenStreetMap\Forms\Components;

Expand All @@ -17,40 +17,40 @@ class MapInput extends Textarea
* широта
* @var float|int| Closure
*/
protected float|int|Closure $x = 0;
protected float|int|Closure $latitude = 0;
/**
* longitude
* долгота
* @var float|int| Closure
*/
protected float|int|Closure $y = 0;
protected float|int|Closure $longitude = 0;

public function latitude(float|int|Closure $x): self
public function latitude(float|int|Closure $latitude): self
{
$this->x = $x;
$this->latitude = $latitude;
return $this;
}

public function longitude(float|int|Closure $y): self
public function longitude(float|int|Closure $longitude): self
{
$this->y = $y;
$this->longitude = $longitude;
return $this;
}

public function coordinates(float|int|Closure $x, float|int|Closure $y): self
public function coordinates(float|int|Closure $latitude, float|int|Closure $longitude): self
{
$this->x = $x;
$this->y = $y;
$this->latitude = $latitude;
$this->longitude = $longitude;
return $this;
}

public function getX(): ?int
public function getLatitude(): ?float
{
return $this->evaluate($this->x) ?: 0;
return $this->evaluate($this->latitude) ?: 0;
}

public function getY(): ?int
public function getLongitude(): ?float
{
return $this->evaluate($this->y) ?: 0;
return $this->evaluate($this->longitude) ?: 0;
}
}
13 changes: 13 additions & 0 deletions src/Testing/TestsFilamentOpenStreetMap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Traineratwot\FilamentOpenStreetMap\Testing;

use Livewire\Features\SupportTesting\Testable;

/**
* @mixin Testable
*/
class TestsFilamentOpenStreetMap
{
//
}
10 changes: 10 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const preset = require('./vendor/filament/filament/tailwind.config.preset')

module.exports = {
presets: [preset],
content: [
'./app/Filament/**/*.php',
'./resources/views/filament/**/*.blade.php',
'./vendor/filament/**/*.blade.php',
],
}

0 comments on commit 035275a

Please sign in to comment.