another piece of experimental marker drawing code - not 100% working. committing for future reference if needed
This commit is contained in:
parent
2334166e69
commit
c6e557a557
79
plugins/experimental/marker-divicon-svg.user.js
Normal file
79
plugins/experimental/marker-divicon-svg.user.js
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @id iitc-plugin-marker-divicon-svg@jonatkins
|
||||||
|
// @name IITC plugin: Marker drawn using separate SVGs
|
||||||
|
// @category Tweaks
|
||||||
|
// @version 0.1.0.@@DATETIMEVERSION@@
|
||||||
|
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||||
|
// @updateURL @@UPDATEURL@@
|
||||||
|
// @downloadURL @@DOWNLOADURL@@
|
||||||
|
// @description [@@BUILDNAME@@-@@BUILDDATE@@] EXPERIMENTAL: draw markers using individual Leaflet DivIcons, as SVG
|
||||||
|
// @include https://www.ingress.com/intel*
|
||||||
|
// @include http://www.ingress.com/intel*
|
||||||
|
// @match https://www.ingress.com/intel*
|
||||||
|
// @match http://www.ingress.com/intel*
|
||||||
|
// @grant none
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
@@PLUGINSTART@@
|
||||||
|
|
||||||
|
// PLUGIN START ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
// use own namespace for plugin
|
||||||
|
window.plugin.markerDivIconSvg = function() {};
|
||||||
|
|
||||||
|
window.plugin.markerDivIconSvg.setup = function() {
|
||||||
|
|
||||||
|
// create a new marker. 'data' contain the IITC-specific entity data to be stored in the object options
|
||||||
|
window.createMarker = function(latlng, data) {
|
||||||
|
var icon = createMarkerDivIcon(data);
|
||||||
|
|
||||||
|
var options = L.extend({}, data, { icon: icon });
|
||||||
|
|
||||||
|
var marker = L.marker (latlng, options);
|
||||||
|
return marker;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
window.setMarkerStyle = function(marker, selected) {
|
||||||
|
var icon = createMarkerDivIcon(marker.options);
|
||||||
|
|
||||||
|
marker.setIcon(icon);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
window.createMarkerDivIcon = function(details) {
|
||||||
|
var scale = window.portalMarkerScale();
|
||||||
|
|
||||||
|
var lvlWeight = Math.max(2, Math.floor(details.level) / 1.5) * scale;
|
||||||
|
var lvlRadius = (details.team === window.TEAM_NONE ? 7 : Math.floor(details.level) + 4) * scale;
|
||||||
|
|
||||||
|
lvlRadius += (L.Browser.mobile ? PORTAL_RADIUS_ENLARGE_MOBILE*scale : 0);
|
||||||
|
|
||||||
|
var size = Math.ceil(lvlRadius + lvlWeight/2)*2;
|
||||||
|
var anchor = Math.floor(size/2);
|
||||||
|
|
||||||
|
var svg = '<svg width="'+size+'" height="'+size+'">'
|
||||||
|
+ '<circle cx="'+anchor+'" cy="'+anchor+'" r="'+lvlRadius+'" stroke="'+COLORS[details.team]+'" stroke-width="'+lvlWeight+'" fill="'+COLORS[details.team]+'" fill-opacity="0.5" />'
|
||||||
|
+ '</svg>';
|
||||||
|
|
||||||
|
return L.divIcon({
|
||||||
|
iconSize: [size,size],
|
||||||
|
iconAnchor: [anchor,anchor],
|
||||||
|
className: 'portal-marker',
|
||||||
|
html: svg
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var setup = window.plugin.markerDivIconSvg.setup;
|
||||||
|
|
||||||
|
// PLUGIN END //////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@@PLUGINEND@@
|
Loading…
x
Reference in New Issue
Block a user