Skip to content

Commit

Permalink
Added new method updateBBox in order to allow extent comparison to se…
Browse files Browse the repository at this point in the history
…e if coverage returned by WPS is inside or outside of a map visualization extent, other plugins should still work as before
  • Loading branch information
santilland committed Feb 27, 2014
1 parent ab8cd2a commit f0c34cf
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 48 deletions.
40 changes: 33 additions & 7 deletions src/d3.timeslider.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class TimeSlider
# Debugging?
@debug = true

localStorage.clear()
#localStorage.clear()

@bbox = null

# create the root svg element
@svg = d3.select(element).append('svg').attr('class', 'timeslider')
Expand Down Expand Up @@ -143,13 +145,13 @@ class TimeSlider
ranges: []
}

reloadDataset(dataset.id)
@reloadDataset(dataset.id)

@updateDataset = (dataset) =>
el = @svg.select("g.datasets #dataset-#{dataset}")
d = @data[dataset]

points = d.ranges.filter((values) => (@scales.x(new Date(values[1])) - @scales.x(new Date(values[0]))) < 5).map((values) => values[0])
points = d.ranges.filter((values) => (@scales.x(new Date(values[1])) - @scales.x(new Date(values[0]))) < 5)#.map((values) => values[0])
ranges = d.ranges.filter((values) => (@scales.x(new Date(values[1])) - @scales.x(new Date(values[0]))) >= 5)

drawRanges(el, ranges, { index: d.index, color: d.color })
Expand All @@ -165,9 +167,15 @@ class TimeSlider
d3.svg.line()
.x( (a) => @scales.x(new Date(a)) )
.y( -5 * options.index )
.defined((a, i) -> i <= 1)
.interpolate('linear')
)
.attr('stroke', options.color)
.style('opacity',
(a) =>
if(a[4]==false)
return 0.5
)

r.exit().remove()

Expand All @@ -177,14 +185,24 @@ class TimeSlider
.data(data)

p.enter().append('circle')
.attr('cx', (a) => @scales.x(new Date(a)) )
.attr('cx', (a) =>
if Array.isArray(a)
return @scales.x(new Date(a[0]))
else
return @scales.x(new Date(a))
)
.attr('cy', -5 * options.index )
.attr('fill', options.color)
.attr('r', 2)
.style('opacity',
(a) =>
if(a[4]==false)
return 0.5
)

p.exit().remove()

reloadDataset = (dataset) =>
@reloadDataset = (dataset) =>
callback = debounce(@options.debounce, dataset, =>
@data[dataset].callback(@scales.x.domain()[0], @scales.x.domain()[1], (id, data) =>
el = @svg.select("g.datasets #dataset-#{id}")
Expand All @@ -205,7 +223,7 @@ class TimeSlider
@data[id].ranges = ranges
@data[id].points = points
@updateDataset(id)
)
, @bbox)
)
callback()

Expand All @@ -223,7 +241,7 @@ class TimeSlider

# repaint the datasets
for dataset of @data
reloadDataset(dataset)
@reloadDataset(dataset)
@updateDataset(dataset)

# resizing (the window)
Expand Down Expand Up @@ -342,6 +360,14 @@ class TimeSlider
@zoom(@options.domain.start, @options.domain.end)
true

updateBBox: (bbox, id) ->
return false unless @data[id]?
@bbox = bbox
#d3.select(@element).select("g.dataset#dataset-#{id}").remove()
@reloadDataset(id)

true


class TimeSlider.Plugin

Expand Down
121 changes: 80 additions & 41 deletions src/plugins/wps.coffee
Original file line number Diff line number Diff line change
@@ -1,55 +1,94 @@
class TimeSlider.Plugin.WPS

constructor: (@options = {})->

@formatDate = (date) ->
# All EO-WCS servers used for testing can't handle subsecond precision dates, so we strip this information
date.toISOString().substring(0, 19) + "Z"

callback = (start, end, callback) =>
postdata = """
<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
<ows:Identifier>getTimeData</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>collection</ows:Identifier>
<wps:Data>
<wps:LiteralData>#{ @options.eoid }</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>begin_time</ows:Identifier>
<wps:Data>
<wps:LiteralData>#{ @formatDate(start) }</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>end_time</ows:Identifier>
<wps:Data>
<wps:LiteralData>#{ @formatDate(end) }</wps:LiteralData>
</wps:Data>
</wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput mimeType="text/plain">
<ows:Identifier>times</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>
"""
request = d3.csv(@options.url)

request.post(postdata, (error, response) =>
callback(@options.dataset, []) if error
@current_bbox = @options.bbox
@current_data = null
@current_start = new Date();
@current_end = new Date();

callback = (start, end, callback, bbox) =>

if (@current_start.getTime() != start.getTime() && @current_end.getTime() != end.getTime())
#console.log "Fetching data for " + @options.eoid
postdata = """
<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
<ows:Identifier>getTimeData</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>collection</ows:Identifier>
<wps:Data>
<wps:LiteralData>#{ @options.eoid }</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>begin_time</ows:Identifier>
<wps:Data>
<wps:LiteralData>#{ @formatDate(start) }</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>end_time</ows:Identifier>
<wps:Data>
<wps:LiteralData>#{ @formatDate(end) }</wps:LiteralData>
</wps:Data>
</wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput mimeType="text/plain">
<ows:Identifier>times</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>
"""
request = d3.csv(@options.url)

request.post(postdata, (error, response) =>
callback(@options.dataset, []) if error

datasets = []

for coverage in response
inside = false
if !@current_bbox
inside = true
else
bbox_a = coverage.bbox.replace(/[()]/g,'').split(',').map(parseFloat)
if(!(@current_bbox[0] > bbox_a[2] || @current_bbox[2] < bbox_a[0] || @current_bbox[3] < bbox_a[1] || @current_bbox[1] > bbox_a[3]) )
inside = true

datasets.push([ new Date(coverage.starttime), new Date(coverage.endtime), coverage.identifier, coverage.bbox, inside ])

@current_data = datasets
@current_bbox = bbox
@current_start = start
@current_end = end

callback(@options.dataset, datasets)
)

else
#console.log "Updating data for " + @options.eoid
datasets = []
for coverage in @current_data
inside = false
bbox_a = coverage[3].replace(/[()]/g,'').split(',').map(parseFloat)
if @current_bbox
if(!(bbox[0] > bbox_a[2] || bbox[2] < bbox_a[0] || bbox[3] < bbox_a[1] || bbox[1] > bbox_a[3]) )
inside = true
else
inside = true

datasets.push([ new Date(coverage[0]), new Date(coverage[1]), coverage[2], coverage[3], inside ])

for coverage in response
datasets.push([ new Date(coverage.starttime), new Date(coverage.endtime) ])
@current_data = datasets
@current_bbox = bbox

callback(@options.dataset, datasets)
)

return callback


0 comments on commit f0c34cf

Please sign in to comment.