Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-tile-loading-progress-control

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-tile-loading-progress-control - npm Package Compare versions

Comparing version 0.0.3 to 1.0.0

rollup.config.js

2

bower.json
{
"name": "leaflet-tile-loading-progress-control",
"version": "0.0.3",
"version": "1.0.0",
"homepage": "https://github.com/jbccollins/leaflet-tile-loading-progress-control",

@@ -6,0 +6,0 @@ "authors": [

@@ -0,124 +1,132 @@

/* @preserve
* Leaflet Control TileLoadingProgress 1.0.0
* https://github.com/jbccollins/leaflet-tile-loading-progress-control
*
* Copyright (c) 2018 James Collins
* All rights reserved.
*/
this.L = this.L || {};
this.L.Control = this.L.Control || {};
this.L.Control.TileLoadingProgress = (function (L) {
'use strict';
'use strict';
L = L && L.hasOwnProperty('default') ? L['default'] : L;
L = L && L.hasOwnProperty('default') ? L['default'] : L;
var Control = {
class: L.Control.extend({
options: {
leafletElt: null,
position: 'topright'
},
initialize: function (options) {
// constructor
this.handleLoadingStatusUpdate = this.handleLoadingStatusUpdate.bind(this);
this.handleTileLoadStart = this.handleTileLoadStart.bind(this);
this.handleTileUnload = this.handleTileUnload.bind(this);
this.handleTileLoad = this.handleTileLoad.bind(this);
this.handleLayerLoading = this.handleLayerLoading.bind(this);
this.handleTileError = this.handleTileError.bind(this);
this.handleLayerLoad = this.handleLayerLoad.bind(this);
this.getTileStatusCounts = this.getTileStatusCounts.bind(this);
L.Util.setOptions(this, options);
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control-progress-bar');
var loadingContainer = L.DomUtil.create('div', 'loading-container');
var loadingBackground = L.DomUtil.create('div', 'loading-background');
var loadingForeground = L.DomUtil.create('div', 'loading-foreground');
var loadingText = L.DomUtil.create('div', 'loading-text');
loadingContainer.appendChild(loadingBackground);
loadingContainer.appendChild(loadingForeground);
container.appendChild(loadingContainer);
container.appendChild(loadingText);
for (var key in this.options.leafletElt._layers) {
var layer = this.options.leafletElt._layers[key];
layer.on('tileloadstart', this.handleTileLoadStart);
layer.on('tileunload', this.handleTileUnload);
layer.on('tileload', this.handleTileLoad);
layer.on('loading', this.handleLayerLoading);
layer.on('tileerror', this.handleTileError);
layer.on('load', this.handleLayerLoad);
}
this.loadingForegroundElt = loadingForeground;
this.container = container;
this.loadingText = loadingText;
return container;
},
onRemove: function (map) {
// when removed
},
handleLoadingStatusUpdate: function () {
var status = null;
var status = {
var Control = {
class: L.Control.extend({
options: {
leafletElt: null,
position: 'topright'
},
initialize: function (options) {
// constructor
this.handleLoadingStatusUpdate = this.handleLoadingStatusUpdate.bind(this);
this.handleTileLoadStart = this.handleTileLoadStart.bind(this);
this.handleTileUnload = this.handleTileUnload.bind(this);
this.handleTileLoad = this.handleTileLoad.bind(this);
this.handleLayerLoading = this.handleLayerLoading.bind(this);
this.handleTileError = this.handleTileError.bind(this);
this.handleLayerLoad = this.handleLayerLoad.bind(this);
this.getTileStatusCounts = this.getTileStatusCounts.bind(this);
L.Util.setOptions(this, options);
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control-progress-bar');
var loadingContainer = L.DomUtil.create('div', 'loading-container');
var loadingBackground = L.DomUtil.create('div', 'loading-background');
var loadingForeground = L.DomUtil.create('div', 'loading-foreground');
var loadingText = L.DomUtil.create('div', 'loading-text');
loadingContainer.appendChild(loadingBackground);
loadingContainer.appendChild(loadingForeground);
container.appendChild(loadingContainer);
container.appendChild(loadingText);
for (var key in this.options.leafletElt._layers) {
var layer = this.options.leafletElt._layers[key];
layer.on('tileloadstart', this.handleTileLoadStart);
layer.on('tileunload', this.handleTileUnload);
layer.on('tileload', this.handleTileLoad);
layer.on('loading', this.handleLayerLoading);
layer.on('tileerror', this.handleTileError);
layer.on('load', this.handleLayerLoad);
}
this.loadingForegroundElt = loadingForeground;
this.container = container;
this.loadingText = loadingText;
return container;
},
onRemove: function (map) {
// when removed
},
handleLoadingStatusUpdate: function () {
var status = null;
var status = {
loading: 0,
loaded: 0
};
for (var key in this.options.leafletElt._layers) {
var layer = this.options.leafletElt._layers[key];
var layerStatus = this.getTileStatusCounts(layer);
status.loading += layerStatus.loading;
status.loaded += layerStatus.loaded;
}
var numTiles = status.loading + status.loaded;
var w = numTiles ? status.loaded / numTiles : 0;
var percent = w * 100;
this.loadingForegroundElt.style.width = percent + "%";
if (w === 1) {
this.container.style.opacity = 0;
} else {
this.container.style.opacity = 1;
}
this.loadingText.innerHTML = "Loading Tiles (" + Math.floor(percent) + "%)";
},
handleLayerLoading: function (e) {
this.handleLoadingStatusUpdate();
},
handleTileLoadStart: function (e) {
this.handleLoadingStatusUpdate();
},
handleTileLoad: function (e) {
this.handleLoadingStatusUpdate();
},
handleTileError: function (e) {
this.handleLoadingStatusUpdate();
},
handleTileUnload: function (e) {
this.handleLoadingStatusUpdate();
},
handleLayerLoad: function (e) {
//console.log('loaded');
},
getTileStatusCounts: function (l) {
var status = {
loaded: 0,
loading: 0,
loaded: 0
};
for (var key in this.options.leafletElt._layers) {
var layer = this.options.leafletElt._layers[key];
var layerStatus = this.getTileStatusCounts(layer);
status.loading += layerStatus.loading;
status.loaded += layerStatus.loaded;
};
for (var key in l._tiles) {
if (l._tiles[key].loaded) {
status.loaded++;
} else {
status.loading++;
}
}
return status;
}
var numTiles = status.loading + status.loaded;
var w = numTiles ? status.loaded / numTiles : 0;
var percent = w * 100;
this.loadingForegroundElt.style.width = percent + "%";
if (w === 1) {
this.container.style.opacity = 0;
} else {
this.container.style.opacity = 1;
}
this.loadingText.innerHTML = `Loading Tiles (${Math.floor(percent)}%)`;
},
handleLayerLoading: function (e) {
this.handleLoadingStatusUpdate();
},
handleTileLoadStart: function (e) {
this.handleLoadingStatusUpdate();
},
handleTileLoad: function (e) {
this.handleLoadingStatusUpdate();
},
handleTileError: function (e) {
this.handleLoadingStatusUpdate();
},
handleTileUnload: function (e) {
this.handleLoadingStatusUpdate();
},
handleLayerLoad: function (e) {
//console.log('loaded');
},
getTileStatusCounts: function (l) {
var status = {
loaded: 0,
loading: 0,
};
for (var key in l._tiles) {
if (l._tiles[key].loaded) {
status.loaded++;
} else {
status.loading++;
}
}
return status;
}),
factory: function(options) {
return new L.Control.TileLoadingProgress(options);
}
}),
factory: function(options) {
return new L.Control.TileLoadingProgress(options);
}
};
};
var TileLoadingProgress = L.Util.extend(Control.class, {});
var TileLoadingProgress = L.Util.extend(Control.class, {});
L.Util.extend(L.Control, {
TileLoadingProgress: TileLoadingProgress,
tileLoadingProgress: Control.factory
});
L.Util.extend(L.Control, {
TileLoadingProgress: TileLoadingProgress,
tileLoadingProgress: Control.factory
});
return TileLoadingProgress;
return TileLoadingProgress;
}(L));
//# sourceMappingURL=Control.TileLoadingProgress.js.map
{
"name": "leaflet-tile-loading-progress-control",
"version": "0.0.3",
"version": "1.0.0",
"description": "A leaflet control that indicates tile loading progress for a group of tile layers",

@@ -9,3 +9,3 @@ "main": "dist/Control.TileLoadingProgress.js",

"build": "npm run build:js && npm run build:css",
"build:js": "rollup --output.format=iife --name=L.Control.TileLoadingProgress --globals=leaflet:L src/index.js --output.file=dist/Control.TileLoadingProgress.js --sourcemap",
"build:js": "rollup -c",
"build:css": "cpr Control.TileLoadingProgress.css dist/Control.TileLoadingProgress.css --overwrite",

@@ -17,3 +17,4 @@ "test": "npm run lint",

"publish": "sh ./scripts/publish.sh",
"postpublish": "sh ./scripts/postpublish.sh"
"postpublish": "sh ./scripts/postpublish.sh",
"dev": "rollup -c -w"
},

@@ -33,4 +34,3 @@ "repository": {

},
"dependencies": {},
"devDependencies": {
"dependencies": {
"cpr": "^3.0.1",

@@ -40,4 +40,4 @@ "eslint": "^4.15.0",

"prettier": "^1.9.2",
"rollup": "^0.53.2"
"rollup": "^0.64.1"
}
}
# leaflet-tile-loading-progress-control
A leaflet control that indicates tile loading progress for a group of tile layers.
A leaflet control that indicates tile loading progress for a group of tile layers. This can be useful when you have a lot of tile layers or tiles that frequently refresh.
My particualar use case was for a looping precipitation radar that was built using ten tile layers that each needed to be updated every five minutes.
# Usage
```javascript
import 'leaflet-tile-loading-progress-control';
import 'leaflet-tile-loading-progress-control/dist/Control.TileLoadingProgress.css';
const tileLayer1 = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')
const tileLayer2 = L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png');
const tileLayers = L.layerGroup([tileLayer1, tileLayer2]);
const tileLoadingProgress = new L.Control.TileLoadingProgress({
leafletElt: tileLayers,
position: 'bottomleft'
});
tileLoadingProgress.addTo(map);
```
## Options
| Option | Type | Description |
| --------------- | ---------------- | ----------------- | ----------- |
| `leafletElt` | Leaflet LayerGroup | Group of tile layers tracked by the loading progress control. |
# Example GIF
from https://us-weather-monitor.herokuapp.com/
![Example Gif](https://media.giphy.com/media/4EFCKYcBEztFydh9HR/giphy.gif)

@@ -68,3 +68,3 @@ import L from 'leaflet';

}
this.loadingText.innerHTML = `Loading Tiles (${Math.floor(percent)}%)`
this.loadingText.innerHTML = "Loading Tiles (" + Math.floor(percent) + "%)";
},

@@ -71,0 +71,0 @@ handleLayerLoading: function (e) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc