Skip to content

Commit

Permalink
merge in missing stuff from the mapstory branch, now that this develo…
Browse files Browse the repository at this point in the history
…pment has settled down
  • Loading branch information
Bart van den Eijnden committed Feb 11, 2013
1 parent 0761fae commit cb8d52c
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 65 deletions.
1 change: 1 addition & 0 deletions src/script/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"widgets/form/FontComboBox.js",
"widgets/form/GoogleGeocoderComboBox.js",
"widgets/form/ViewerField.js",
"widgets/form/ExtendedDateField.js",
"widgets/grid/CapabilitiesGrid.js",
"widgets/grid/FeatureGrid.js",
"widgets/GoogleEarthPanel.js",
Expand Down
142 changes: 84 additions & 58 deletions src/script/widgets/TimelinePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,10 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
*/
onChange: function(slider, value, thumb) {
// TODO this logic needs to be more centralized, it's now in several places
var range = this.playbackTool.playbackToolbar.control.range;
var range = this.playbackTool.playbackToolbar.control.animationRange;
range = this.calculateNewRange(range, value);
var start = new Date(range[0].getTime() - this.bufferFraction * (range[1] - range[0]));
var end = new Date(range[1].getTime() + this.bufferFraction * (range[1] - range[0]));
var start = new Date(range[0] - this.bufferFraction * (range[1] - range[0]));
var end = new Date(range[1] + this.bufferFraction * (range[1] - range[0]));
// don't go beyond the original range
start = new Date(Math.max(this.originalRange[0], start));
end = new Date(Math.min(this.originalRange[1], end));
Expand All @@ -457,13 +457,13 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
*/
onChangeComplete: function(slider, value) {
if (this.playbackTool) {
var range = this.playbackTool.playbackToolbar.control.range;
var range = this.playbackTool.playbackToolbar.control.animationRange;
range = this.calculateNewRange(range, value);
// correct for movements of the timeline in the mean time
var center = this.playbackTool.playbackToolbar.control.currentTime;
var center = this.playbackTool.playbackToolbar.control.currentValue;
var span = range[1]-range[0];
var start = new Date(center.getTime() - span/2);
var end = new Date(center.getTime() + span/2);
var start = new Date(center - span/2);
var end = new Date(center + span/2);
for (var key in this.layerLookup) {
var layer = this.layerLookup[key].layer;
layer && this.setTimeFilter(key, this.createTimeFilter([start, end], key, this.bufferFraction));
Expand Down Expand Up @@ -627,6 +627,13 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
this.featureEditor = featureEditor;
this.featureManager = featureEditor.getFeatureManager();
this.featureManager.on("layerchange", this.onLayerChange, this);
this.featureManager.on("query", function(fm ,store) {
store.on("load", function(store, rs, options) {
if (rs.length > 0) {
this.ownerCt.expand();
}
}, this, {single: true});
}, this, {single: true});
},

/**
Expand Down Expand Up @@ -755,13 +762,13 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
/**
* private: method[onTimeChange]
* :arg toolbar: ``gxp.plugin.PlaybackToolbar``
* :arg currentTime: ``Date``
* :arg currentValue: ``Number``
*
* Listener for when the playback tool fires timechange.
*/
onTimeChange: function(toolbar, currentTime) {
onTimeChange: function(toolbar, currentValue) {
this._silent = true;
this._ignoreTimeChange !== true && this.setCenterDate(currentTime);
this._ignoreTimeChange !== true && this.setCenterDate(currentValue);
delete this._silent;
},

Expand Down Expand Up @@ -797,7 +804,7 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
intervalUnits.push(Timeline.DateTime.YEAR);
intervalUnits.push(Timeline.DateTime.DECADE);
}
var d = new Date(range[0].getTime() + span/2);
var d = new Date(range[0] + span/2);
var bandInfos = [
Timeline.createBandInfo({
width: "80%",
Expand Down Expand Up @@ -868,7 +875,7 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
if (this._silent !== true && this.playbackTool && this.playbackTool.playbackToolbar.playing !== true) {
this._ignoreTimeChange = true;
this.playbackTool.setTime(time);
this.timeline.getBand(0)._decorators[0]._date = this.playbackTool.playbackToolbar.control.currentTime;
this.timeline.getBand(0)._decorators[0]._date = this.playbackTool.playbackToolbar.control.currentValue;
this.timeline.getBand(0)._decorators[0].paint();
delete this._ignoreTimeChange;
this.showAnnotations();
Expand Down Expand Up @@ -1134,8 +1141,8 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
gxp.TimelinePanel.superclass.onLayout.call(this, arguments);
if (!this.timeline) {
if (this.playbackTool && this.playbackTool.playbackToolbar) {
this.setRange(this.playbackTool.playbackToolbar.control.range);
this.setCenterDate(this.playbackTool.playbackToolbar.control.currentTime);
this.setRange(this.playbackTool.playbackToolbar.control.animationRange);
this.setCenterDate(this.playbackTool.playbackToolbar.control.currentValue);
}
}
},
Expand Down Expand Up @@ -1243,39 +1250,53 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
this.tooltips = {};
}
var fid = record.getFeature().fid;
var content = record.get('content') || '';
var youtubeContent = content.indexOf('[youtube=') !== -1;
var listeners = {
'show': function(cmp) {
if (this.youtubePlayers[fid]._ready && this.playbackTool.playbackToolbar.playing) {
this.youtubePlayers[fid].playVideo();
if (youtubeContent === true) {
if (this.youtubePlayers[fid]._ready &&
this.playbackTool.playbackToolbar.playing) {
this.youtubePlayers[fid].playVideo();
}
}
},
'afterrender': function() {
if (!this.youtubePlayers[fid]) {
var id = 'player_' + fid;
var me = this;
this.youtubePlayers[fid] = new YT.Player(id, {
events: {
'onReady': function(evt) {
evt.target._ready = true;
if (me.playbackTool.playbackToolbar.playing) {
evt.target.playVideo();
}
},
'onStateChange': function(evt) {
if (evt.data === YT.PlayerState.PLAYING) {
if (me.playbackTool.playbackToolbar.playing) {
me.playbackTool.playbackToolbar._weStopped = true;
me.playbackTool.playbackToolbar.control.stop();
if (youtubeContent === true) {
if (!this.youtubePlayers[fid]) {
var me = this;
// stop immediately, if we wait for PLAYING we might be too late already
if (me.playbackTool.playbackToolbar.playing) {
me.playbackTool.playbackToolbar._weStopped = true;
me.playbackTool.playbackToolbar.control.stop();
}
var id = 'player_' + fid;
this.youtubePlayers[fid] = new YT.Player(id, {
events: {
'onReady': function(evt) {
evt.target._ready = true;
if (me.playbackTool.playbackToolbar.playing ||
me.playbackTool.playbackToolbar._weStopped) {
evt.target.playVideo();
}
} else if (evt.data == YT.PlayerState.ENDED) {
if (me.playbackTool.playbackToolbar._weStopped) {
me.playbackTool.playbackToolbar.control.play();
delete me.playbackTool.playbackToolbar._weStopped;
},
'onStateChange': function(evt) {
if (evt.data === YT.PlayerState.PLAYING) {
if (!me.playbackTool.playbackToolbar._weStopped &&
me.playbackTool.playbackToolbar.playing) {
me.playbackTool.playbackToolbar._weStopped = true;
me.playbackTool.playbackToolbar.control.stop();
}
} else if (evt.data == YT.PlayerState.ENDED) {
if (me.playbackTool.playbackToolbar._weStopped) {
me.playbackTool.playbackToolbar.control.play();
delete me.playbackTool.playbackToolbar._weStopped;
}
}
}
}
}
});
});
}
}
},
scope: this
Expand Down Expand Up @@ -1335,7 +1356,7 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
* Show annotations in the map.
*/
showAnnotations: function() {
var time = this.playbackTool.playbackToolbar.control.currentTime;
var time = this.playbackTool.playbackToolbar.control.currentValue;
if (!this.annotationsLayer) {
this.annotationsLayer = new OpenLayers.Layer.Vector(null, {
displayInLayerSwitcher: false,
Expand All @@ -1352,7 +1373,7 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
});
this.viewer && this.viewer.mapPanel.map.addLayer(this.annotationsLayer);
}
var compare = time.getTime()/1000;
var compare = time/1000;
if (this.featureManager && this.featureManager.featureStore) {
this.featureManager.featureStore.each(function(record) {
var mapFilterAttr = this.annotationConfig.mapFilterAttr;
Expand All @@ -1361,7 +1382,7 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
var endTime = record.get(this.annotationConfig.endTimeAttr);
var ranged = (endTime != startTime);
if (endTime == "" || endTime == null) {
endTime = this.playbackTool.playbackToolbar.control.range[1].getTime();
endTime = this.playbackTool.playbackToolbar.control.animationRange[1];
}
if (ranged === true) {
if (compare <= parseFloat(endTime) && compare >= startTime) {
Expand Down Expand Up @@ -1390,6 +1411,9 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
* Set the center datetime on the bands of this timeline.
*/
setCenterDate: function(time) {
if (!(time instanceof Date)) {
time = new Date(time);
}
if (this.timeline) {
this.timeline.getBand(0)._decorators[0]._date = time;
this.timeline.getBand(0)._decorators[0].paint();
Expand Down Expand Up @@ -1446,10 +1470,10 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
percentage = this.showRangeSlider ? this.rangeSlider.getValue() : this.initialRangeSliderValue;
}
var span = range[1] - range[0];
var center = this.playbackTool.playbackToolbar.control.currentTime;
var center = this.playbackTool.playbackToolbar.control.currentValue;
var newSpan = (percentage/100)*span;
var start = new Date(center.getTime() - newSpan/2);
var end = new Date(center.getTime() + newSpan/2);
var start = new Date(center - newSpan/2);
var end = new Date(center + newSpan/2);
return [start, end];
}
},
Expand All @@ -1464,8 +1488,8 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
* Create an OpenLayers.Filter to use in the WFS requests.
*/
createTimeFilter: function(range, key, fraction, updateRangeInfo) {
var start = new Date(range[0].getTime() - fraction * (range[1] - range[0]));
var end = new Date(range[1].getTime() + fraction * (range[1] - range[0]));
var start = new Date(range[0] - fraction * (range[1] - range[0]));
var end = new Date(range[1] + fraction * (range[1] - range[0]));
// don't go beyond the original range
if(this.originalRange){
start = new Date(Math.max(this.originalRange[0], start));
Expand Down Expand Up @@ -1611,9 +1635,9 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
this.layerLookup[key].sldFilter = this.getFilterFromSLD(key, style);
if (this.playbackTool) {
// TODO consider putting an api method getRange on playback tool
var range = this.playbackTool.playbackToolbar.control.range;
var range = this.playbackTool.playbackToolbar.control.animationRange;
range = this.calculateNewRange(range);
this.setCenterDate(this.playbackTool.playbackToolbar.control.currentTime);
this.setCenterDate(this.playbackTool.playbackToolbar.control.currentValue);
// create a PropertyIsBetween filter
this.setTimeFilter(key, this.createTimeFilter(range, key, this.bufferFraction));
}
Expand Down Expand Up @@ -1957,18 +1981,20 @@ gxp.TimelinePanel = Ext.extend(Ext.Panel, {
if (end == "" || end == null) {
// Simile does not deal with unlimited ranges, so let's
// take the range from the playback control
end = this.playbackTool.playbackToolbar.control.range[1];
end = new Date(this.playbackTool.playbackToolbar.control.animationRange[1]);
}
}
events.push({
start: start,
end: end,
icon: this.layerLookup[key].icon,
title: attributes[titleAttr],
durationEvent: durationEvent,
key: key,
fid: features[i].fid
});
if(start != null){
events.push({
start: start,
end: end,
icon: this.layerLookup[key].icon,
title: attributes[titleAttr],
durationEvent: durationEvent,
key: key,
fid: features[i].fid
});
}
}
}
}
Expand Down
43 changes: 37 additions & 6 deletions src/script/widgets/form/ExtendedDateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Date.defaults.d = 1;
Date.defaults.m = 1;

gxp.form.ExtendedDateTimeField = Ext.extend(Ext.form.CompositeField, {

initComponent: function() {
//ensure that qtips are initialized
Ext.QuickTips.init();
this.items = [{
xtype: 'gxp_datefield',
allowBlank: (this.initialConfig.allowBlank !== false),
Expand Down Expand Up @@ -71,27 +73,56 @@ Ext.reg('gxp_datetimefield', gxp.form.ExtendedDateTimeField);
*/
gxp.form.ExtendedDateField = Ext.extend(Ext.form.DateField, {

altFormats : "Y|m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j",

//negative year formats will parse but give a positive year
altFormats : "-c|-Y|m -Y|n -Y|M -Y|m/d/-Y|n/j/-Y|m/j/-Y|n/d/-Y|c|Y|" +
"m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|" +
"m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j",

bcYrRegEx : /^(-\d+)|(-\d+)$/,

invalidText : "{0} is not a valid date. If you are attempting to enter a BCE date please enter a zero padded 4 digit year or just enter the year",

beforeBlur: Ext.emptyFn,

getValue : function() {
var value = Ext.form.DateField.superclass.getValue.call(this);
var date = this.parseDate(value);
var bcYear = value.match(this.bcYrRegEx);
if (bcYear) {
if(date){
date = new Date(-1*date.getFullYear(),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds());
}
}
return (date) ? date.getTime()/1000 : null;
},

setValue: function(v) {
var d = v;
if (Ext.isNumber(parseFloat(v))) {
d = new Date(parseFloat(v)*1000);
}
return Ext.form.DateField.superclass.setValue.call(this, this.formatDate(d));
}
var str = this.formatDate(d);
if (str) {
var bcYear = str.match(this.bcYrRegEx);
if (bcYear) {
bcYear = bcYear[0] || bcYear[1];
if (bcYear && bcYear.length < 5) {
var zeropad = '-';
for (var i=bcYear.length;i<=4; ++i) {
zeropad += '0';
}
str = str.replace(bcYear, zeropad + Math.abs(parseInt(bcYear, 10)));
}
}
}
return Ext.form.DateField.superclass.setValue.call(this, str);
},

onTriggerClick : function(){
if(this.disabled){
return;
}
if(this.menu == null){
if(!this.menu){
this.menu = new Ext.menu.DateMenu({
hideOnClick: false,
focusOnSelect: false
Expand Down
1 change: 0 additions & 1 deletion src/theme/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ div.olMap div.gx-overlay-playback {
}

.gx_timeslider div.x-slider-thumb{
background-position:0;
cursor: pointer;
}
.gx_timeslider div.x-slider-min-thumb{
Expand Down
1 change: 1 addition & 0 deletions tests/list-tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<li>script/widgets/form/FontComboBox.html</li>
<li>script/widgets/form/GoogleGeocoderComboBox.html</li>
<li>script/widgets/form/ViewerField.html</li>
<li>script/widgets/form/ExtendedDateField.html</li>
<li>script/widgets/GoogleEarthPanel.html</li>
<li>script/widgets/GoogleStreetViewPanel.html</li>
<li>script/widgets/grid/CapabilitiesGrid.html</li>
Expand Down
Loading

0 comments on commit cb8d52c

Please sign in to comment.