Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @id latitude-geodesic-precision
// @name IITC plugin: Latitude geodesic precision
// @category Custom
// @version 0.2.0
// @description Increase latitude geodesic precision
// @namespace https://github.com/IITC-CE/ingress-intel-total-conversion
// @include https://intel.ingress.com/*
// @grant none
// ==/UserScript==
if (typeof window.plugin !== 'function') window.plugin = function() {};
(function wrapper (plugin_info) {
// constants
var d2r = Math.PI/180.0;
var r2d = 180.0/Math.PI;
function geodesicConvertLine (start, end, convertedPoints) {
var lng1 = start.lng * d2r;
var lng2 = end.lng * d2r;
var dLng = lng1-lng2;
var segments = 0;
if (dLng !== 0) {
var lat1 = start.lat * d2r;
var lat2 = end.lat * d2r;
var sinLat1 = Math.sin(lat1);
var sinLat2 = Math.sin(lat2);
var cosLat1 = Math.cos(lat1);
var cosLat2 = Math.cos(lat2);
var distance = Math.acos(sinLat1*sinLat2 + cosLat1*cosLat2*Math.cos(dLng)); // http://www.edwilliams.org/avform.htm#Dist
segments = Math.floor(distance / this.options.segmentsCoeff);
}
if (segments > 1) {
// maths based on https://edwilliams.org/avform.htm#Int
// pre-calculate some constant values for the loop
var sinLat1CosLat2 = sinLat1*cosLat2;
var sinLat2CosLat1 = sinLat2*cosLat1;
var cosLat1CosLat2SinDLng = cosLat1*cosLat2*Math.sin(dLng);
for (var i=1; i < segments; i++) {
var iLng = lng1-dLng*(i/segments);
var iLat = Math.atan(
(sinLat1CosLat2 * Math.sin(iLng-lng2) - sinLat2CosLat1 * Math.sin(iLng-lng1))
/ cosLat1CosLat2SinDLng
);
convertedPoints.push(L.latLng(iLat*r2d, iLng*r2d));
}
}
convertedPoints.push(end);
}
function updatePoly(Class) {
Class.mergeOptions({segmentLength: 10000});
Class.include({_geodesicConvertLine: geodesicConvertLine});
}
function setup () {
updatePoly(L.GeodesicPolyline);
updatePoly(L.GeodesicPolygon);
}
setup.priority = 'high';
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 (window.iitcLoaded && typeof setup === 'function') setup();
})({ script: typeof GM_info !== 'undefined' && GM_info.script && {
version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description
}})// wrapper end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment