commit
This commit is contained in:
commit
0d4606d92c
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
node_modules
|
||||||
|
|
||||||
|
# Output
|
||||||
|
.output
|
||||||
|
.vercel
|
||||||
|
.netlify
|
||||||
|
.wrangler
|
||||||
|
/.svelte-kit
|
||||||
|
/build
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Env
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
!.env.test
|
||||||
|
|
||||||
|
# Vite
|
||||||
|
vite.config.js.timestamp-*
|
||||||
|
vite.config.ts.timestamp-*
|
||||||
6
.vscode/extensions.json
vendored
Normal file
6
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"svelte.svelte-vscode",
|
||||||
|
"bradlc.vscode-tailwindcss"
|
||||||
|
]
|
||||||
|
}
|
||||||
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"*.css": "tailwindcss"
|
||||||
|
}
|
||||||
|
}
|
||||||
42
README.md
Normal file
42
README.md
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# sv
|
||||||
|
|
||||||
|
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
|
||||||
|
|
||||||
|
## Creating a project
|
||||||
|
|
||||||
|
If you're seeing this, you've probably already done this step. Congrats!
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# create a new project
|
||||||
|
npx sv create my-app
|
||||||
|
```
|
||||||
|
|
||||||
|
To recreate this project with the same configuration:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# recreate this project
|
||||||
|
npx sv@0.16.1 create --template minimal --types ts --add tailwindcss="plugins:none" --install npm ./
|
||||||
|
```
|
||||||
|
|
||||||
|
## Developing
|
||||||
|
|
||||||
|
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# or start the server and open the app in a new browser tab
|
||||||
|
npm run dev -- --open
|
||||||
|
```
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
To create a production version of your app:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
You can preview the production build with `npm run preview`.
|
||||||
|
|
||||||
|
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|
||||||
4354
package-lock.json
generated
Normal file
4354
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
package.json
Normal file
29
package.json
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "svelte-ver3",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.1",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite dev",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"prepare": "svelte-kit sync || echo ''",
|
||||||
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@sveltejs/adapter-auto": "^7.0.1",
|
||||||
|
"@sveltejs/kit": "^2.63.0",
|
||||||
|
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
||||||
|
"@tailwindcss/vite": "^4.3.0",
|
||||||
|
"svelte": "^5.56.1",
|
||||||
|
"svelte-check": "^4.6.0",
|
||||||
|
"tailwindcss": "^4.3.0",
|
||||||
|
"typescript": "^6.0.3",
|
||||||
|
"vite": "^8.0.16"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@turf/turf": "^7.3.5",
|
||||||
|
"svelte-maplibre": "^1.3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/app.d.ts
vendored
Normal file
13
src/app.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// See https://svelte.dev/docs/kit/types#app.d.ts
|
||||||
|
// for information about these interfaces
|
||||||
|
declare global {
|
||||||
|
namespace App {
|
||||||
|
// interface Error {}
|
||||||
|
// interface Locals {}
|
||||||
|
// interface PageData {}
|
||||||
|
// interface PageState {}
|
||||||
|
// interface Platform {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {};
|
||||||
12
src/app.html
Normal file
12
src/app.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta name="text-scale" content="scale" />
|
||||||
|
%sveltekit.head%
|
||||||
|
</head>
|
||||||
|
<body data-sveltekit-preload-data="hover">
|
||||||
|
<div style="display: contents">%sveltekit.body%</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
BIN
src/lib/assets/car.png
Normal file
BIN
src/lib/assets/car.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 397 B |
1
src/lib/assets/favicon.svg
Normal file
1
src/lib/assets/favicon.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"><title>svelte-logo</title><path d="M94.157 22.819c-10.4-14.885-30.94-19.297-45.792-9.835L22.282 29.608A29.92 29.92 0 0 0 8.764 49.65a31.5 31.5 0 0 0 3.108 20.231 30 30 0 0 0-4.477 11.183 31.9 31.9 0 0 0 5.448 24.116c10.402 14.887 30.942 19.297 45.791 9.835l26.083-16.624A29.92 29.92 0 0 0 98.235 78.35a31.53 31.53 0 0 0-3.105-20.232 30 30 0 0 0 4.474-11.182 31.88 31.88 0 0 0-5.447-24.116" style="fill:#ff3e00"/><path d="M45.817 106.582a20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.503 18 18 0 0 1 .624-2.435l.49-1.498 1.337.981a33.6 33.6 0 0 0 10.203 5.098l.97.294-.09.968a5.85 5.85 0 0 0 1.052 3.878 6.24 6.24 0 0 0 6.695 2.485 5.8 5.8 0 0 0 1.603-.704L69.27 76.28a5.43 5.43 0 0 0 2.45-3.631 5.8 5.8 0 0 0-.987-4.371 6.24 6.24 0 0 0-6.698-2.487 5.7 5.7 0 0 0-1.6.704l-9.953 6.345a19 19 0 0 1-5.296 2.326 20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.502 17.99 17.99 0 0 1 8.13-12.052l26.081-16.623a19 19 0 0 1 5.3-2.329 20.72 20.72 0 0 1 22.237 8.243 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-.624 2.435l-.49 1.498-1.337-.98a33.6 33.6 0 0 0-10.203-5.1l-.97-.294.09-.968a5.86 5.86 0 0 0-1.052-3.878 6.24 6.24 0 0 0-6.696-2.485 5.8 5.8 0 0 0-1.602.704L37.73 51.72a5.42 5.42 0 0 0-2.449 3.63 5.79 5.79 0 0 0 .986 4.372 6.24 6.24 0 0 0 6.698 2.486 5.8 5.8 0 0 0 1.602-.704l9.952-6.342a19 19 0 0 1 5.295-2.328 20.72 20.72 0 0 1 22.237 8.242 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-8.13 12.053l-26.081 16.622a19 19 0 0 1-5.3 2.328" style="fill:#fff"/></svg>
|
||||||
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/lib/assets/point.png
Normal file
BIN
src/lib/assets/point.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 871 B |
1
src/lib/index.ts
Normal file
1
src/lib/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
// place files you want to import through the `$lib` alias in this folder.
|
||||||
9
src/routes/+layout.svelte
Normal file
9
src/routes/+layout.svelte
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import './layout.css';
|
||||||
|
import favicon from '$lib/assets/favicon.svg';
|
||||||
|
|
||||||
|
let { children } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head><link rel="icon" href={favicon} /></svelte:head>
|
||||||
|
{@render children()}
|
||||||
123
src/routes/+page.svelte
Normal file
123
src/routes/+page.svelte
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { MapLibre, Marker, GeoJSON, LineLayer, FillLayer, SymbolLayer, Popup } from "svelte-maplibre";
|
||||||
|
import * as turf from "@turf/turf";
|
||||||
|
import type { GeoJSON as GeoJSONType, Position } from 'geojson';
|
||||||
|
import pointIcon from '$lib/assets/point.png';
|
||||||
|
|
||||||
|
let route = $state<Array<Position>>([])
|
||||||
|
|
||||||
|
let point = $state<Position>([])
|
||||||
|
const radius = 20;
|
||||||
|
route = [
|
||||||
|
[-122.48369693756104, 37.83381888486939],
|
||||||
|
[-122.48348236083984, 37.83317489144141],
|
||||||
|
[-122.48339653015138, 37.83270036637107],
|
||||||
|
[-122.48356819152832, 37.832056363179625],
|
||||||
|
[-122.48404026031496, 37.83114119107971],
|
||||||
|
[-122.48404026031496, 37.83049717427869],
|
||||||
|
[-122.48348236083984, 37.829920943955045],
|
||||||
|
[-122.48356819152832, 37.82954808664175],
|
||||||
|
[-122.48507022857666, 37.82944639795659],
|
||||||
|
[-122.48610019683838, 37.82880236636284],
|
||||||
|
[-122.48695850372314, 37.82931081282506],
|
||||||
|
[-122.48700141906738, 37.83080223556934],
|
||||||
|
[-122.48751640319824, 37.83168351665737],
|
||||||
|
[-122.48803138732912, 37.832158048267786],
|
||||||
|
[-122.48888969421387, 37.83297152392784],
|
||||||
|
[-122.48987674713133, 37.83263257682617],
|
||||||
|
[-122.49043464660643, 37.832937629287755],
|
||||||
|
[-122.49125003814696, 37.832429207817725],
|
||||||
|
[-122.49163627624512, 37.832564787218985],
|
||||||
|
[-122.49223709106445, 37.83337825839438],
|
||||||
|
[-122.49378204345702, 37.83368330777276]
|
||||||
|
]
|
||||||
|
let popupich = $state('')
|
||||||
|
|
||||||
|
|
||||||
|
let routeGeoJSON = $derived<GeoJSONType>({
|
||||||
|
type: 'Feature',
|
||||||
|
properties:{},
|
||||||
|
geometry: {
|
||||||
|
type: 'LineString',
|
||||||
|
coordinates: route
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// let transportGeoJSON = $derived<GeoJSONType>({
|
||||||
|
// type: 'Feature',
|
||||||
|
// properties:{},
|
||||||
|
// geometry: {
|
||||||
|
// type: 'Point',
|
||||||
|
// coordinates: point
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
let transportGeoJSON: GeoJSONType = ({
|
||||||
|
type: 'Feature',
|
||||||
|
properties:{},
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: route[0]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
function pointOnCircle(angle: number) {
|
||||||
|
return [Math.cos(angle) * radius, Math.sin(angle) * radius]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function animateMarker(timestamp: number) {
|
||||||
|
// Update the data to a new position based on the animation timestamp. The
|
||||||
|
// divisor in the expression `timestamp / 1000` controls the animation speed.
|
||||||
|
// map.getSource('point').setData(pointOnCircle(timestamp / 1000));
|
||||||
|
transportGeoJSON.geometry.coordinates = pointOnCircle(timestamp / 1000)
|
||||||
|
console.log(transportGeoJSON.geometry.coordinates)
|
||||||
|
// Request the next frame of the animation.
|
||||||
|
requestAnimationFrame(animateMarker);
|
||||||
|
}
|
||||||
|
|
||||||
|
const button1 = () => {
|
||||||
|
// point = route[Math.floor(Math.random() * route.length)]
|
||||||
|
// console.log(transportGeoJSON)
|
||||||
|
animateMarker(0)
|
||||||
|
}
|
||||||
|
const button2 = () => {
|
||||||
|
point=[-122.48888969421387, 37.83297152392784]
|
||||||
|
}
|
||||||
|
// button1()
|
||||||
|
// button2()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<MapLibre style="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
|
||||||
|
center={[-122.48369693756104, 37.83381888486939]}
|
||||||
|
zoom={15}
|
||||||
|
standardControls
|
||||||
|
images={[
|
||||||
|
{id: 'point', url: pointIcon},
|
||||||
|
]}
|
||||||
|
class="h-[80vh]">
|
||||||
|
<GeoJSON data={routeGeoJSON}>
|
||||||
|
<LineLayer
|
||||||
|
layout={{'line-cap': 'round', 'line-join': 'round'}}
|
||||||
|
paint={{'line-color': '#112E81', 'line-width': 5, 'line-dasharray': [5,2]}}
|
||||||
|
/>
|
||||||
|
</GeoJSON>
|
||||||
|
<GeoJSON data={transportGeoJSON}>
|
||||||
|
<SymbolLayer
|
||||||
|
|
||||||
|
hoverCursor="pointer"
|
||||||
|
layout={{"icon-image": 'point', 'icon-size': 0.6}}
|
||||||
|
onclick={(e) => {popupich = e.features[0].geometry.coordinates}}
|
||||||
|
>
|
||||||
|
<Popup>
|
||||||
|
<p>{popupich}</p>
|
||||||
|
</Popup>
|
||||||
|
</SymbolLayer>
|
||||||
|
</GeoJSON>
|
||||||
|
|
||||||
|
</MapLibre>
|
||||||
|
<button onclick={button1} class="cursor-pointer">
|
||||||
|
<p>Кнопка 1</p>
|
||||||
|
</button>
|
||||||
|
<button onclick={button2} class="cursor-pointer">
|
||||||
|
<p>Кнопка 2</p>
|
||||||
|
</button>
|
||||||
1
src/routes/layout.css
Normal file
1
src/routes/layout.css
Normal file
@ -0,0 +1 @@
|
|||||||
|
@import 'tailwindcss';
|
||||||
141
src/routes/map/+page.svelte
Normal file
141
src/routes/map/+page.svelte
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { DefaultMarker, MapLibre, Marker, SymbolLayer, GeoJSON, LineLayer, Popup } from 'svelte-maplibre';
|
||||||
|
import type { GeoJSON as GeoJSONType, Position } from 'geojson';
|
||||||
|
import pointIcon from '$lib/assets/point.png';
|
||||||
|
import carIcon from '$lib/assets/car.png'
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
|
||||||
|
type LngLat = [number, number];
|
||||||
|
|
||||||
|
const route: Position[] = [
|
||||||
|
[-122.48369693756104, 37.83381888486939],
|
||||||
|
[-122.48348236083984, 37.83317489144141],
|
||||||
|
[-122.48339653015138, 37.83270036637107],
|
||||||
|
[-122.48356819152832, 37.832056363179625],
|
||||||
|
[-122.48404026031496, 37.83114119107971],
|
||||||
|
[-122.48404026031496, 37.83049717427869],
|
||||||
|
[-122.48348236083984, 37.829920943955045],
|
||||||
|
[-122.48356819152832, 37.82954808664175],
|
||||||
|
[-122.48507022857666, 37.82944639795659],
|
||||||
|
[-122.48610019683838, 37.82880236636284],
|
||||||
|
[-122.48695850372314, 37.82931081282506],
|
||||||
|
[-122.48700141906738, 37.83080223556934],
|
||||||
|
[-122.48751640319824, 37.83168351665737],
|
||||||
|
[-122.48803138732912, 37.832158048267786],
|
||||||
|
[-122.48888969421387, 37.83297152392784],
|
||||||
|
[-122.48987674713133, 37.83263257682617],
|
||||||
|
[-122.49043464660643, 37.832937629287755],
|
||||||
|
[-122.49125003814696, 37.832429207817725],
|
||||||
|
[-122.49163627624512, 37.832564787218985],
|
||||||
|
[-122.49223709106445, 37.83337825839438],
|
||||||
|
[-122.49378204345702, 37.83368330777276]
|
||||||
|
];
|
||||||
|
let routeGeoJSON = $derived<GeoJSONType>({
|
||||||
|
type: 'Feature',
|
||||||
|
properties:{},
|
||||||
|
geometry: {
|
||||||
|
type: 'LineString',
|
||||||
|
coordinates: route
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// Реактивная переменная для позиции маркера
|
||||||
|
let markerPosition: Position = $state(route[0]);
|
||||||
|
|
||||||
|
let animationId: number | null = null;
|
||||||
|
let currentSegment = 0;
|
||||||
|
let progress = 0;
|
||||||
|
const speed = 0.01;
|
||||||
|
let rotation = $state(0);
|
||||||
|
|
||||||
|
function getBearing(start: LngLat, end: LngLat): number {
|
||||||
|
const [lng1, lat1] = start;
|
||||||
|
const [lng2, lat2] = end;
|
||||||
|
const dLng = lng2 - lng1;
|
||||||
|
const y = Math.sin(dLng) * Math.cos(lat2);
|
||||||
|
const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLng);
|
||||||
|
return (Math.atan2(y, x) * 180) / Math.PI;
|
||||||
|
}
|
||||||
|
function getCurrentPosition(segment: number, t: number): LngLat {
|
||||||
|
const start = route[segment];
|
||||||
|
const end = route[(segment + 1) % route.length];
|
||||||
|
return [
|
||||||
|
start[0] + (end[0] - start[0]) * t,
|
||||||
|
start[1] + (end[1] - start[1]) * t
|
||||||
|
] as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
progress += speed;
|
||||||
|
progress += speed;
|
||||||
|
if (progress >= 1) {
|
||||||
|
progress = 0;
|
||||||
|
currentSegment = (currentSegment + 1) % route.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startPos = route[currentSegment];
|
||||||
|
const endPos = route[(currentSegment + 1) % route.length];
|
||||||
|
|
||||||
|
markerPosition = getCurrentPosition(currentSegment, progress);
|
||||||
|
rotation = getBearing(startPos as LngLat, endPos as LngLat);
|
||||||
|
|
||||||
|
animationId = requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем анимацию
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (animationId) cancelAnimationFrame(animationId);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<MapLibre
|
||||||
|
center={route[0] as LngLat}
|
||||||
|
zoom={15}
|
||||||
|
style="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
|
||||||
|
images={[
|
||||||
|
{id: 'point', url: pointIcon},
|
||||||
|
{id: 'car', url: carIcon}
|
||||||
|
]}
|
||||||
|
class="h-[80vh]"
|
||||||
|
standardControls
|
||||||
|
>
|
||||||
|
<GeoJSON data={routeGeoJSON}>
|
||||||
|
<LineLayer
|
||||||
|
layout={{'line-cap': 'round', 'line-join': 'round'}}
|
||||||
|
paint={{'line-color': '#112E81', 'line-width': 5, 'line-dasharray': [5,2]}}
|
||||||
|
/>
|
||||||
|
</GeoJSON>
|
||||||
|
<Marker bind:lngLat={markerPosition as LngLat} anchor="center" >
|
||||||
|
|
||||||
|
<div class="border-1 rounded-3xl p-1 bg-blue-100" >
|
||||||
|
<img
|
||||||
|
src={carIcon}
|
||||||
|
alt="car"
|
||||||
|
class="w-5 h-5 block"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="absolute inset-0 flex items-center justify-center pointer-events-none"
|
||||||
|
style="transform: rotate({rotation}deg);">
|
||||||
|
<div class="absolute -top-1">
|
||||||
|
<div class="w-0 h-0 border-l-[6px] border-r-[6px] border-b-[6px] border-b-blue-500 border-l-transparent border-r-transparent"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<Popup>
|
||||||
|
<p>0_0</p>
|
||||||
|
</Popup>
|
||||||
|
</Marker>
|
||||||
|
|
||||||
|
</MapLibre>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button onclick={animate} class="cursor-pointer">
|
||||||
|
start
|
||||||
|
</button>
|
||||||
|
<button onclick={() => {if (animationId) cancelAnimationFrame(animationId);}} class="cursor-pointer">
|
||||||
|
stop
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
141
src/routes/map/123123
Normal file
141
src/routes/map/123123
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { MapLibre, GeoJSON, SymbolLayer } from 'svelte-maplibre';
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
import type { GeoJSON as GeoJSONType, Position, Feature, Point } from 'geojson';
|
||||||
|
import pointIcon from '$lib/assets/point.png';
|
||||||
|
|
||||||
|
type LngLat = [number, number];
|
||||||
|
|
||||||
|
// Маршрут для анимации
|
||||||
|
const route: LngLat[] = [
|
||||||
|
[30.5, 50.5],
|
||||||
|
[30.6, 50.55],
|
||||||
|
[30.7, 50.5],
|
||||||
|
[30.8, 50.45],
|
||||||
|
[30.7, 50.4],
|
||||||
|
[30.5, 50.45],
|
||||||
|
[30.5, 50.5]
|
||||||
|
];
|
||||||
|
const promoteId = 'id';
|
||||||
|
// let isAnimating = false;
|
||||||
|
// Функция для расчёта азимута (поворота)
|
||||||
|
function getBearing(start: LngLat, end: LngLat): number {
|
||||||
|
const [lng1, lat1] = start;
|
||||||
|
const [lng2, lat2] = end;
|
||||||
|
const dLng = lng2 - lng1;
|
||||||
|
const y = Math.sin(dLng) * Math.cos(lat2);
|
||||||
|
const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLng);
|
||||||
|
return (Math.atan2(y, x) * 180) / Math.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentSegment = 0;
|
||||||
|
let progress = 0;
|
||||||
|
const speed = 0.005;
|
||||||
|
let animationId: number | null = null;
|
||||||
|
let coord = (route[0] as Position)
|
||||||
|
|
||||||
|
// ✅ GeoJSON данные с вашей структурой
|
||||||
|
let geojsonData: GeoJSONType = ({
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: [
|
||||||
|
{
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: coord
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
bearing: 0,
|
||||||
|
// можно добавить любые другие свойства
|
||||||
|
id: 'animated-point-1',
|
||||||
|
name: 'Моя точка'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
function getCurrentPosition(segment: number, t: number): Position {
|
||||||
|
const start = route[segment];
|
||||||
|
const end = route[(segment + 1) % route.length];
|
||||||
|
return [
|
||||||
|
start[0] + (end[0] - start[0]) * t,
|
||||||
|
start[1] + (end[1] - start[1]) * t
|
||||||
|
] as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
progress += speed;
|
||||||
|
if (progress >= 1) {
|
||||||
|
progress = 0;
|
||||||
|
currentSegment = (currentSegment + 1) % route.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startPos = route[currentSegment];
|
||||||
|
const endPos = route[(currentSegment + 1) % route.length];
|
||||||
|
const currentPos = getCurrentPosition(currentSegment, progress);
|
||||||
|
const bearing = getBearing(startPos, endPos);
|
||||||
|
|
||||||
|
// // ✅ Обновляем данные
|
||||||
|
// const updatedFeature: Feature<Point> = {
|
||||||
|
// type: 'Feature',
|
||||||
|
// geometry: {
|
||||||
|
// type: 'Point',
|
||||||
|
// coordinates: currentPos as Position
|
||||||
|
// },
|
||||||
|
// properties: {
|
||||||
|
// bearing: bearing,
|
||||||
|
// id: 'animated-point',
|
||||||
|
// name: 'Моя точка'
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
coord = currentPos
|
||||||
|
// geojsonData.features[0].geometry.coordinates = currentPos as Position;
|
||||||
|
// console.log(geojsonData.features[0].geometry.coordinates = currentPos as Position)
|
||||||
|
// geojsonData = {
|
||||||
|
// type: 'FeatureCollection',
|
||||||
|
// features: [updatedFeature]
|
||||||
|
// };
|
||||||
|
|
||||||
|
animationId = requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем анимацию
|
||||||
|
// animate();
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (animationId) cancelAnimationFrame(animationId);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<MapLibre
|
||||||
|
center={[30.5, 50.5]}
|
||||||
|
zoom={12}
|
||||||
|
class="h-[80vh]"
|
||||||
|
images={[
|
||||||
|
{id: 'point', url: pointIcon},
|
||||||
|
]}
|
||||||
|
style="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
|
||||||
|
standardControls
|
||||||
|
>
|
||||||
|
<!-- ✅ Ваш компонент GeoJSON с SymbolLayer -->
|
||||||
|
<GeoJSON data={geojsonData} id="animated-pointf" promoteId={promoteId}>
|
||||||
|
<SymbolLayer
|
||||||
|
hoverCursor="pointer"
|
||||||
|
layout={{
|
||||||
|
"icon-image": 'point',
|
||||||
|
"icon-size": 0.6,
|
||||||
|
// Добавляем поворот на основе свойства bearing
|
||||||
|
"icon-rotate": ['get', 'bearing'],
|
||||||
|
"icon-rotation-alignment": 'map',
|
||||||
|
"icon-overlap": 'always',
|
||||||
|
"icon-ignore-placement": true
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</GeoJSON>
|
||||||
|
</MapLibre>
|
||||||
|
<button onclick={animate} class="cursor-pointer">
|
||||||
|
<p>Кнопка 1</p>
|
||||||
|
</button>
|
||||||
|
<button onclick={() => {if (animationId) cancelAnimationFrame(animationId);}} class="cursor-pointer">
|
||||||
|
<p>Кнопка 2</p>
|
||||||
|
</button>
|
||||||
3
static/robots.txt
Normal file
3
static/robots.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# allow crawling everything by default
|
||||||
|
User-agent: *
|
||||||
|
Disallow:
|
||||||
20
tsconfig.json
Normal file
20
tsconfig.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"extends": "./.svelte-kit/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"rewriteRelativeImportExtensions": true,
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"strict": true,
|
||||||
|
"moduleResolution": "bundler"
|
||||||
|
}
|
||||||
|
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
|
||||||
|
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
|
||||||
|
//
|
||||||
|
// To make changes to top-level options such as include and exclude, we recommend extending
|
||||||
|
// the generated config; see https://svelte.dev/docs/kit/configuration#typescript
|
||||||
|
}
|
||||||
21
vite.config.ts
Normal file
21
vite.config.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import tailwindcss from '@tailwindcss/vite';
|
||||||
|
import adapter from '@sveltejs/adapter-auto';
|
||||||
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [
|
||||||
|
tailwindcss(),
|
||||||
|
sveltekit({
|
||||||
|
compilerOptions: {
|
||||||
|
// Force runes mode for the project, except for libraries. Can be removed in svelte 6.
|
||||||
|
runes: ({ filename }) => filename.split(/[/\\]/).includes('node_modules') ? undefined : true
|
||||||
|
},
|
||||||
|
|
||||||
|
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
|
||||||
|
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
||||||
|
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
|
||||||
|
adapter: adapter()
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user