Skip to content

Instantly share code, notes, and snippets.

const iconWindowHTML = (data, iconsData) => {
const iconWindowElement = document.createElement('div');
iconWindowElement.classList.add('card', 'marker-window');
const iconsHTML = Object.values(iconsData).map(iconData => {
if(!iconData?.icon){
return '';
}
return `
<div class="d-flex flex-column align-items-center mr-1">
@tmdesigned
tmdesigned / icon-html.js
Created July 3, 2023 15:12
map icon html
// html for the marker
const iconHTML = (attr,percent,value,colors,unit) => {
if(attr === "battery"){
return `
<div title="${value}${unit}" class="marker">
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="30" viewBox="0 0 55 120">
<rect x="10" y="7" width="45" height="102" stroke="black" fill="white" stroke-width="5"/>
<rect x="12" y="${107-percent}" width="40" height="${percent + 1}" stroke="black" fill="${colors.background}" stroke-width="0"/>
<rect x="12" y="30" width="20" height="4" fill="black" />
@tmdesigned
tmdesigned / build-icon.js
Created July 3, 2023 15:10
build map icon
const buildIcon = (data,attr) => {
const value = data.attributeValues?.[attr];
const meta = data.attributes?.find(a => a.name === attr);
if(!value || !meta){
throw new TypeError('Missing values'); // value at this point is string, so "0" won't fail
}
const min = meta.attributeTags?.min ? Number(meta.attributeTags.min) : 0;
@tmdesigned
tmdesigned / marker-setup.js
Created July 3, 2023 14:58
map marker setup
// set up individual marker
const setUpMarker = (id, data) => {
if(!data.attributeValues?.location){
return false;
}
// Pull marker from dictionary, or create new
let marker = markers[id];
@tmdesigned
tmdesigned / map-globals.js
Created July 3, 2023 13:52
Set up globals and listeners
// Excerpt from https://github.com/Losant/google-map-advanced-markers/blob/main/custom-head-content.html
// Initialize globals
const markers = {};
let devices = [];
let map;
let numSelected = 0;
let AdvancedMarkerElement;
let bounds;
let selectedAttribute = $('#attribute-selector').val() || 'battery';
@tmdesigned
tmdesigned / EventBus.js
Created October 6, 2018 12:17 — forked from PierfrancescoSoffritti/eventBus.js
A simple implementation of an event bus in Javascript
function EventBus() {
const eventCallbacksPairs = [];
this.subscribe = function( eventType, callback ) {
const eventCallbacksPair = findEventCallbacksPair(eventType);
if(eventCallbacksPair)
eventCallbacksPair.callbacks.push(callback);
else
eventCallbacksPairs.push( new EventCallbacksPair(eventType, callback) );