Procházet zdrojové kódy

add clustering to structures map

Olivier Massot před 4 roky
rodič
revize
5ab404b589

+ 14 - 0
ot_templating/Resources/Private/Partials/Classic/Assets.html

@@ -29,6 +29,16 @@ Assets included with the VHS viewhelpers
                rewrite="0"
                rewrite="0"
                standalone="1"/>
                standalone="1"/>
 
 
+<v:asset.style name="classic-leaflet-clusters-css"
+               path="{assets_dir}/style/ext/MarkerCluster.css"
+               rewrite="0"
+               standalone="1"/>
+
+<v:asset.style name="classic-leaflet-clusters-default-css"
+               path="{assets_dir}/style/ext/MarkerCluster.Default.css"
+               rewrite="0"
+               standalone="1"/>
+
 <f:comment><!-- Theme's file shall not be rewritten since
 <f:comment><!-- Theme's file shall not be rewritten since
                 it may not be updated from a website to another --></f:comment>
                 it may not be updated from a website to another --></f:comment>
 <v:asset.style name="classic-theme"
 <v:asset.style name="classic-theme"
@@ -56,6 +66,10 @@ Assets included with the VHS viewhelpers
                 path="{assets_dir}/script/leaflet.js"
                 path="{assets_dir}/script/leaflet.js"
                 defer="1"/>
                 defer="1"/>
 
 
+<v:asset.script name="classic-leaflet-clusters"
+                path="{assets_dir}/script/leaflet.markercluster.js"
+                defer="1"/>
+
 <v:asset.script name="classic-main"
 <v:asset.script name="classic-main"
                 path="{assets_dir}/script/main.js"
                 path="{assets_dir}/script/main.js"
                 dependencies="classic-jquery,classic-datepicker,classic-slick,classic-leaflet"
                 dependencies="classic-jquery,classic-datepicker,classic-slick,classic-leaflet"

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
ot_templating/Resources/Public/assets/Classic/script/leaflet.markercluster.js


+ 14 - 9
ot_templating/Resources/Public/assets/Classic/script/main.js

@@ -251,27 +251,32 @@ $(document).ready(function(){
         showMap(mapDiv, false);
         showMap(mapDiv, false);
 
 
         let greySquareIcon = L.divIcon({
         let greySquareIcon = L.divIcon({
-            html: '<svg style="width:5px;height:5px;fill:#808080" width="512px" height="512px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><title>ionicons-v5-q</title><path d="M416,464H96a48.05,48.05,0,0,1-48-48V96A48.05,48.05,0,0,1,96,48H416a48.05,48.05,0,0,1,48,48V416A48.05,48.05,0,0,1,416,464Z"/></svg>',
+            html: '<svg style="width:5px;height:5px;fill:#808080" width="512px" height="512px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="M416,464H96a48.05,48.05,0,0,1-48-48V96A48.05,48.05,0,0,1,96,48H416a48.05,48.05,0,0,1,48,48V416A48.05,48.05,0,0,1,416,464Z"/></svg>',
             className: "",
             className: "",
             iconSize: [5, 5],
             iconSize: [5, 5],
             iconAnchor: [0, 10],
             iconAnchor: [0, 10],
         });
         });
 
 
+        var clusters = L.markerClusterGroup();
+
         let allStructures = mapDiv.data('all-structures') ?? [];
         let allStructures = mapDiv.data('all-structures') ?? [];
         allStructures.forEach(function (item) {
         allStructures.forEach(function (item) {
-            L.marker([item.lat, item.long], { icon: greySquareIcon, zIndexOffset: -1 }).addTo(map);
+            // L.marker([item.lat, item.long], { icon: greySquareIcon, zIndexOffset: -1 }).addTo(map);
+            clusters.addLayer(L.marker([item.lat, item.long], { icon: greySquareIcon, zIndexOffset: -1 }))
         });
         });
+        map.addLayer(clusters);
 
 
-        let orangeSquareIcon = L.divIcon({
-            html: '<svg style="width:8px;height:8px;fill:#e4611b" width="512px" height="512px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><title>ionicons-v5-q</title><path d="M416,464H96a48.05,48.05,0,0,1-48-48V96A48.05,48.05,0,0,1,96,48H416a48.05,48.05,0,0,1,48,48V416A48.05,48.05,0,0,1,416,464Z"/></svg>',
-            className: "",
-            iconSize: [8, 8],
-            iconAnchor: [0, 16],
-        });
+        // let orangeSquareIcon = L.divIcon({
+        //     html: '<svg style="width:8px;height:8px;fill:#e4611b" width="512px" height="512px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><title>ionicons-v5-q</title><path d="M416,464H96a48.05,48.05,0,0,1-48-48V96A48.05,48.05,0,0,1,96,48H416a48.05,48.05,0,0,1,48,48V416A48.05,48.05,0,0,1,416,464Z"/></svg>',
+        //     className: "",
+        //     iconSize: [8, 8],
+        //     iconAnchor: [0, 16],
+        // });
 
 
         let selectedStructures = mapDiv.data('selected-structures') ?? [];
         let selectedStructures = mapDiv.data('selected-structures') ?? [];
         selectedStructures.forEach(function (item) {
         selectedStructures.forEach(function (item) {
-            L.marker([item.lat, item.long], { icon: orangeSquareIcon }).addTo(map);
+            L.marker([item.lat, item.long]).addTo(map);
+            // L.marker([item.lat, item.long], { icon: orangeSquareIcon }).addTo(map);
         });
         });
     }
     }
 
 

+ 60 - 0
ot_templating/Resources/Public/assets/Classic/style/ext/MarkerCluster.Default.css

@@ -0,0 +1,60 @@
+.marker-cluster-small {
+	background-color: rgba(181, 226, 140, 0.6);
+	}
+.marker-cluster-small div {
+	background-color: rgba(110, 204, 57, 0.6);
+	}
+
+.marker-cluster-medium {
+	background-color: rgba(241, 211, 87, 0.6);
+	}
+.marker-cluster-medium div {
+	background-color: rgba(240, 194, 12, 0.6);
+	}
+
+.marker-cluster-large {
+	background-color: rgba(253, 156, 115, 0.6);
+	}
+.marker-cluster-large div {
+	background-color: rgba(241, 128, 23, 0.6);
+	}
+
+	/* IE 6-8 fallback colors */
+.leaflet-oldie .marker-cluster-small {
+	background-color: rgb(181, 226, 140);
+	}
+.leaflet-oldie .marker-cluster-small div {
+	background-color: rgb(110, 204, 57);
+	}
+
+.leaflet-oldie .marker-cluster-medium {
+	background-color: rgb(241, 211, 87);
+	}
+.leaflet-oldie .marker-cluster-medium div {
+	background-color: rgb(240, 194, 12);
+	}
+
+.leaflet-oldie .marker-cluster-large {
+	background-color: rgb(253, 156, 115);
+	}
+.leaflet-oldie .marker-cluster-large div {
+	background-color: rgb(241, 128, 23);
+}
+
+.marker-cluster {
+	background-clip: padding-box;
+	border-radius: 20px;
+	}
+.marker-cluster div {
+	width: 30px;
+	height: 30px;
+	margin-left: 5px;
+	margin-top: 5px;
+
+	text-align: center;
+	border-radius: 15px;
+	font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif;
+	}
+.marker-cluster span {
+	line-height: 30px;
+	}

+ 14 - 0
ot_templating/Resources/Public/assets/Classic/style/ext/MarkerCluster.css

@@ -0,0 +1,14 @@
+.leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow {
+	-webkit-transition: -webkit-transform 0.3s ease-out, opacity 0.3s ease-in;
+	-moz-transition: -moz-transform 0.3s ease-out, opacity 0.3s ease-in;
+	-o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in;
+	transition: transform 0.3s ease-out, opacity 0.3s ease-in;
+}
+
+.leaflet-cluster-spider-leg {
+	/* stroke-dashoffset (duration and function) should match with leaflet-marker-icon transform in order to track it exactly */
+	-webkit-transition: -webkit-stroke-dashoffset 0.3s ease-out, -webkit-stroke-opacity 0.3s ease-in;
+	-moz-transition: -moz-stroke-dashoffset 0.3s ease-out, -moz-stroke-opacity 0.3s ease-in;
+	-o-transition: -o-stroke-dashoffset 0.3s ease-out, -o-stroke-opacity 0.3s ease-in;
+	transition: stroke-dashoffset 0.3s ease-out, stroke-opacity 0.3s ease-in;
+}

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů