public
Created

broadband.com jquery javascript plugin

  • Download Gist
broadbandmap.jquery.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
(function( $ ){
var settings = {
lat: 38.651198,
lng: -97.976074,
address: '',
minimumDetailZoom: 4,
defaultZoom: 4,
displayLitBuildings: false,
displayCentralOffices: false,
dslHeatmapActive: false,
eocHeatmapActive: false,
displayFiberMap: false,
displayPriceMap: false,
includePricing: false,
includeControls: true,
includeBranding: true,
includeZipCodeSearch: true,
mapTypeControl: true,
detailedLitBuildings: false,
controlsBackgroundColor: '#269FB2'
};
 
$.fn.broadbandMap = function(options) {
return this.each(function() {
var $this = $(this);
$.extend(settings, options);
// ========================
// = include map controls =
// ========================
if (settings.includeControls) {
var broadbandmap_controls = [];
var cosChecked = settings.displayCentralOffices ? 'checked="checked"' : '';
var litBuildingsChecked = settings.displayLitBuildings ? 'checked="checked"' : '';
var dslCoverageChecked = settings.dslHeatmapActive ? 'checked="checked"' : '';
var eocCoverageChecked = settings.eocHeatmapActive ? 'checked="checked"' : '';
broadbandmap_controls.push('<div id="broadbandmap_controls" style="background-color: ' + settings.controlsBackgroundColor + '; width: ' + $this.width() + 'px; color: white; font: 14px Arial, Helvetica; padding: 4px 0;">');
broadbandmap_controls.push('<input style="margin-bottom: 0; height: 12px; display: inline; margin-left: 12px" type="checkbox" name="centralOffices" id="broadbandmap_controls_centralOffices" class="broadbandmap_controls_layer_toggle" ' + cosChecked + '/>');
broadbandmap_controls.push('<label style="color: white; display: inline;" for="broadbandmap_controls_centralOffices">COs</label>');
broadbandmap_controls.push('<input style="margin-bottom: 0; height: 12px; display: inline; margin-left: 12px" type="checkbox" name="litBuildings" id="broadbandmap_controls_litBuildings" class="broadbandmap_controls_layer_toggle" ' + litBuildingsChecked + '/>');
broadbandmap_controls.push('<label style="color: white; display: inline;" for="broadbandmap_controls_litBuildings">Lit buildings</label>');
broadbandmap_controls.push('<input style="margin-bottom: 0; height: 12px; display: inline; margin-left: 12px" type="checkbox" name="dslCoverage" id="broadbandmap_controls_dslCoverage" class="broadbandmap_controls_layer_toggle" ' + dslCoverageChecked + '/>');
broadbandmap_controls.push('<label style="color: white; display: inline;" for="broadbandmap_controls_dslCoverage">DSL</label>');
broadbandmap_controls.push('<input style="margin-bottom: 0; height: 12px; display: inline; margin-left: 12px" type="checkbox" name="eocCoverage" id="broadbandmap_controls_eocCoverage" class="broadbandmap_controls_layer_toggle" ' + eocCoverageChecked + '/>');
broadbandmap_controls.push('<label style="color: white; display: inline;" for="broadbandmap_controls_eocCoverage">EOC</label>');
if (settings.includeZipCodeSearch) {
broadbandmap_controls.push('<input style="height: 12px; display: inline; margin-left: 24px" type="text" name="broadbandmap_controls_zipcode" id="broadbandmap_controls_zipcode" size="5" maxlength="5" />');
broadbandmap_controls.push('<label style="color: white; display: inline; margin-left: 4px" for="broadbandmap_controls_zipcode">Zip Code</label>');
broadbandmap_controls.push('<button style="margin-left: 4px" id="broadbandmap_controls_update_zipcode">Go!</button>');
}
broadbandmap_controls.push('</div>');
$this.before(broadbandmap_controls.join(''));
$('#broadbandmap_controls_update_zipcode').click(function() {
$('#broadbandmap_controls_update_zipcode').change();
});
$('#broadbandmap_controls_zipcode').change(function() {
$.ajax({
url: 'http://api.broadband.com/zipcode_lookup/latlng/' + $(this).val(),
data: {
format: 'json'
},
dataType: 'jsonp',
jsonp: 'jsonp_callback',
success: function(json) {
$('#broadbandmap_controls_zipcode_error').remove();
if (json.status == 'failure') {
$('#broadbandmap_controls_update_zipcode').after('<span style="margin-left: 8px; color: #f00; font-weight: bold; position: relative; top: 1px" id="broadbandmap_controls_zipcode_error">Not found.</span>');
return;
}
var gmap = $this.data('broadbandMap').gmap;
var zipCenter = new google.maps.LatLng(json.data.lat, json.data.lng);
gmap.setCenter(zipCenter);
gmap.setZoom(10);
}
});
});
// watch for layer toggling
(function(bbmap) {
$('.broadbandmap_controls_layer_toggle').change(function() {
var layers = {};
$('.broadbandmap_controls_layer_toggle').each(function(index) {
layers[this.name] = this.checked;
});
bbmap.trigger('layersToggle', layers);
});
bbmap.bind('layer-loaded', function(event) {
setTimeout(function() {
$('#broadbandmap_controls_ajax_loader').fadeOut('fast');
}, 4000);
});
})($this);
}
 
$this.bind({
'layerToggle': layerToggle,
'layersToggle': layersToggle
});
 
// map variables
var markers = [];
var seenCoordinates = {};
var productAreas = {
eoc: {},
dsl: {}
};
var minDetailZoom = settings.minimumDetailZoom;
var defaultZoom = settings.defaultZoom;
var dslHeatmapActive = settings.dslHeatmapActive;
var eocHeatmapActive = settings.eocHeatmapActive;
var loadLitBuildings = settings.displayLitBuildings;
var loadCentralOffices = settings.displayCentralOffices;
var loadFiberMap = settings.displayFiberMap;
var loadPriceMap = settings.displayPriceMap;
var litBuildings01;
var litBuildings02;
var litBuildings03;
var centralOffices;
var dslCoverage;
var eocCoverage;
var fibermap01;
var fibermap02;
var fibermap03;
var broadbandMap;
 
init();
 
function init() {
var origin = new google.maps.LatLng(settings.lat, settings.lng);
relativeCenter = origin;
var mapOptions = {
zoom: defaultZoom,
minZoom: minDetailZoom,
center: origin,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: settings.mapTypeControl,
streetViewControl: false,
scaleControl: true,
scrollwheel: false,
disableDoubleClickZoom: false
};
broadbandMap = new google.maps.Map($this.get(0), mapOptions);
$this.data('broadbandMap', {
gmap: broadbandMap,
coDistance: '-',
fiberDistance: '-'
});
 
// DSL Coverage layer
dslCoverage = new google.maps.FusionTablesLayer(1012330, {
clickable: false,
suppressInfoWindows: true
});
if (dslHeatmapActive) {
dslCoverage.setMap(broadbandMap);
}
 
// EOC Coverage KML
eocCoverage = new google.maps.FusionTablesLayer(1012138, {
clickable: false,
suppressInfoWindows: true
});
if (eocHeatmapActive) {
eocCoverage.setMap(broadbandMap);
}
 
// Central Offices Layer
centralOffices = new google.maps.FusionTablesLayer(1012233);
if (loadCentralOffices) {
centralOffices.setMap(broadbandMap);
}
 
// Lit Buildings KML Layers (fusion tables has a max of 100,000 mappable points per layer)
// detailedLitBuildings contain carrier and npa/nxx data
if (settings.detailedLitBuildings) {
litBuildings01 = new google.maps.FusionTablesLayer(815002);
litBuildings02 = new google.maps.FusionTablesLayer(816600);
litBuildings03 = new google.maps.FusionTablesLayer(816614);
} else {
litBuildings01 = new google.maps.FusionTablesLayer(817304);
litBuildings02 = new google.maps.FusionTablesLayer(817059);
litBuildings03 = new google.maps.FusionTablesLayer(817063);
}
if (loadLitBuildings) {
litBuildings01.setMap(broadbandMap);
litBuildings02.setMap(broadbandMap);
litBuildings03.setMap(broadbandMap);
}
 
// Fiber Map KML Layers
fibermap01 = new google.maps.FusionTablesLayer(1340901);
fibermap02 = new google.maps.FusionTablesLayer(1340906);
fibermap03 = new google.maps.FusionTablesLayer(1346568);
if (loadFiberMap) {
fibermap01.setMap(broadbandMap);
fibermap02.setMap(broadbandMap);
fibermap03.setMap(broadbandMap);
}
 
// Pricing Map Layer
pricemap = new google.maps.FusionTablesLayer(1372881);
if (loadPriceMap) {
pricemap.setMap(broadbandMap);
}
}
 
function layerToggle(e, data) {
var layerName = data.name;
var active = data.active;
var layers = [];
switch (layerName) {
case 'dslCoverage':
dslHeatmapActive = active;
layers.push(dslCoverage);
break;
case 'eocCoverage':
eocHeatmapActive = active;
layers.push(eocCoverage);
break;
case 'litBuildings':
loadLitBuildings = active;
layers.push(litBuildings01);
layers.push(litBuildings02);
layers.push(litBuildings03);
break;
case 'centralOffices':
loadCentralOffices = active;
layers.push(centralOffices);
break;
}
for (var i = 0, ii = layers.length; i < ii; i++) {
if (active) {
layers[i].setMap(broadbandMap);
} else {
layers[i].setMap(null);
}
}
}
 
function layersToggle(e, data) {
if (data.dslCoverage) {
dslCoverage.setMap(broadbandMap);
} else {
dslCoverage.setMap(null);
}
if (data.eocCoverage) {
eocCoverage.setMap(broadbandMap);
} else {
eocCoverage.setMap(null);
}
if (data.centralOffices) {
centralOffices.setMap(broadbandMap);
} else {
centralOffices.setMap(null);
}
if (data.litBuildings) {
litBuildings01.setMap(broadbandMap);
litBuildings02.setMap(broadbandMap);
litBuildings03.setMap(broadbandMap);
} else {
litBuildings01.setMap(null);
litBuildings02.setMap(null);
litBuildings03.setMap(null);
}
if (data.fiber_map) {
fibermap01.setMap(broadbandMap);
fibermap02.setMap(broadbandMap);
fibermap03.setMap(broadbandMap);
} else {
fibermap01.setMap(null);
fibermap02.setMap(null);
fibermap03.setMap(null);
}
if (data.price_map) {
pricemap.setMap(broadbandMap);
} else {
pricemap.setMap(null);
}
}
});
};
})(jQuery);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.