1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| <!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cartographie</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet-src.js" crossorigin=""></script>
<link rel="stylesheet" href="C:/Users/name.name/node_modules/leaflet.control.layers.tree/L.Control.Layers.Tree.css"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="C:/Users/name.name/node_modules/leaflet.control.layers.tree/L.Control.Layers.Tree.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster/dist/MarkerCluster.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster/dist/MarkerCluster.Default.css" />
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0;
font-family: Arial, sans-serif;
}
#title-container h1 {
color: #500838;
font-size: 28px;
font-weight: bold;
font-family: Arial, sans-serif;
margin-bottom: 10px;
text-align: center;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
#map {
width: 100%;
height: calc(100% - 120px); /* Ajusté pour inclure la barre de légende */
}
#legend-container {
position: absolute;
bottom: 0;
left: 0;
width: 100%; /* Largeur du conteneur de légende */
background-color: white;
border-top: 1px solid #ccc;
display: flex;
justify-content: center;
align-items: center;
font-size: 14px;
padding: 10px 0;
height: 80px;
box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.2);
}
#legend {
width: 80%;
background-color: white;
padding: 10px;
border: 1px solid #4d081f;
border-radius: 5px;
}
.leaflet-control-layers {
max-width: 250px;
word-wrap: break-word;
}
.leaflet-control-layers-expanded {
max-width: 250px;
word-wrap: break-word;
}
.leaflet-control-layers-bottomleft {
bottom: 250px;
left: 250px;
}
.leaflet-popup-content {
font-family: Arial, sans-serif;
}
.leaflet-popup-content h3 {
color: rgb(155, 5, 105) !important;
font-size: 20px;
font-weight: bold;
text-shadow: 2px 2px 4 px rgba(0,0,0,0.5);
}
img {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<div id="title-container">
<h1>Cartographie</h1>
</div>
<div id="map"></div>
<div id="legend-container">
<div id="legend"></div>
</div>
<script type="text/javascript">
var center = [40, 0];
var osm = L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{ attribution: '© OpenStreetMap contributors' }
);
var map = L.map('map', {
layers: [osm],
center: center,
zoom: 5
});
// Fonction pour générer du contenu HTML de popup
var createPopupContent = function (title, description, imageUrl, partners, learnMoreUrl) {
var htmlContent = '<h3>' + title + '</h3>';
htmlContent += '<p>' + description + '</p>';
if (imageUrl && imageUrl.trim() !== "") {
htmlContent += '<img src="' + imageUrl + '" alt="Image for ' + title + '" width="100" height="100">';
}
if (partners && partners.trim() !== "") {
htmlContent += '<p><strong>Partenaires:</strong> ' + partners + '</p>';
}
if (learnMoreUrl && learnMoreUrl.trim() !== "") {
htmlContent += '<p><a href="' + learnMoreUrl + '" target="_blank">En savoir plus</a></p>';
}
return htmlContent;
};
// icônes personnalisées
var redIcon = L.icon({
iconUrl: 'Images_tree/pointgpsred.png',
iconSize: [45, 40],
iconAnchor: [25, 35],
popupAnchor: [1, -25],
shadowUrl: 'https://unpkg.com/leaflet@1.7.1/dist/images/marker-shadow.png',
shadowSize: [50, 25]
});
// groupes de couches
var expertisegroup = L.layerGroup([
L.marker([48.552, 2.316], {icon: redIcon}).bindPopup(createPopupContent('Mission d\'expertise', 'Contribution aux travaux de la mission', '', '', '')),
L.marker([43.3316, 5.4582], {icon:redIcon}).bindPopup(createPopupContent('Expertise', 'Projets', '', '', '')),
]);
var crogroup = L.layerGroup([
L.marker([48.5237, 2.7867], {icon:redIcon}).bindPopup(createPopupContent('Interview sur la presse', 'Il a été invité pour parler de la presse', '', '', ''))
]);
var larcangroup = L.layerGroup([
L.marker([43.316, 5.4582], {icon:redIcon}).bindPopup(createPopupContent('Expertise en matière de droit', '', '', '', '')),
L.marker([48.672, 2.8259], {icon:redIcon}).bindPopup(createPopupContent('Ecriture', 'Edition', '', '', ''))
]);
var projetsaction = {
label: 'Projets',
selectAllCheckbox: true,
children: [
{ label: 'Centre',
selectAllCheckbox: true,
children: [
{label: 'CRO', layer: crogroup },
{label: 'Arcane', layer: larcangroup }
]},
{ label: 'Type d\'action',
selectAllCheckbox: true,
children: [
{ label: 'Expertise', layer: expertisegroup }
]}
]
};
var makePopups = function (node) {
if (node.layer && node.popupContent) {
node.layer.bindPopup(node.popupContent);
}
if (node.children) {
node.children.forEach(function (element) { makePopups(element); });
}
};
// Appel de la fonction pour créer les popups
makePopups(projetsaction);
var ctl = L.control.layers.tree(null, projetsaction, {
namedToggle: true,
collapseAll: 'Collapse all',
expandAll: 'Expand all',
collapsed: false
});
ctl.addTo(map).collapseTree(true).expandSelected(true).SetSelected();
// Déplacer le contrôle des couches dans le conteneur de légende
var legendContainer = document.getElementById('legend');
var layersControlElement = document.querySelector('.leaflet-control-layers');
legendContainer.appendChild(layersControlElement);
</script>
</body>
</html> |
Partager