Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

	<title>Multiple routes</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" href="" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin=""/>
	<script src=""
   integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" crossorigin=""></script>
   	<style>#mapid {width: 800px; height: 600px; border: 1px solid #ccc;}</style>
	<script src=""></script>
<div id="mapid"></div>
<script type="text/javascript">
	var mymap ='mapid');
	// Fallback view: North of the equator, along Greenwich Meridian.
	// If "bounds-finding" fails, one marker should show up on both East and West edges of the map!
	// My dataset of three routes: (1) a random line somewhere north of India (roughly), 
	// (2) the same but mirrored along Greenwich meridian, so it's across the Eastern USA and Cuba (roughly).
	// and (3) same as first but scaled 10x smaller towards (0,0).
	var routeData = [
		[[33, 77], [33, 88], [22, 77], [44, 66], [44, 99], [38.5, 93.5], [38.5, 77]],
		[[33, -77], [33, -88], [22, -77], [44, -66], [44, -99], [38.5, -93.5], [38.5, -77]],
		[[3, 7], [3, 8], [2, 7], [4, 6], [4, 9], [3.5, 9.5], [3.5, 7]]
	// add map layer with attributions
	L.tileLayer('https://cartodb-basemaps-{s}{z}/{x}/{y}.png', {
	maxZoom: 5, minZoom: 2, attribution: 'mapdata &copy; <a href="">OpenStreetMap</a>, styling &copy; <a href="">CartoDB</a>', subdomains: 'abcd'}).addTo(mymap);

	// automatic "bounds-finding" variable:
	var bounds = new L.LatLngBounds();
	//Here I'm using Leaflet.MarkerCluster --- I haven't figured out yet whether the problem lies here or not
	var markers = L.markerClusterGroup();
	// I'll loop through the routes (1,2,3; using variable j=0,1,2) then through the points on them (seven each, using variable i=0,1,..,6)
	// So there's an array of routes to be initialized, 
	// and each of them will get a polyline, 
	// and all those LatLong-pairs will end up together in an array of arrays called "latlngs":
	var routes = [];	
  var polyline = [];		
	var latlngs = [[]];

	for (var j = 0; j < routeData.length; j++) {
    latlngs[j] = []; // SOLUTION!
	// For each route: Declare it's a marker cluster/group, then 
		routes[j] = markers;
		for (var i = 0; i < routeData[j].length; i++) {
			var a = routeData[j][i];
			var loc = new L.LatLng(a[0], a[1]);
			var marker = L.marker(loc);
			marker.bindPopup('Route '.concat(String(j+1),', marker ', String(i+1)));
		polyline[j] = L.polyline(latlngs[j]).addTo(routes[j]);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.