Giter VIP home page Giter VIP logo

Comments (5)

jasomdotnet avatar jasomdotnet commented on June 9, 2024 1

Okey, here we go. This is first locally working example:

<!DOCTYPE html>
<html lang="en">
    <head>
	<meta charset="utf-8" />
	<title>Example</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" href="screen.css" />
	<script src="https://leaflet.github.io/Leaflet.markercluster/example/realworld.50000.1.js"></script>
	<script src="https://leaflet.github.io/Leaflet.markercluster/example/realworld.50000.2.js"></script>
    </head>
    <body>
	<div id="progress"><div id="progress-bar"></div></div>
	<div id="map"></div>

	<link rel="stylesheet" href="leaflet.css" />
	<script src="leaflet-src.js"></script>
	<link rel="stylesheet" href="MarkerCluster.css" />
	<link rel="stylesheet" href="MarkerCluster.Default.css" />
	<script src="leaflet.markercluster-src.js"></script>
	<script src="leaflet.markercluster.layersupport-src.js"></script>
	<script >
	    var tiles = L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
		maxZoom: 18,
		attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Points &copy 2012 LINZ'
	    } ),
		latlng = L.latLng( -37.82, 175.24 );


	    var map = L.map( 'map', { center: latlng, zoom: 13, layers: [ tiles ] } );

	    var progress = document.getElementById( 'progress' );
	    var progressBar = document.getElementById( 'progress-bar' );

	    var mcgLayerSupportGroup = L.markerClusterGroup.layerSupport( {
		chunkedLoading: true,
		chunkInterval: 100,
		chunkProgress: updateProgressBar
	    } ),
		control = L.control.layers( null, null, { collapsed: false } );

	    var group1 = L.layerGroup( fillMarkerList( addressPoints ) ); // 25k points
	    var group2 = L.layerGroup( fillMarkerList( addressPoints2 ) ); // 25k points
	    var group3 = L.layerGroup( fillMarkerList( addressPoints ) ); // 25k points
	    var group4 = L.layerGroup( fillMarkerList( addressPoints2 ) ); // 25k points
	    //var superGroup = L.layerGroup([group1, group2, group3, group4]);

	    mcgLayerSupportGroup.addTo( map );

	    mcgLayerSupportGroup.checkIn( [ group1, group2, group3, group4 ] );

	    control.addOverlay( group1, 'First quarter' );
	    control.addOverlay( group2, 'Second quarter' );
	    control.addOverlay( group3, 'Third quarter' );
	    control.addOverlay( group4, 'Fourth quarter' );
	    //control.addOverlay(superGroup, 'Super Group');
	    control.addTo( map );

	    group1.addTo( map ); // Adding to map or to AutoMCG are now equivalent.
	    group2.addTo( map );
	    group3.addTo( map );
	    group4.addTo( map );
	    //mcgLayerSupportGroup.addLayer(superGroup);

	    function updateProgressBar( processed, total, elapsed, layersArray ) {
		console.log( "updateProgressBar" );
		if ( elapsed > 200 ) {
		    // if it takes more than a second to load, display the progress bar:
		    progress.style.display = 'block';
		    progressBar.style.width = Math.round( processed / total * 100 ) + '%';
		}
		if ( processed === total ) {
		    // all markers processed - hide the progress bar:
		    progress.style.display = 'none';
		}
	    }

	    function fillMarkerList( addressPointsSource ) {
		var markerList = [ ];
		for ( var i = 0; i < addressPointsSource.length; i++ ) {
		    var a = addressPointsSource[i];
		    var title = a[2];
		    var marker = L.marker( L.latLng( a[0], a[1] ), {
			title: title
		    } );
		    marker.bindPopup( title );
		    markerList.push( marker );
		}
		return markerList;
	    }

	</script>
    </body>
</html>

Pasting the code here so it may help somebody. Also linked this template from here.

Note: do not use resources left on unpkg.com, download them locally. You will find download links in example files when you open console.

from leaflet.markercluster.layersupport.

ghybs avatar ghybs commented on June 9, 2024 1

Hi,

I am glad you managed to get an example to your liking.

It is true the demo was not meant to be reproduced, but only to provide a live trial.

The quick guide was there for that. But maybe a working bootstrapping example would have provided an intermediate step.

from leaflet.markercluster.layersupport.

jasomdotnet avatar jasomdotnet commented on June 9, 2024

OMFG, I found it, what a feeling! It is in mcgLayerSupport-controlLayers-realworld.388.js file in the same folder. #ReverseEngineeringRetro

from leaflet.markercluster.layersupport.

jasomdotnet avatar jasomdotnet commented on June 9, 2024

This morning I glued Leaflet.MarkerCluster.LayerSupport in my app and it is perfect!

I saw that quick guide text and for me it was too technical (js guy writes for js guys).

I was disappointed with "live trial" source code, because there was no direct script configuration.

For example original Leafleat tutorials are easy to follow. Plug-ins should follow the pattern.

from leaflet.markercluster.layersupport.

ghybs avatar ghybs commented on June 9, 2024

Closing due to inactivity.
PR welcome if someone can submit! 🙏

from leaflet.markercluster.layersupport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.