/* * Timemap.js Copyright 2008 Nick Rabinowitz. * Licensed under the MIT License (see LICENSE.txt) */ (function(){var j=this,g,h=j.Timeline,i=h.DateTime,d=j.jQuery,q=j.mxn,s=q.Mapstraction,c=q.LatLonPoint,a=q.BoundingBox,f=q.Marker,o=q.Polyline,r="itemsloaded",k="/images/",l,p,n,m,e;l=function(u,w,v){var t=this,y={mapCenter:new c(0,0),mapZoom:0,mapType:"physical",showMapTypeCtrl:true,showMapCtrl:true,syncBands:true,mapFilter:"hidePastFuture",centerOnItems:true,theme:"red",dateParser:"hybrid",checkResize:true,multipleInfoWindows:false},x;t.mElement=w;t.tElement=u;t.datasets={};t.chains={};t.opts=v=d.extend(y,v);x=v.mapCenter;if(x.constructor!=c&&x.lat){v.mapCenter=new c(x.lat,x.lon)}v.mapType=b.lookup(v.mapType,l.mapTypes);v.mapFilter=b.lookup(v.mapFilter,l.filters);v.theme=m.create(v.theme,v);t.initMap()};l.version="2.0.1";var b=l.util={};l.init=function(v){var C="TimeMap.init: Either %Id or %Selector is required",B={options:{},datasets:[],bands:false,bandInfo:false,bandIntervals:"wk",scrollTo:"earliest"},t=l.state,F,I,D=[],G,y,A,u,z=[],w;v.mapSelector=v.mapSelector||"#"+v.mapId;v.timelineSelector=v.timelineSelector||"#"+v.timelineId;if(t){t.setConfigFromUrl(v)}v=d.extend(B,v);if(!v.bandInfo&&!v.bands){F=b.lookup(v.bandIntervals,l.intervals);v.bandInfo=[{width:"80%",intervalUnit:F[0],intervalPixels:70},{width:"20%",intervalUnit:F[1],intervalPixels:100,showEventText:false,overview:true,trackHeight:0.4,trackGap:0.2}]}I=new l(d(v.timelineSelector).get(0),d(v.mapSelector).get(0),v.options);v.datasets.forEach(function(K,J){y=d.extend({title:K.title,theme:K.theme,dateParser:K.dateParser},K.options);u=K.id||"ds"+J;D[J]=I.createDataset(u,y);if(J>0){D[J].eventSource=D[0].eventSource}});I.eventSource=D[0].eventSource;w=(D[0]&&D[0].eventSource)||new h.DefaultEventSource();if(v.bands){v.bands.forEach(function(x){if(x.eventSource!==null){x.eventSource=w}});z=v.bands}else{v.bandInfo.forEach(function(K,J){if(!(("eventSource" in K)&&!K.eventSource)){K.eventSource=w}else{K.eventSource=null}z[J]=h.createBandInfo(K);if(J>0&&b.TimelineVersion()=="1.2"){z[J].eventPainter.setLayout(z[0].eventPainter.getLayout())}})}I.initTimeline(z);var E=l.loadManager,H=function(){E.increment()};E.init(I,v.datasets.length,v);v.datasets.forEach(function(P,K){var Q=D[K],M=P.data||P.options||{},O=P.type||M.type,N=(typeof O=="string")?l.loaders[O]:O,J=new N(M);J.load(Q,H)});return I};l.prototype={initMap:function(){var t=this,u=t.opts,w,v;t.map=w=new s(t.mElement,u.mapProvider);w.setCenterAndZoom(u.mapCenter,u.mapZoom);w.addControls({pan:u.showMapCtrl,zoom:u.showMapCtrl?"large":false,map_type:u.showMapTypeCtrl});w.setMapType(u.mapType);if(u.multipleInfoWindows){w.setOption("enableMultipleBubbles",true)}t.getNativeMap=function(){return w.getMap()}},initTimeline:function(w){var C=this,B,u=C.opts,D=function(x){return x.visible},v=function(x){return x.dataset.visible},y=function(E,G,F){F.item.openInfoWindow()},t,A,z;for(A=1;A0?true:false;switch(t){case"now":break;case"earliest":case"first":if(w){v=u.getEarliestDate()}break;case"latest":case"last":if(w){v=u.getLatestDate()}break;default:v=x(t)}return v},scrollToDate:function(z,A,y){var G=this.timeline,u=G.getBand(0),D,v,E=[],F,w,t;z=this.parseDate(z);if(z){v=z.getTime();for(D=0;Dw&&v=t.target){t.complete()}};t.complete=function(){var u=t.tm,w=t.opts,v=w.dataLoadedFunction;if(v){v(u)}else{u.scrollToDate(w.scrollTo,true);if(u.initState){u.initState()}v=w.dataDisplayedFunction;if(v){v(u)}}}}();l.loaders={cb:{},cancel:function(u){var t=l.loaders.cb;t[u]=function(){delete t[u]}},cancelAll:function(){var t=l.loaders,u=t.cb,v;for(v in u){if(u.hasOwnProperty(v)){t.cancel(v)}}},counter:0,base:function(u){var v=function(w){return w},t=this;t.parse=u.parserFunction||v;t.preload=u.preloadFunction||v;t.transform=u.transformFunction||v;t.scrollTo=u.scrollTo||"earliest";t.getCallbackName=function(y,z){var w=l.loaders.cb,x="_"+l.loaders.counter++;z=z||function(){y.timemap.scrollToDate(t.scrollTo,true)};w[x]=function(A){var B=t.parse(A);B=t.preload(B);y.loadItems(B,t.transform);z();delete w[x]};return x};t.getCallback=function(x,y){var w=t.getCallbackName(x,y);return l.loaders.cb[w]};t.cancel=function(){l.loaders.cancel(t.callbackName)}},basic:function(u){var t=new l.loaders.base(u);t.data=u.items||u.value||[];t.load=function(v,w){(this.getCallback(v,w))(this.data)};return t},remote:function(u){var t=new l.loaders.base(u);t.opts=d.extend({},u,{type:"GET",dataType:"text"});t.load=function(v,w){t.callbackName=t.getCallbackName(v,w);t.opts.success=l.loaders.cb[t.callbackName];d.ajax(t.opts)};return t}};p=function(v,u,t,A,x,w){var y=this,z=d.noop;y.timemap=v;y.chain=w||[];y.on=u||z;y.off=t||z;y.pre=A||z;y.post=x||z};p.prototype={add:function(t){return this.chain.push(t)},remove:function(v){var u=this.chain,t=v?u.indexOf(v):u.length-1;return u.splice(t,1)},run:function(){var u=this,t=u.chain;if(!t.length){return}u.pre();u.timemap.eachItem(function(x){var v,w=t.length;L:while(!v){while(w--){if(!t[w](x)){u.off(x);break L}}u.on(x);v=true}});u.post()}};l.filters={hidePastFuture:function(t){return t.onVisibleTimeline()},hideFuture:function(v){var u=v.timeline.getBand(0).getMaxVisibleDate().getTime(),t=v.getStartTime();if(t!==g){return tx||t>x)}return true}};n=function(t,u){var v=this;v.timemap=t;v.eventSource=new h.DefaultEventSource();v.items=[];v.visible=true;v.opts=u=d.extend({},t.opts,u);u.dateParser=b.lookup(u.dateParser,l.dateParsers);u.theme=m.create(u.theme,u)};n.prototype={getItems:function(u){var t=this.items;return u===g?t:u in t?t[u]:null},getTitle:function(){return this.opts.title},each:function(t){this.items.forEach(t)},loadItems:function(v,t){if(v){var u=this;v.forEach(function(w){u.loadItem(w,t)});d(u).trigger(r)}},loadItem:function(w,t){if(t){w=t(w)}if(w){var v=this,u;w.options=d.extend({},v.opts,{title:null},w.options);u=new e(w,v);v.items.push(u);return u}}};m=function(t){var v={color:"#FE766A",lineOpacity:1,lineWeight:2,fillOpacity:0.4,eventTextColor:null,eventIconPath:"timemap/images/",eventIconImage:"red-circle.png",classicTape:false,icon:k+"red-dot.png",iconSize:[32,32],iconShadow:k+"msmarker.shadow.png",iconShadowSize:[59,32],iconAnchor:[16,33]};var u=d.extend(v,t);v={lineColor:u.color,fillColor:u.color,eventColor:u.color,eventIcon:u.eventIcon||u.eventIconPath+u.eventIconImage};return d.extend(v,u)};m.create=function(v,t){v=b.lookup(v,l.themes);if(!v){return new m(t)}if(t){var w=false,u;for(u in t){if(v.hasOwnProperty(u)){w={};break}}if(w){for(u in v){if(v.hasOwnProperty(u)){w[u]=t[u]||v[u]}}w.eventIcon=t.eventIcon||w.eventIconPath+w.eventIconImage;return w}}return v};e=function(O,F){var M=this,z=d.extend({type:"none",description:"",infoPoint:null,infoHtml:"",infoUrl:"",openInfoWindow:O.options.infoUrl?e.openInfoWindowAjax:e.openInfoWindowBasic,infoTemplate:'
{{title}}
{{description}}
',templatePattern:/\{\{([^}]+)\}\}/g,closeInfoWindow:e.closeInfoWindowBasic},O.options),x=F.timemap,N=z.theme=m.create(z.theme,z),w=z.dateParser,E=h.DefaultEventSource.Event,C=O.start,A=O.end,u=N.eventIcon,B=N.eventTextColor,P=z.title=O.title||"Untitled",J=null,v,D=[],H=[],t=null,y="",I=null,K;M.dataset=F;M.map=x.map;M.timeline=x.timeline;M.opts=z;C=C?w(C):null;A=A?w(A):null;v=!A;if(C!==null){if(b.TimelineVersion()=="1.2"){J=new E(C,A,null,null,v,P,null,null,null,u,N.eventColor,N.eventTextColor)}else{if(!B){B=(N.classicTape&&!v)?"#FFFFFF":"#000000"}J=new E({start:C,end:A,instant:v,text:P,icon:u,color:N.eventColor,textColor:B})}J.item=M;if(!z.noEventLoad){F.eventSource.add(J)}}M.event=J;function G(U){var T=null,W="",Z=null,ac;if(U.point){var V=U.point.lat,Q=U.point.lon;if(V===g||Q===g){return T}Z=new c(parseFloat(V),parseFloat(Q));T=new f(Z);T.setLabel(U.title);T.addData(N);W="marker"}else{if(U.polyline||U.polygon){var aa=[],R="polygon" in U,ab=U.polyline||U.polygon,X;ac=new a();if(ab&&ab.length){for(X=0;X1?"array":y;z.infoPoint=z.infoPoint?new c(parseFloat(z.infoPoint.lat),parseFloat(z.infoPoint.lon)):I;D.forEach(function(Q){Q.item=M;Q.click.addHandler(function(){M.openInfoWindow()});if(!z.noPlacemarkLoad){if(b.getPlacemarkType(Q)=="marker"){x.map.addMarker(Q)}else{x.map.addPolyline(Q)}Q.hide()}});M.placemark=D.length==1?D[0]:D.length?D:null;M.getNativePlacemark=function(){var Q=M.placemark;return Q&&(Q.proprietary_marker||Q.proprietary_polyline)};M.getType=function(){return z.type};M.getTitle=function(){return z.title};M.getInfoPoint=function(){return z.infoPoint||M.map.getCenter()};M.getStart=function(){return M.event?M.event.getStart():null};M.getEnd=function(){return M.event?M.event.getEnd():null};M.getStartTime=function(){var Q=M.getStart();if(Q){return Q.getTime()}};M.getEndTime=function(){var Q=M.getEnd();if(Q){return Q.getTime()}};M.isSelected=function(){return x.getSelected()===M};M.visible=true;M.placemarkVisible=false;M.eventVisible=true;M.openInfoWindow=function(){z.openInfoWindow.call(M);x.setSelected(M)};M.closeInfoWindow=function(){z.closeInfoWindow.call(M);x.setSelected(g)}};e.prototype={showPlacemark:function(){var t=this,u=function(v){if(v.api){v.show()}};if(t.placemark&&!t.placemarkVisible){if(t.getType()=="array"){t.placemark.forEach(u)}else{u(t.placemark)}t.placemarkVisible=true}},hidePlacemark:function(){var t=this,u=function(v){if(v.api){v.hide()}};if(t.placemark&&t.placemarkVisible){if(t.getType()=="array"){t.placemark.forEach(u)}else{u(t.placemark)}t.placemarkVisible=false}t.closeInfoWindow()},showEvent:function(){var u=this,t=u.event;if(t&&!u.eventVisible){u.timeline.getBand(0).getEventSource()._events._events.add(t);u.eventVisible=true}},hideEvent:function(){var u=this,t=u.event;if(t&&u.eventVisible){u.timeline.getBand(0).getEventSource()._events._events.remove(t);u.eventVisible=false}},scrollToStart:function(u){var t=this;if(t.event){t.dataset.timemap.scrollToDate(t.getStart(),false,u)}},getInfoHtml:function(){var v=this.opts,u=v.infoHtml,w=v.templatePattern,t;if(!u){u=v.infoTemplate;t=w.exec(u);while(t){u=u.replace(t[0],v[t[1]]||"");t=w.exec(u)}v.infoHtml=u}return u},onVisibleTimeline:function(){var w=this,y=w.timeline.getBand(0),u=y.getMaxVisibleDate().getTime(),v=y.getMinVisibleDate().getTime(),t=w.getStartTime(),x=w.getEndTime();return t!==g?tv||t>v):true}};e.openInfoWindowBasic=function(){var v=this,u=v.getInfoHtml(),w=v.dataset,t=v.placemark;if(!v.onVisibleTimeline()){w.timemap.scrollToDate(v.getStart())}if(v.getType()=="marker"&&t.api){t.setInfoBubble(u);t.openBubble();v.closeHandler=t.closeInfoBubble.addHandler(function(){w.timemap.setSelected(g);t.closeInfoBubble.removeHandler(v.closeHandler)})}else{v.map.openBubble(v.getInfoPoint(),u);v.map.tmBubbleItem=v}};e.openInfoWindowAjax=function(){var t=this;if(!t.opts.infoHtml&&t.opts.infoUrl){d.get(t.opts.infoUrl,function(u){t.opts.infoHtml=u;t.openInfoWindow()});return}t.openInfoWindow=function(){e.openInfoWindowBasic.call(t);t.dataset.timemap.setSelected(t)};t.openInfoWindow()};e.closeInfoWindowBasic=function(){var t=this;if(t.getType()=="marker"){t.placemark.closeBubble()}else{if(t==t.map.tmBubbleItem){t.map.closeBubble();t.map.tmBubbleItem=null}}};l.util.getTagValue=function(v,t,u){return b.getNodeList(v,t,u).first().text()};l.util.nsMap={};l.util.getNodeList=function(w,u,v){var t=l.util.nsMap;w=w.jquery?w[0]:w;return !w?d():!v?d(u,w):(w.getElementsByTagNameNS&&t[v])?d(w.getElementsByTagNameNS(t[v],u)):d(w.getElementsByTagName(v+":"+u))};l.util.makePoint=function(u,v){var t=null;if(u.lat&&u.lng){t=[u.lat(),u.lng()]}if(d.type(u)=="array"){t=u}if(!t){u=d.trim(u);if(u.indexOf(",")>-1){t=u.split(",")}else{t=u.split(/[\r\n\f ]+/)}}if(t.length>2){t=t.slice(0,2)}if(v){t.reverse()}return{lat:d.trim(t[0]),lon:d.trim(t[1])}};l.util.makePoly=function(w,z){var v=[],u,t,y=d.trim(w).split(/[\r\n\f ]+/);for(t=0;t0)?y[t].split(","):[y[t],y[++t]];if(u.length>2){u=u.slice(0,2)}if(z){u.reverse()}v.push({lat:u[0],lon:u[1]})}return v};l.util.formatDate=function(z,y){y=y||3;var A="";if(z){var x=z.getUTCFullYear(),u=z.getUTCMonth(),B=z.getUTCDate();if(x<1000){return(x<1?(x*-1+"BC"):x+"")}if(z.toISOString&&y==3){return z.toISOString()}var t=function(D){return((D<10)?"0":"")+D};A+=x+"-"+t(u+1)+"-"+t(B);if(y>1){var v=z.getUTCHours(),w=z.getUTCMinutes(),C=z.getUTCSeconds();A+="T"+t(v)+":"+t(w);if(y>2){A+=t(C)}A+="Z"}}return A};l.util.TimelineVersion=function(){return h.version||(h.DurationEventPainter?"1.2":"2.2.0")};l.util.getPlacemarkType=function(t){return t.constructor==f?"marker":t.constructor==o?(t.closed?"polygon":"polyline"):false};l.util.lookup=function(t,u){return typeof t=="string"?u[t]:t};if(!([].indexOf)){Array.prototype.indexOf=function(v){var t=this,u=t.length;while(--u>=0){if(t[u]===v){break}}return u}}if(!([].forEach)){Array.prototype.forEach=function(v){var t=this,u;for(u=0;u