/* * Timemap.js Copyright 2010 Nick Rabinowitz. * Licensed under the MIT License (see LICENSE.txt) */ /** * @fileOverview * Additional TimeMap manipulation functions. * Functions in this file are used to manipulate a TimeMap, TimeMapDataset, or * TimeMapItem after the initial load process. * * @author Nick Rabinowitz (www.nickrabinowitz.com) */ (function(){ var window = this, TimeMap = window.TimeMap, TimeMapDataset = window.TimeMapDataset, TimeMapItem = window.TimeMapItem, util = TimeMap.util; /*---------------------------------------------------------------------------- * TimeMap manipulation: stuff affecting every dataset *---------------------------------------------------------------------------*/ // XXX: This should $.extend the prototype, I think /** * Delete all datasets, clearing them from map and timeline. Note * that this is more efficient than calling clear() on each dataset. */ TimeMap.prototype.clear = function() { var tm = this; tm.eachItem(function(item) { item.event = item.placemark = null; }); tm.map.removeAllPolylines(); tm.map.removeAllMarkers(); tm.eventSource.clear(); tm.datasets = []; }; /** * Delete one dataset, clearing it from map and timeline * * @param {String} id Id of dataset to delete */ TimeMap.prototype.deleteDataset = function(id) { this.datasets[id].clear(); delete this.datasets[id]; }; /** * Hides placemarks for a given dataset * * @param {String} id The id of the dataset to hide */ TimeMap.prototype.hideDataset = function (id){ if (id in this.datasets) { this.datasets[id].hide(); } }; /** * Hides all the datasets on the map */ TimeMap.prototype.hideDatasets = function(){ var tm = this; tm.each(function(ds) { ds.visible = false; }); tm.filter("map"); tm.filter("timeline"); }; /** * Shows placemarks for a given dataset * * @param {String} id The id of the dataset to hide */ TimeMap.prototype.showDataset = function(id) { if (id in this.datasets) { this.datasets[id].show(); } }; /** * Shows all the datasets on the map */ TimeMap.prototype.showDatasets = function() { var tm = this; tm.each(function(ds) { ds.visible = true; }); tm.filter("map"); tm.filter("timeline"); }; /** * Change the default map type * * @param {String} mapType The maptype for the map (see {@link TimeMap.mapTypes} for options) */ TimeMap.prototype.changeMapType = function (mapType) { var tm = this; // check for no change if (mapType == tm.opts.mapType) { return; } // look for mapType if (typeof(mapType) == 'string') { mapType = TimeMap.mapTypes[mapType]; } // no mapType specified if (!mapType) { return; } // change it tm.opts.mapType = mapType; tm.map.setMapType(mapType); }; /*---------------------------------------------------------------------------- * TimeMap manipulation: stuff affecting the timeline *---------------------------------------------------------------------------*/ /** * Refresh the timeline, maintaining the current date */ TimeMap.prototype.refreshTimeline = function () { var topband = this.timeline.getBand(0); var centerDate = topband.getCenterVisibleDate(); if (util.TimelineVersion() == "1.2") { topband.getEventPainter().getLayout()._laidout = false; } this.timeline.layout(); topband.setCenterVisibleDate(centerDate); }; /** * Change the intervals on the timeline. * * @param {String|Array} intervals New intervals. If string, looks up in TimeMap.intervals. */ TimeMap.prototype.changeTimeIntervals = function (intervals) { var tm = this; // check for no change or no intervals if (!intervals || intervals == tm.opts.bandIntervals) { return; } // resolve string references if necessary intervals = util.lookup(intervals, TimeMap.intervals); tm.opts.bandIntervals = intervals; // internal function - change band interval function changeInterval(band, interval) { band.getEther()._interval = Timeline.DateTime.gregorianUnitLengths[interval]; band.getEtherPainter()._unit = interval; } // grab date var topband = tm.timeline.getBand(0), centerDate = topband.getCenterVisibleDate(), x; // change interval for each band for (x=0; x