/* Shaw_GoogleMaps
*
* Description:
* Jquery plugin, in order to have an abstraction layer for Google Maps.
* The idea is to simplify the interaction with Google Maps, and to encapsulate
* all the functionality we need, in order to get it working with Ektron.
*
* Contact:
* Nathan Arnold -- nathan.arnold@globalnews.ca
*
* Version log:
* v1.0 -- May 2011 -- added basic functionality
* v1.1 -- June 9, 2011 -- added ability to toggle between KML layers via a select box
* v1.2 -- June 9, 2011 -- changed KML toggling methodology, so legends can toggle as well
* v1.3 -- June 29, 2011 -- changed Fusion table support
* v1.4 -- Aug 3, 2011 -- added Fusion table support for toggling between labels
* v1.5 -- Jul 7, 2015 -- added support for multiple Fusion tables on same map
*/
(function( $ ) {
/* This method is called when the object is created, or used for the first time */
$.fn.Shaw_GoogleMaps = function(method) {
//console.log('Shaw_GoogleMaps()');
/* grab and store initial object scope */
obj.root = $(this);
/* method calling logic */
if ( methods[method] ) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1), Array.prototype.slice.call(arguments, 2));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, Array.prototype.slice.call(arguments, 0), Array.prototype.slice.call(arguments, 1) );
} else {
$.error('Method '+ method +' does not exist on jQuery.Shaw_GoogleMaps');
};
};
// DOM/jQuery Objects
var obj = {
root: false, // root object
addressInput: false, // geocoder input
addressSubmit: false, // submit button for the geocoder input
legends: false, // jQuery obj -- holds instance of all legend nodes
dataSelect: false, // the select dropdown, used to toggle between KML files
map: false // the map div
};
// USER-DEFINED PROPERTIES
var prop = {
addressInputId: '', // string - submission input ID, for location text entry
addressSubmitId: '', // string - submission submit ID, for location submission
legendParentId: '', // string - ID for the parent of all legend objects
legendClass: '', // string - classname of each legend obj
dataSelectId: '', // string - select box ID, to toggle KML
dataSelectData: {}, // JSON obj - object used to hold dataSelect controls { index:int, kmlSrc:'', fusionSrc:'', legendId:'' }
kml: [], // array of strings - KML layer(s) to load
fusion: [], // array of strings - fusion layer(s) to load
css: '', // string - CSS styling for map, if not on HTML page itself
style: {}, // JSON obj - Google JSON data object, for custom map style
styleName: '', // string - name of custom Map style, for use in label
geocoder: false // Obj - Google GeoCoder object
};
// USER-DEFINED GOOGLE MAP OPTIONS
var options = {
zoom: 3, // set for Canada-wide zoom, by default
center: new google.maps.LatLng(60, -97), // set for Canada, by default
mapTypeId: google.maps.MapTypeId.ROADMAP, // show standard roadmap, by default
streetViewControl: false, // don't show streetview option, by default
mapTypeControlOptions: { // just show Roadmap style toggle, by default
mapTypeIds: [google.maps.MapTypeId.ROADMAP]
}
};
// store KML
var kmlLayers = {};
var fusionLayers = {};
// METHODS
var methods = {
// Takes all instance-defined arguments, and sub out any matching predefined properties with the new args
processProperties: function(args) {
//console.log('processProperties()');
//console.log(args);
// loop through each predefined arg, and swap out any new values
for (i in args) { if (typeof prop[i] != "undefined") { prop[i] = args[i]; }; };
},
processOptions: function(args) {
//console.log('processOptions()');
// loop through each predefined arg, and swap out any new values
for (i in args) { if (typeof options[i] != "undefined" || i == 'maxZoom' || i == 'minZoom') { options[i] = args[i]; }; };
},
// All instances of this object call this method when the app is first initialized.
init: function() {
//console.log('init()');
// handle args, if necessary
if (arguments.length > 0) { methods.processProperties(arguments[0]); };
if (arguments.length > 1) { methods.processOptions(arguments[1]); };
// draw the map
obj.map = new google.maps.Map(obj.root.get(0), options);
// add CSS to map
var css = prop.css.split(';');
var keyValue = [];
for (var i=0; i 0 ) {
legend_data = legend_data.children("tbody").first();
}
// Build control data
legend_data.children("tr").each(function(idy){
var dl_name = $(this).children("td").eq(0).text();
control_drop_down.append("");
var wizard_legend = $(this).children("td").eq(3).children("ul.auto_legend_wizard");
if( wizard_legend.length > 0) {
shawmaps_build_wizard_legend( wizard_legend , $ );
}
var dl_legend = $(this).children("td").eq(3).html();
$("#mapLegend" + shawmaps_list[map_indx]).append("
" + dl_legend + "
");
});
$(".legend" + shawmaps_list[map_indx] ).css("display","none");
$("#legend" + shawmaps_list[map_indx] +"1" ).css("display","inline");
control_drop_down.change(function(){
var selected_value = $(this).children("option:selected").val();
var map_id = ($(this).attr("id")+"").replace("dataControlSelect","");
$(".legend" + map_id ).css("display","none");
$("#legend" + map_id +""+selected_value ).css("display","inline");
});
}
});
});
function shawmaps_build_wizard_legend( wizard_legend , $ ) {
wizard_legend.children("li").each(function(idx){
var legend_item = $(this);
var legend_item_type = legend_item.attr("data-type");
legend_item.css("color", legend_item.attr("data-color") );
switch(legend_item_type){
case "fill":
legend_item.css( "background-color", legend_item.attr("data-icon") );
legend_item.css( "padding-left", "5px" );
break;
case "color":
legend_item.prepend("");
legend_item.children("span.shawmaps_colored_icon").css("background-color", legend_item.attr("data-icon") );
break;
case "icon":
case "image":
//By Span
/*
legend_item.prepend("");
legend_item.children("span.shawmaps_image_icon").css("background-image", "url("+legend_item.attr("data-icon")+")" );
*/
// By Image
legend_item.prepend("");
break;
}
});
}
function shawmaps_add_data_layers( mapProperties, MapId ){
var legend_data = jQuery("#hidden_legend_code" + MapId + " table" ).first();
if( legend_data.children("tbody").length > 0 ) {
legend_data = legend_data.children("tbody").first();
}
var layer_props = new Array();
legend_data.children("tr").each(function(idy){
var kml_name = jQuery(this).children("td").eq(1).text();
var fusion_1 = jQuery(this).children("td").eq(2).text();
var fusion_sid_1 = jQuery(this).children("td").eq(4).text();
var fusion_tid_1 = jQuery(this).children("td").eq(5).text();
var fusion_count = parseInt( jQuery(this).children("td").eq(6).text(), 10 );
fusion_count = ( isNaN( fusion_count ) ) ? 1 : fusion_count; // for older map entries wihtout a fusionCount value
// set base properties
layer_props[idy+1] = {
"index" : idy+1,
"kmlSrc" : kml_name,
"legendId": "legend"+ MapId +(idy+1),
"fusionCount": fusion_count,
"fusionSrc_1": fusion_1,
"fusionStyleId_1": fusion_sid_1,
"fusionTemplateId_1": fusion_tid_1
};
// set properties for any additional fusion tables
var eq = 7;
for ( var i = 2; i <= fusion_count; i++ ) {
layer_props[idy+1][ "fusionSrc_" + i ] = jQuery(this).children("td").eq( eq ).text(); eq++;
layer_props[idy+1][ "fusionStyleId_" + i ] = jQuery(this).children("td").eq( eq ).text(); eq++;
layer_props[idy+1][ "fusionTemplateId_" + i ] = jQuery(this).children("td").eq( eq ).text(); eq++;
}
});
mapProperties["dataSelectData"] = layer_props;
return mapProperties;
}
;