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

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Traineratwot committed Jun 17, 2024
1 parent d68a75a commit 5146b30
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 106 deletions.
18 changes: 9 additions & 9 deletions resources/dist/filament-openstreetmap.js

Large diffs are not rendered by default.

196 changes: 100 additions & 96 deletions resources/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,115 +12,119 @@ import VectorLayer from 'ol/layer/Vector'
import { Point } from 'ol/geom'
import Geocoder from 'ol-geocoder'
import { Icon, Style } from 'ol/style'

window['traineratwot'] = {}

class mPoint {
constructor(public view: View, public projection: ProjectionLike) {
}
try {

public onChange(callback: (lon: number, lat: number) => void) {
try {
this.view.on('change', () => {
const [lat, lon] = this.getCoordinates()
callback(lat, lon)
})
} catch (e) {
console.error(e)
class mPoint {
constructor(public view: View, public projection: ProjectionLike) {
}
}

public getCoordinates() {
return this.view.getCenter()
}
public onChange(callback: (lon: number, lat: number) => void) {
try {
this.view.on('change', () => {
const [lat, lon] = this.getCoordinates()
callback(lat, lon)
})
} catch (e) {
console.error(e)
}
}

public setCoordinates(lat: number, lon: number) {
this.view.setCenter(fromLonLat([lat, lon], this.projection))
public getCoordinates() {
return this.view.getCenter()
}

public setCoordinates(lat: number, lon: number) {
this.view.setCenter(fromLonLat([lat, lon], this.projection))
}
}
}

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

const mousePositionControl = new MousePosition({
coordinateFormat: createStringXY(4),
projection: projection,
className: `mouse-position-${id}`,
target: document.getElementById(`OSMap-${id}`),
})
let point = new Feature({
projection: projection,
geometry: new Point(fromLonLat([lat, lon], projection)),
})
const vectorSource = new VectorSource({
features: [point],
})
const vectorLayer = new VectorLayer({
source: vectorSource,
})
const MapLayer = new TileLayer({
source: new OSM(),
})
const target = document.getElementById(`OSMap-${id}`)
const mousePositionControl = new MousePosition({
coordinateFormat: createStringXY(4),
projection: projection,
className: `mouse-position-${id}`,
target: document.getElementById(`OSMap-${id}`),
})
let point = new Feature({
projection: projection,
geometry: new Point(fromLonLat([lat, lon], projection)),
})
const vectorSource = new VectorSource({
features: [point],
})
const vectorLayer = new VectorLayer({
source: vectorSource,
})
const MapLayer = new TileLayer({
source: new OSM(),
})
const target = document.getElementById(`OSMap-${id}`)

const view = new View({
projection: projection,
center: fromLonLat([lat, lon], projection),
zoom: zoom,
})
const map = new Map({
controls: defaultControls().extend([mousePositionControl]),
layers: [
MapLayer,
vectorLayer,
],
target: target,
view: view,
})
const geocoder = new Geocoder('nominatim', {
provider: 'osm',
lang: lang, //en-US, fr-FR
placeholder: 'Поиск...',
limit: 5,
keepOpen: true,
})
map.addControl(geocoder)
try {
geocoder.on('addresschosen', function(evt: any) {
console.log(evt)
const feature = evt.feature as Feature<Point>
const coordinate = evt.coordinate as Coordinate
feature.setStyle(new Style({
image: new Icon({
color: 'rgba(0, 0, 0, 0)',
crossOrigin: 'anonymous',
src: 'https://openlayers.org/en/latest/examples/data/dot.png',
scale: 0.01,
}),
}))
// application specific
view.setCenter(fromLonLat([coordinate[0], coordinate[1]], projection))
const view = new View({
projection: projection,
center: fromLonLat([lat, lon], projection),
zoom: zoom,
})
} catch (e) {
console.error(e)
}
const map = new Map({
controls: defaultControls().extend([mousePositionControl]),
layers: [
MapLayer,
vectorLayer,
],
target: target,
view: view,
})
const geocoder = new Geocoder('nominatim', {
provider: 'osm',
lang: lang, //en-US, fr-FR
placeholder: 'Поиск...',
limit: 5,
keepOpen: true,
})
map.addControl(geocoder)
try {
geocoder.on('addresschosen', function(evt: any) {
console.log(evt)
const feature = evt.feature as Feature<Point>
const coordinate = evt.coordinate as Coordinate
feature.setStyle(new Style({
image: new Icon({
color: 'rgba(0, 0, 0, 0)',
crossOrigin: 'anonymous',
src: 'https://openlayers.org/en/latest/examples/data/dot.png',
scale: 0.01,
}),
}))
// application specific
view.setCenter(fromLonLat([coordinate[0], coordinate[1]], projection))
})
} catch (e) {
console.error(e)
}

function updateCenter() {
// Получаем новые координаты центра карты
const [lat, lon] = map.getView().getCenter()
// Обновляем координаты точки
point.getGeometry().setCoordinates([lat, lon])
}
function updateCenter() {
// Получаем новые координаты центра карты
const [lat, lon] = map.getView().getCenter()
// Обновляем координаты точки
point.getGeometry().setCoordinates([lat, lon])
}

try {
map.on('movestart', updateCenter)
map.on('moveend', updateCenter)
} catch (e) {
console.error(e)
try {
map.on('movestart', updateCenter)
map.on('moveend', updateCenter)
} catch (e) {
console.error(e)
}
target.classList.add('map-done')
return new mPoint(view, projection)
}
target.classList.add('map-done')
return new mPoint(view, projection)
}

window['traineratwot'].GetPointMap = GetPointMap
window['traineratwot'].GetPointMap = GetPointMap

} catch (e) {

}
1 change: 0 additions & 1 deletion src/FilamentOpenStreetMapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ protected function getAssetPackageName(): ?string
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'),
];
Expand Down

0 comments on commit 5146b30

Please sign in to comment.