PageSourceSearch

https://commonwealth-connection.com/static/web_portal/js/compare_locations.mjs

js commonwealth-connection.com collected 2026-10-04 05:27:09 UTC 4,542 bytes, 145 lines download raw bytes

1import { populateDataset } from "/static/web_portal/js/data.js";
2import { createLocationStorage, fetchLocationData } from "/static/web_portal/js/util_location.mjs";
3import { latestCoverageVersion, coverageVersions } from "./data.js";
4
5globalThis.locationMetadata = await createLocationStorage();
6
7await latestCoverageVersion();
8
9// Function to parse location parameter from URL
10// the format of the URL variable is "?location=county:51015,county:51159,..."
11export async function parseLocationFromURL() {
12    const urlParams = new URLSearchParams(window.location.search);
13    const locationParam = urlParams.get('location');
14    
15    if (!locationParam) {
16        // Return no locations if no parameter found
17        // return ['statewide:51','county:51107','county:51041'];
18        return ['statewide:51'];
19
20    }
21    
22    // Decode the URL parameter and split by comma
23    const decodedParam = decodeURIComponent(locationParam);
24    const locations = decodedParam.split(',');
25    
26    // Format each location as "locationType:locationID"
27    return locations.map(location => {
28        const trimmedLocation = location.trim();
29        // Handle the format "county%3A51015" -> "county:51015"
30        return trimmedLocation.replace('%3A', ':');
31    });
32}
33
34globalThis.locationCompare = await parseLocationFromURL();
35
36export const coverageTypes = [
37    {
38        "pk":"any_100_20",
39        "tech":"Any",
40        "down":"100 Mbps",
41        "up":"20 Mbps"
42    },
43    {
44        "pk":"any_1000",
45        "tech":"Any",
46        "down":"1,000 Mbps",
47        "up":""
48    },
49    {
50        "pk":"cable_100_20",
51        "tech":"Cable",
52        "down":"100 Mbps",
53        "up":"20 Mbps"
54    },
55    {
56        "pk":"fiber_100_20",
57        "tech":"Fiber",
58        "down":"100 Mbps",
59        "up":"20 Mbps"
60    },
61    {
62        "pk":"dsl_100_20",
63        "tech":"DSL",
64        "down":"100 Mbps",
65        "up":"20 Mbps"
66    },
67    {
68        "pk":"fixedwireless_100_20",
69        "tech":"Fixed",
70        "down":"100 Mbps",
71        "up":"20 Mbps"
72    }
73];
74
75globalThis.allowedLocationTypes = ['county', 'leg_house', 'leg_senate', 'school', 'congress', 'tribal'];
76
77let apiBaseUrl = {
78    "coverage": "/coverage/Coverage/get/",
79    "fabric": "/dhcd/FabricPoint/get/"
80};
81
82// Start once page is loaded
83if (document.readyState !== 'loading') { initCode(); }
84else { document.addEventListener('DOMContentLoaded', initCode); }
85
86async function initCode(){
87
88    await fetchLocationData('county','', globalThis.locationMetadata);
89
90    await fetchLatestCoverageData();
91    
92    fetchAllCoverageData();
93}
94
95async function fetchLatestCoverageData() {
96    try {
97        const messageContainer = document.querySelector(".split-container");
98        
99        // TODO: Change to CGIT notifications
100        showLoadingMessage(messageContainer, true, "Loading coverage data", "load-cov-data");
101
102        // Loop through all coverage versions
103        await populateDataset(latestCoverageVersion().id, {'coverageTypes':coverageTypes.map(item => item.pk),'locationTypes':allowedLocationTypes});
104        
105        // TODO: Change to CGIT notifications
106        showLoadingMessage(messageContainer, false, "", "load-cov-data");
107
108        // Trigger custom event to indicate coverage data fetch completion
109        const coverageDataEvent = new CustomEvent('coverageDataReady', {
110            detail: { 
111                // localityCoverage: aggregateData[coverageVersionLatest.id],
112                timestamp: new Date().toISOString()
113            }
114        });
115        document.dispatchEvent(coverageDataEvent);
116        
117    } catch (error) {
118        console.error('Error in fetchLatestCoverageData:', error);
119        showLoadingMessage(messageContainer, false);
120        throw error;
121    }
122}
123
124async function fetchAllCoverageData() {
125    try {
126
127        // Loop through all coverage versions
128        for (const version of coverageVersions()) {
129            await populateDataset(version.id, {'coverageTypes':coverageTypes.map(item => item.pk),'locationTypes':allowedLocationTypes});
130        }
131
132        // Trigger custom event to indicate coverage data fetch completion
133        const allCoverageDataEvent = new CustomEvent('allCoverageDataReady', {
134            detail: { 
135                // localityCoverage: aggregateData[coverageVersionLatest.id],
136                timestamp: new Date().toISOString()
137            }
138        });
139        document.dispatchEvent(allCoverageDataEvent);
140        
141    } catch (error) {
142        console.error('Error in fetchAllCoverageData:', error);
143        throw error;
144    }
145}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.