<commit_before>/*! 
 * Timemap.js Copyright 2008 <NAME>.
 * Licensed under the MIT License (see LICENSE.txt)
 */

/**
 * @overview
 * Timemap.js is intended to sync a SIMILE Timeline with a Google Map.
 * Dependencies: Google Maps API v2, SIMILE Timeline v1.2 - 2.3.1
 * Thanks to <NAME> (http://www.oe-files.de) for initial concept and code. 
 *
 * @name timemap.js
 * @author <NAME> (www.nickrabinowitz.com)
 * @version 1.6pre
 */

// globals - for JSLint
/*global GBrowserIsCompatible, GLargeMapControl, GMap2, GIcon       */ 
/*global GMapTypeControl, GDownloadUrl, GGroundOverlay              */
/*global GMarker, GPolygon, GPolyline, GSize, G_DEFAULT_ICON        */
/*global G_HYBRID_MAP, G_MOON_VISIBLE_MAP, G_SKY_VISIBLE_MAP        */

(function(){

// borrowing some space-saving devices from jquery
var 
	// Will speed up references to window, and allows munging its name.
	window = this,
	// Will speed up references to undefined, and allows munging its name.
	undefined,
    // aliases for Timeline objects
    Timeline = window.Timeline, DateTime = Timeline.DateTime, 
    // aliases for Google variables (anything that gets used more than once)
    G_DEFAULT_MAP_TYPES = window.G_DEFAULT_MAP_TYPES, 
    G_NORMAL_MAP = window.G_NORMAL_MAP, 
    G_PHYSICAL_MAP = window.G_PHYSICAL_MAP, 
    G_SATELLITE_MAP = window.G_SATELLITE_MAP, 
    GLatLng = window.GLatLng, 
    GLatLngBounds = window.GLatLngBounds, 
    GEvent = window.GEvent,
    // Google icon path
    GIP = "http://www.google.com/intl/en_us/mapfiles/ms/icons/",
    // aliases for class names, allowing munging
    TimeMap, TimeMapDataset, TimeMapTheme, TimeMapItem;

/*----------------------------------------------------------------------------
 * TimeMap Class
 *---------------------------------------------------------------------------*/
 
/**
 * @class
 * The TimeMap object holds references to timeline, map, and datasets.
 * This will create the visible map, but not the timeline, which must be initialized separately.
 *
 * @constructor
 * @param {element} tElement     The timeline element.
 * @param {element} mElement     The map element.
 * @param {Object} [options]       A container for optional arguments:<pre>
 *   {Boolean} syncBands            Whether to synchronize all bands in timeline
 *   {GLatLng} mapCenter            Point for map center
 *   {Number} mapZoom               Intial map zoom level
 *   {GMapType/String} mapType      The maptype for the map
 *   {Array} mapTypes               The set of maptypes available for the map
 *   {Function/String} mapFilter    How to hide/show map items depending on timeline state;
                                    options: "hidePastFuture", "showMomentOnly", or function
 *   {Boolean} showMapTypeCtrl      Whether to display the map type control
 *   {Boolean} showMapCtrl          Whether to show map navigation control
 *   {Boolean} centerMapOnItems     Whether to center and zoom the map based on loaded item positions
 *   {Function} openInfoWindow      Function redefining how info window opens
 *   {Function} closeInfoWindow     Function redefining how info window closes
 * </pre>
 */
TimeMap = function(tElement, mElement, options) {
    
    // save DOM elements
    /**
     * Map element
     * @type DOM Element
     */
    this.mElement = mElement;
    /**
     * Timeline element
     * @type DOM Element
     */
    this.tElement = tElement;
    
    /** 
     * Map of datasets 
     * @type Object 
     */
    this.datasets = {};
    /**
     * Filter chains for this timemap 
     * @type Object
     */
    this.chains = {};
    /** 
     * Bounds of the map 
     * @type GLatLngBounds
     */
    this.mapBounds = new GLatLngBounds();
    
    // set defaults for options
    var defaults = {
        mapCenter:          new GLatLng(0,0),
        mapZoom:            0,
        mapType:            G_PHYSICAL_MAP,
        mapTypes:           [G_NORMAL_MAP, G_SATELLITE_MAP, G_PHYSICAL_MAP],
        showMapTypeCtrl:    true,
        showMapCtrl:        true,
        syncBands:          true,
        mapFilter:          'hidePastFuture',
        centerOnItems:      true,
        theme:              'red'
    };
    
    /** 
     * Container for optional settings passed in the "options" parameter
     * @type Object
     */
    this.opts = options = util.merge(options, defaults);
    
    // only these options will cascade to datasets and items
    options.mergeOnly = ['mergeOnly', 'theme', 'eventIconPath', 'openInfoWindow', 
                         'closeInfoWindow', 'noPlacemarkLoad', 'noEventLoad']
    
    // allow map types to be specified by key
    options.mapType = util.lookup(options.mapType, TimeMap.mapTypes);
    // allow map filters to be specified by key
    options.mapFilter = util.lookup(options.mapFilter, TimeMap.filters);
    // allow theme options to be specified in options
    options.theme = TimeMapTheme.create(options.theme, options);
    
    // initialize map
    if (GBrowserIsCompatible()) {
        /** 
         * The associated GMap object 
         * @type GMap2
         */
        this.map = new GMap2(this.mElement);
        var map = this.map;
        if (options.showMapCtrl) {
            map.addControl(new GLargeMapControl());
        }
        if (options.showMapTypeCtrl) {
            map.addControl(new GMapTypeControl());
        }
        // drop all existing types
        var i;
        for (i=G_DEFAULT_MAP_TYPES.length-1; i>0; i--) {
            map.removeMapType(G_DEFAULT_MAP_TYPES[i]);
        }
        // you can't remove the last maptype, so add a new one first
        map.addMapType(options.mapTypes[0]);
        map.removeMapType(G_DEFAULT_MAP_TYPES[0]);
        // add the rest of the new types
        for (i=1; i<options.mapTypes.length; i++) {
            map.addMapType(options.mapTypes[i]);
        }
        map.enableDoubleClickZoom();
        map.enableScrollWheelZoom();
        map.enableContinuousZoom();
        // initialize map center and zoom
        map.setCenter(options.mapCenter, options.mapZoom);
        // must be called after setCenter, for reasons unclear
        map.setMapType(options.mapType);
    }
};

/**
 * Current library version.
 * @type String
 */
TimeMap.version = "1.6pre";

/**
 * @name TimeMap.util
 * @namespace
 * Namespace for TimeMap utility functions.
 */
var util = TimeMap.util = {};

/**
 * Intializes a TimeMap.<commit_msg>moving mapInit to a separate function<commit_after>/*! 
 * Timemap.js Copyright 2008 <NAME>.
 * Licensed under the MIT License (see LICENSE.txt)
 */

/**
 * @overview
 * Timemap.js is intended to sync a SIMILE Timeline with a Google Map.
 * Dependencies: Google Maps API v2, SIMILE Timeline v1.2 - 2.3.1
 * Thanks to <NAME> (http://www.oe-files.de) for initial concept and code. 
 *
 * @name timemap.js
 * @author <NAME> (www.nickrabinowitz.com)
 * @version 1.6pre
 */

// globals - for JSLint
/*global GBrowserIsCompatible, GLargeMapControl, GMap2, GIcon       */ 
/*global GMapTypeControl, GDownloadUrl, GGroundOverlay              */
/*global GMarker, GPolygon, GPolyline, GSize, G_DEFAULT_ICON        */
/*global G_HYBRID_MAP, G_MOON_VISIBLE_MAP, G_SKY_VISIBLE_MAP        */

(function(){

// borrowing some space-saving devices from jquery
var 
	// Will speed up references to window, and allows munging its name.
	window = this,
	// Will speed up references to undefined, and allows munging its name.
	undefined,
    // aliases for Timeline objects
    Timeline = window.Timeline, DateTime = Timeline.DateTime, 
    // aliases for Google variables (anything that gets used more than once)
    G_DEFAULT_MAP_TYPES = window.G_DEFAULT_MAP_TYPES, 
    G_NORMAL_MAP = window.G_NORMAL_MAP, 
    G_PHYSICAL_MAP = window.G_PHYSICAL_MAP, 
    G_SATELLITE_MAP = window.G_SATELLITE_MAP, 
    GLatLng = window.GLatLng, 
    GLatLngBounds = window.GLatLngBounds, 
    GEvent = window.GEvent,
    // Google icon path
    GIP = "http://www.google.com/intl/en_us/mapfiles/ms/icons/",
    // aliases for class names, allowing munging
    TimeMap, TimeMapDataset, TimeMapTheme, TimeMapItem;

/*----------------------------------------------------------------------------
 * TimeMap Class
 *---------------------------------------------------------------------------*/
 
/**
 * @class
 * The TimeMap object holds references to timeline, map, and datasets.
 * This will create the visible map, but not the timeline, which must be initialized separately.
 *
 * @constructor
 * @param {element} tElement     The timeline element.
 * @param {element} mElement     The map element.
 * @param {Object} [options]       A container for optional arguments:<pre>
 *   {Boolean} syncBands            Whether to synchronize all bands in timeline
 *   {GLatLng} mapCenter            Point for map center
 *   {Number} mapZoom               Intial map zoom level
 *   {GMapType/String} mapType      The maptype for the map
 *   {Array} mapTypes               The set of maptypes available for the map
 *   {Function/String} mapFilter    How to hide/show map items depending on timeline state;
                                    options: "hidePastFuture", "showMomentOnly", or function
 *   {Boolean} showMapTypeCtrl      Whether to display the map type control
 *   {Boolean} showMapCtrl          Whether to show map navigation control
 *   {Boolean} centerMapOnItems     Whether to center and zoom the map based on loaded item positions
 *   {Function} openInfoWindow      Function redefining how info window opens
 *   {Function} closeInfoWindow     Function redefining how info window closes
 * </pre>
 */
TimeMap = function(tElement, mElement, options) {
    
    // save DOM elements
    /**
     * Map element
     * @type DOM Element
     */
    this.mElement = mElement;
    /**
     * Timeline element
     * @type DOM Element
     */
    this.tElement = tElement;
    
    /** 
     * Map of datasets 
     * @type Object 
     */
    this.datasets = {};
    /**
     * Filter chains for this timemap 
     * @type Object
     */
    this.chains = {};
    /** 
     * Bounds of the map 
     * @type GLatLngBounds
     */
    this.mapBounds = new GLatLngBounds();
    
    // set defaults for options
    var defaults = {
        mapCenter:          new GLatLng(0,0),
        mapZoom:            0,
        mapType:            G_PHYSICAL_MAP,
        mapTypes:           [G_NORMAL_MAP, G_SATELLITE_MAP, G_PHYSICAL_MAP],
        showMapTypeCtrl:    true,
        showMapCtrl:        true,
        syncBands:          true,
        mapFilter:          'hidePastFuture',
        centerOnItems:      true,
        theme:              'red'
    };
    
    /** 
     * Container for optional settings passed in the "options" parameter
     * @type Object
     */
    this.opts = options = util.merge(options, defaults);
    
    // only these options will cascade to datasets and items
    options.mergeOnly = ['mergeOnly', 'theme', 'eventIconPath', 'openInfoWindow', 
                         'closeInfoWindow', 'noPlacemarkLoad', 'noEventLoad']
    
    // allow map types to be specified by key
    options.mapType = util.lookup(options.mapType, TimeMap.mapTypes);
    // allow map filters to be specified by key
    options.mapFilter = util.lookup(options.mapFilter, TimeMap.filters);
    // allow theme options to be specified in options
    options.theme = TimeMapTheme.create(options.theme, options);
    
    // initialize map
    this.initMap();
};

/**
 * Initialize the map.
 */
TimeMap.prototype.initMap = function() {
    var options = this.opts, map, i;
    if (GBrowserIsCompatible()) {
    
        /** 
         * The associated GMap object 
         * @type GMap2
         */
        this.map = map = new GMap2(this.mElement);
        
        // set controls
        if (options.showMapCtrl) {
            map.addControl(new GLargeMapControl());
        }
        if (options.showMapTypeCtrl) {
            map.addControl(new GMapTypeControl());
        }
        
        // drop all existing types
        for (i=G_DEFAULT_MAP_TYPES.length-1; i>0; i--) {
            map.removeMapType(G_DEFAULT_MAP_TYPES[i]);
        }
        // you can't remove the last maptype, so add a new one first
        map.addMapType(options.mapTypes[0]);
        map.removeMapType(G_DEFAULT_MAP_TYPES[0]);
        // add the rest of the new types
        for (i=1; i<options.mapTypes.length; i++) {
            map.addMapType(options.mapTypes[i]);
        }
        // set basic parameters
        map.enableDoubleClickZoom();
        map.enableScrollWheelZoom();
        map.enableContinuousZoom();
        // initialize map center and zoom
        map.setCenter(options.mapCenter, options.mapZoom);
        // must be called after setCenter, for reasons unclear
        map.setMapType(options.mapType);
    }
};

/**
 * Current library version.
 * @type String
 */
TimeMap.version = "1.6pre";

/**
 * @name TimeMap.util
 * @namespace
 * Namespace for TimeMap utility functions.
 */
var util = TimeMap.util = {};

/**
 * Intializes a TimeMap.
{'fraction_non_alphanumeric': 0.11904944423150632, 'fraction_numerical': 0.0038328861632809506, 'mean_word_length': 2.1489258991069273, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5764084', 'n_tokens_mistral': 3849, 'n_tokens_neox': 3775, 'n_words': 1102}