Skip to content

Instantly share code, notes, and snippets.

@johnd0e
Created December 24, 2018 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnd0e/69133c7e764a553e413e4cfe3f4586ee to your computer and use it in GitHub Desktop.
Save johnd0e/69133c7e764a553e413e4cfe3f4586ee to your computer and use it in GitHub Desktop.
IITC plugin: zoom-label
// ==UserScript==
// @id iitc-plugin-zoom-label
// @name IITC plugin: zoom-label
// @description displays zoom level of the map
// @category test
// @version 0.1.0
// @author jd
// @namespace https://gist.github.com/johnd0e
// @homepageURL https://gist.github.com/johnd0e/%
// @supportURL https://gist.github.com/johnd0e/%#new_comment_field
// @updateURL https://gist.github.com/johnd0e/%/raw/zoom-label.user.js
// @downloadURL https://gist.github.com/johnd0e/%/raw/zoom-label.user.js
// @include https://intel.ingress.com/intel*
// @grant none
// ==/UserScript==
function wrapper(plugin_info) {
// ensure plugin framework is there, even if iitc is not yet loaded
if(typeof window.plugin !== 'function') window.plugin = function() {};
// PLUGIN START ////////////////////////////////////////////////////////
// https://github.com/unbam/Leaflet.ZoomLabel
let css = '\
.leaflet-container .leaflet-control-zoomlabel {\
background-color: rgba(255, 255, 255, 0.7);\
box-shadow: 0 0 5px #bbb;\
padding: 0 5px;\
margin:0;\
color: #333;\
font: 11px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;\
}';
function setup () {
L.Control.ZoomLabel = L.Control.extend({
options: {
position: 'bottomleft'
},
onAdd: function (map) {
this._container = L.DomUtil.create('div', 'leaflet-control-zoomlabel');
L.DomEvent.disableClickPropagation(this._container);
map.on('zoomend', this._onZoomend, this);
this._container.innerHTML = map.getZoom();
return this._container;
},
onRemove: function (map) {
map.off('zoomend', this._onZoomend);
},
_onZoomend: function(e) {
this._container.innerHTML = e.target._zoom;
}
});
L.control.zoomLabel = function (options) {
return new L.Control.ZoomLabel(options);
};
$('<style>').prop('type', 'text/css').html(css).appendTo('head');
L.control.zoomLabel().addTo(map);
}
// PLUGIN END //////////////////////////////////////////////////////////
setup.info = plugin_info; //add the script info data to the function as a property
if(!window.bootPlugins) window.bootPlugins = [];
window.bootPlugins.push(setup);
// if IITC has already booted, immediately run the 'setup' function
if(window.iitcLoaded && typeof setup === 'function') setup();
} // wrapper end
// inject code into site context
var script = document.createElement('script');
var info = {};
if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) info.script = { version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description };
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
(document.body || document.head || document.documentElement).appendChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment