Skip to content

Commit

Permalink
identify moved portals
Browse files Browse the repository at this point in the history
  • Loading branch information
xscreach committed Jun 1, 2023
1 parent 4d9aea1 commit e043da3
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
49 changes: 49 additions & 0 deletions plugins/highlight-moved-portals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// @author screach
// @name Highlight moved portals
// @category Highlighter
// @version 0.1.0
// @description Highlights portals with links with different location data

/* exported setup --eslint */
/* global L */
// use own namespace for plugin
var movedPortals = {};
window.plugin.portalHighlighterMovedPortals = movedPortals;

// exposed objects
movedPortals.styles = {
fillOpacity: 1,
fillColor: '#FF0000',
};

var getLinkData = (lguid) => {
return window.links[lguid].options.data;
};

var toLatLng = (latE6, lngE6) => {
return L.latLng(latE6 / 1e6, lngE6 / 1e6);
};

var getDLatLng = (lguid) => {
var linkData = getLinkData(lguid);
return toLatLng(linkData.dLatE6, linkData.dLngE6);
};

var getOLatLng = (lguid) => {
var linkData = getLinkData(lguid);
return toLatLng(linkData.oLatE6, linkData.oLngE6);
};

movedPortals.highlightMovedPortals = (data) => {
var portalData = data.portal.options.data;
var latLng = toLatLng(portalData.latE6, portalData.lngE6);

var portalLinks = window.getPortalLinks(data.portal.options.guid);
if (portalLinks.in.some((lguid) => !getDLatLng(lguid).equals(latLng)) || portalLinks.out.some((lguid) => !getOLatLng(lguid).equals(latLng))) {
data.portal.setStyle(movedPortals.styles);
}
};

var setup = () => {
window.addPortalHighlighter('Moved portals', movedPortals.highlightMovedPortals);
};
111 changes: 111 additions & 0 deletions plugins/links-to-moved-portals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// @author screach
// @name Links to moved portals
// @category Layer
// @version 0.1.0
// @description Show links to portals with different location data

/* exported setup --eslint */
/* global L */
// use own namespace for plugin
var plugin = {};
window.plugin.linksToMovedPortals = plugin;

// exposed objects
plugin.styles = {
color: '#F00',
opacity: 1,
weight: 3,
interactive: false,
dashArray: '4,4',
};

var toLatLng = (latE6, lngE6) => {
return L.latLng(latE6 / 1e6, lngE6 / 1e6);
};

var getDLatLng = (linkData) => {
return toLatLng(linkData.dLatE6, linkData.dLngE6);
};

var getOLatLng = (linkData) => {
return toLatLng(linkData.oLatE6, linkData.oLngE6);
};

var getPortalLatLng = (portal) => {
return portal && toLatLng(portal.options.data.latE6, portal.options.data.lngE6);
};

var addLinks = (linkGuids) => {
linkGuids.map((lGuid) => window.links[lGuid]).forEach(plugin.addLink);
};

var findLayer = (lguid) => {
return plugin.linkLayer.getLayers().find((l) => l.options.guid === lguid);
};

plugin.portalLoaded = (data) => {
if (!plugin.disabled) {
var portalLinks = window.getPortalLinks(data.guid);
addLinks([...portalLinks.in, ...portalLinks.out]);
}
};

plugin.onLinkRemoved = (data) => {
if (!plugin.disabled) {
var layer = findLayer(data.link.options.guid);
if (layer) {
layer.remove();
}
}
};

plugin.addLink = (link) => {
if (!plugin.disabled && !findLayer(link.options.guid)) {
var linkData = link.options.data;
var origin = getPortalLatLng(window.portals[linkData.oGuid]);
var destination = getPortalLatLng(window.portals[linkData.dGuid]);
if ((origin && !origin.equals(getOLatLng(linkData))) || (destination && !destination.equals(getDLatLng(linkData)))) {
var poly = L.geodesicPolyline(link.getLatLngs(), Object.assign({}, plugin.styles, { guid: link.options.guid }));
poly.addTo(plugin.linkLayer);
}
}
};

plugin.checkAllLinks = () => {
if (!plugin.disabled) {
addLinks(Object.keys(window.links));
}
};

var createLayer = () => {
plugin.linkLayer = new L.FeatureGroup();
window.layerChooser.addOverlay(plugin.linkLayer, 'Links to moved portals');

window.map.on('layeradd', function (obj) {
if (obj.layer === plugin.linkLayer) {
delete plugin.disabled;
plugin.checkAllLinks();
}
});
window.map.on('layerremove', function (obj) {
if (obj.layer === plugin.linkLayer) {
plugin.disabled = true;
plugin.linkLayer.clearLayers();
}
});

if (!window.map.hasLayer(plugin.linkLayer)) {
plugin.disabled = true;
}
};

var addHooks = () => {
window.addHook('mapDataRefreshEnd', plugin.checkAllLinks);
window.addHook('portalDetailsUpdated', plugin.portalLoaded);
window.addHook('linkRemoved', plugin.onLinkRemoved);
};

var setup = () => {
createLayer();
addHooks();
};

0 comments on commit e043da3

Please sign in to comment.