update map
This commit is contained in:
parent
058468c1b6
commit
efb65a72ce
@ -1,5 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount, onDestroy } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { browser } from "$app/environment";
|
import { browser } from "$app/environment";
|
||||||
import "ol/ol.css";
|
import "ol/ol.css";
|
||||||
import Map from "ol/Map";
|
import Map from "ol/Map";
|
||||||
@ -23,6 +23,7 @@
|
|||||||
let map;
|
let map;
|
||||||
let animationFrame;
|
let animationFrame;
|
||||||
let pulseProgress = 0;
|
let pulseProgress = 0;
|
||||||
|
let vectorLayer;
|
||||||
|
|
||||||
// Pulsing style function
|
// Pulsing style function
|
||||||
const createPulseStyle = (progress) => {
|
const createPulseStyle = (progress) => {
|
||||||
@ -36,31 +37,31 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Animation loop
|
// Animation loop function
|
||||||
const animate = () => {
|
const animate = () => {
|
||||||
pulseProgress = (pulseProgress + 0.02) % 1;
|
pulseProgress = (pulseProgress + 0.02) % 1;
|
||||||
vectorLayer
|
const feature = vectorLayer.getSource().getFeatures()[0];
|
||||||
.getSource()
|
if (feature) {
|
||||||
.getFeatures()[0]
|
feature.setStyle([
|
||||||
.setStyle([
|
|
||||||
new Style({
|
new Style({
|
||||||
image: new Circle({
|
image: new Circle({
|
||||||
radius: 6,
|
radius: 6,
|
||||||
fill: new Fill({
|
fill: new Fill({ color: "#2e86de" }),
|
||||||
color: "#2e86de",
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
createPulseStyle(pulseProgress),
|
createPulseStyle(pulseProgress),
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
animationFrame = requestAnimationFrame(animate);
|
animationFrame = requestAnimationFrame(animate);
|
||||||
};
|
};
|
||||||
|
|
||||||
let vectorLayer;
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!browser) return;
|
if (!browser) return;
|
||||||
|
|
||||||
|
// Determine if the user is on a mobile device.
|
||||||
|
// Here we use a simple viewport width check—adjust the threshold if needed.
|
||||||
|
const isMobile = window.innerWidth <= 640;
|
||||||
|
|
||||||
const whiteHousePoint = new Feature({
|
const whiteHousePoint = new Feature({
|
||||||
geometry: new Point(fromLonLat([LON, LAT])),
|
geometry: new Point(fromLonLat([LON, LAT])),
|
||||||
});
|
});
|
||||||
@ -90,16 +91,22 @@
|
|||||||
maxZoom: 18,
|
maxZoom: 18,
|
||||||
}),
|
}),
|
||||||
controls: [],
|
controls: [],
|
||||||
interactions: defaultInteractions({
|
// For mobile devices, disable all interactions to prevent dragging or zooming.
|
||||||
mouseWheelZoom: false, // Disable scroll zoom
|
interactions: isMobile
|
||||||
pinchZoom: false, // Disable pinch-to-zoom
|
? []
|
||||||
|
: defaultInteractions({
|
||||||
|
mouseWheelZoom: false, // Disable scroll zoom on desktop as well
|
||||||
|
pinchZoom: false, // Disable pinch-to-zoom on desktop
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
animate();
|
animate();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (map) map.setTarget(undefined);
|
cancelAnimationFrame(animationFrame);
|
||||||
|
if (map) {
|
||||||
|
map.setTarget(undefined);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user