Carte : remplace Leaflet CDN par bundle Vite local
Le CDN unpkg.com échoue si le serveur n'a pas accès à Internet. - npm install leaflet - resources/js/carte.js : point d'entrée qui importe Leaflet + expose window.LeafletMap - vite.config.js : ajoute carte.js aux inputs compilés - carte/index.blade.php : @vite au lieu du CDN, utilise window.LeafletMap Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Generated
+9
@@ -4,6 +4,9 @@
|
|||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
|
"dependencies": {
|
||||||
|
"leaflet": "^1.9.4"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/forms": "^0.5.2",
|
"@tailwindcss/forms": "^0.5.2",
|
||||||
"@tailwindcss/vite": "^4.0.0",
|
"@tailwindcss/vite": "^4.0.0",
|
||||||
@@ -2276,6 +2279,12 @@
|
|||||||
"vite": "^7.0.0"
|
"vite": "^7.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/leaflet": {
|
||||||
|
"version": "1.9.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.4.tgz",
|
||||||
|
"integrity": "sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==",
|
||||||
|
"license": "BSD-2-Clause"
|
||||||
|
},
|
||||||
"node_modules/lightningcss": {
|
"node_modules/lightningcss": {
|
||||||
"version": "1.32.0",
|
"version": "1.32.0",
|
||||||
"resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz",
|
"resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz",
|
||||||
|
|||||||
@@ -17,5 +17,8 @@
|
|||||||
"postcss": "^8.4.31",
|
"postcss": "^8.4.31",
|
||||||
"tailwindcss": "^3.1.0",
|
"tailwindcss": "^3.1.0",
|
||||||
"vite": "^7.0.7"
|
"vite": "^7.0.7"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"leaflet": "^1.9.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import L from 'leaflet';
|
||||||
|
import 'leaflet/dist/leaflet.css';
|
||||||
|
|
||||||
|
// Correction des icônes Leaflet avec Vite (les chemins par défaut ne fonctionnent pas avec bundler)
|
||||||
|
import markerIcon2x from 'leaflet/dist/images/marker-icon-2x.png';
|
||||||
|
import markerIcon from 'leaflet/dist/images/marker-icon.png';
|
||||||
|
import markerShadow from 'leaflet/dist/images/marker-shadow.png';
|
||||||
|
|
||||||
|
delete L.Icon.Default.prototype._getIconUrl;
|
||||||
|
L.Icon.Default.mergeOptions({
|
||||||
|
iconRetinaUrl: markerIcon2x,
|
||||||
|
iconUrl: markerIcon,
|
||||||
|
shadowUrl: markerShadow,
|
||||||
|
});
|
||||||
|
|
||||||
|
window.LeafletMap = L;
|
||||||
@@ -7,9 +7,8 @@
|
|||||||
</x-slot>
|
</x-slot>
|
||||||
|
|
||||||
@push('head')
|
@push('head')
|
||||||
{{-- Leaflet CSS --}}
|
{{-- Leaflet (bundlé via Vite) --}}
|
||||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
|
@vite('resources/js/carte.js')
|
||||||
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="">
|
|
||||||
<style>
|
<style>
|
||||||
#carte-map {
|
#carte-map {
|
||||||
height: calc(100vh - 120px);
|
height: calc(100vh - 120px);
|
||||||
@@ -45,13 +44,11 @@
|
|||||||
<div id="carte-map" class="w-full"></div>
|
<div id="carte-map" class="w-full"></div>
|
||||||
|
|
||||||
@push('head')
|
@push('head')
|
||||||
{{-- Leaflet JS (chargé en fin de head pour ne pas bloquer le rendu) --}}
|
|
||||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
|
||||||
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV/XN2GqM8=" crossorigin=""
|
|
||||||
defer></script>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
const L = window.LeafletMap;
|
||||||
|
if (!L) return;
|
||||||
|
|
||||||
// ── Initialisation de la carte ──────────────────────────────────────
|
// ── Initialisation de la carte ──────────────────────────────────────
|
||||||
const map = L.map('carte-map', {
|
const map = L.map('carte-map', {
|
||||||
center: [46.5, 2.2], // centre de la France
|
center: [46.5, 2.2], // centre de la France
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ import laravel from 'laravel-vite-plugin';
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
laravel({
|
laravel({
|
||||||
input: ['resources/css/app.css', 'resources/js/app.js'],
|
input: ['resources/css/app.css', 'resources/js/app.js', 'resources/js/carte.js'],
|
||||||
refresh: true,
|
refresh: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user