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

Commit

Permalink
1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Traineratwot committed Jan 23, 2024
1 parent 4569190 commit 5e876e9
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 31 deletions.
6 changes: 0 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ All notable changes to `filament-openstreetmap` will be documented in this file.

Fix composer version required

## 1.1.1 - 2024-01-22

**Full Changelog**: https://github.com/Traineratwot/filament-openstreetmap/compare/1.1.0...1.1.1

fix composer version required

## 1.1.0 - 2024-01-18

**Full Changelog**: https://github.com/Traineratwot/filament-openstreetmap/compare/1.0.0...1.1.0
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "traineratwot/filament-openstreetmap",
"version": "1.2.0",
"version": "1.2.1",
"description": "This is my package filament-openstreetmap",
"keywords": [
"Traineratwot",
Expand Down
6 changes: 6 additions & 0 deletions resources/css/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
.gcd-txt-control {
color: #09090b !important;
}
&.disabled{
pointer-events: none;
.gcd-gl-control{
pointer-events: none;
}
}

.center {
z-index: 9999 !important;
Expand Down
2 changes: 1 addition & 1 deletion resources/dist/filament-openstreetmap.css

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

2 changes: 1 addition & 1 deletion resources/dist/filament-openstreetmap.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions resources/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class mPoint {
}
}

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

const mousePositionControl = new MousePosition({
Expand All @@ -61,7 +61,7 @@ function GetPointMap(id: string, lat: number = 0, lon: number = 0) {
const view = new View({
projection: projection,
center: fromLonLat([lat, lon], projection),
zoom: 10,
zoom: zoom,
})
const map = new Map({
controls: defaultControls().extend([mousePositionControl]),
Expand Down
30 changes: 22 additions & 8 deletions resources/views/forms/components/map.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$statePath = $getStatePath();
$startLat = $getLatitude();
$startLon = $getLongitude();
$zoom = $getZoom();
$initialHeight = (($rows ?? 2) * 1.5) + 0.75;
@endphp
<style>
Expand Down Expand Up @@ -40,7 +41,7 @@

>

<div class="open-street-map" id="OSMap-{{ $getId() }}" style="height: max(500px, 100%);width: max(100px, 100%)">
<div class="open-street-map @if($isDisabled) disabled @endif" id="OSMap-{{ $getId() }}" style="height: max(500px, 100%);width: max(100px, 100%)">
<div class="center"></div>
</div>

Expand Down Expand Up @@ -106,6 +107,11 @@

<script type="text/javascript" class="filament-open-street-map">
setInterval(() => {
const map = document.getElementById('OSMap-{{ $getId() }}')
let disabled = false
if (map.classList.contains('disabled')) {
disabled = true
}
let point
if (typeof window.traineratwot !== 'undefined') {
const input = document.getElementById('{{ $getId() }}')
Expand All @@ -125,15 +131,17 @@
}
}
if (!document.getElementById('OSMap-{{ $getId() }}').classList.contains('map-done')) {
point = window.traineratwot.GetPointMap('{{ $getId() }}', {{ $startLat }}, {{ $startLon }})
if (!map.classList.contains('map-done')) {
point = window.traineratwot.GetPointMap('{{ $getId() }}', {{ $startLat }}, {{ $startLon }}, {{ $zoom }})
input.addEventListener('input', compare)
compare()
point.onChange(function(x, y) {
input.value = `${x}, ${y}`
input.dispatchEvent(new Event('input'))
input.dispatchEvent(new Event('change'))
input.dispatchEvent(new Event('blur'))
if (!disabled) {
input.value = `${x}, ${y}`
input.dispatchEvent(new Event('input'))
input.dispatchEvent(new Event('change'))
input.dispatchEvent(new Event('blur'))
}
})
reset.addEventListener('click', () => {
Expand All @@ -142,9 +150,15 @@
input.dispatchEvent(new Event('change'))
input.dispatchEvent(new Event('blur'))
})
if (disabled) {
if (input.value !== '{{ $startLat }}, {{ $startLon }}') {
reset.click()
compare()
}
}
}
}
}, 200)
</script>
Expand Down
54 changes: 42 additions & 12 deletions src/Forms/Components/MapInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ class MapInput extends Textarea
* @var 'Point'|'String'|'Array'
*/
public string $saveAs = 'String';
private Closure|int|float $zoom = 10;

/**
* latitude
* широта
*/
protected float|int|Closure $latitude = 0;

/**
* longitude
* долгота
*/
protected float|int|Closure $longitude = 0;

protected function setUp(): void
{
Expand Down Expand Up @@ -55,18 +68,6 @@ protected function setUp(): void
$this->rules([new GeoPoint()]);
}

/**
* latitude
* широта
*/
protected float|int|Closure $latitude = 0;

/**
* longitude
* долгота
*/
protected float|int|Closure $longitude = 0;

public function saveAsPoint(): static
{
$this->saveAs = 'Point';
Expand Down Expand Up @@ -138,20 +139,44 @@ protected function parseInput(mixed $state): array
];
}

/**
* @param float|int|Closure $zoom 1-20 (default 10)
* @return $this
*/
public function zoom(float|int|Closure $zoom): static
{
$this->zoom = $zoom;

return $this;
}

/**
* @param float|int|Closure $latitude
* @return $this
*/
public function latitude(float|int|Closure $latitude): static
{
$this->latitude = $latitude;

return $this;
}

/**
* @param float|int|Closure $longitude
* @return $this
*/
public function longitude(float|int|Closure $longitude): static
{
$this->longitude = $longitude;

return $this;
}

/**
* @param float|int|Closure $latitude
* @param float|int|Closure $longitude
* @return $this
*/
public function coordinates(float|int|Closure $latitude, float|int|Closure $longitude): static
{
$this->latitude = $latitude;
Expand All @@ -173,4 +198,9 @@ public function getLongitude(): ?float

return $a['longitude'] ?: $this->evaluate($this->longitude) ?: 0;
}

public function getZoom(): ?float
{
return $this->evaluate($this->zoom) ?: 10;
}
}

0 comments on commit 5e876e9

Please sign in to comment.