from ows_server.lib.base import *
from ows_server.lib.ndgInterface import interface
class VisualiseController(BaseController):
def __setup(self):
c.fullpage=1 # we want the whole page
c.selections = {}
c.selected = {}
c.names={}
c.bbox = (90, -180, 180, -90)
c.inpageid = 'api'
for uri, name in session.get('selection', []):
(rstatus, dataset) = interface.GetParsedCSML(uri)
if not rstatus:
c.xml='
%s
'%dataset
return render('error')
c.selections[uri]=dataset
c.names[uri]=name
c.nothing2see=0
if c.selections=={}:
c.nothing2see=1
return 0
# Need two fundamental variables: the granules which has been selected
# for *possible* visualisation, and the granules (up to two) which have been
# selected for *actual* visualisation:
# session['selection'] holds the uris assocated with the first
# session['selectedVis'] holds the uris and featureIDs associated with the second
# c.selections holds the uris and the parsed csml for the datasets
# c.selected holds the uris, featureIDs and the parsed feature instances for the second
# some defaults
defURI=c.selections.keys()[0]
defFid=c.selections[defURI].getFeatureList()[0]
keys=session.get('selectedVis',[])
if keys==[]: keys=[(defURI,defFid)]
#yes, I know I could have sued the default on the session.get, but
#it's also possible that selectedVis is actually set to [] and we
#want to override that case too!
for uri,featureID in keys:
featureInstance=c.selections[uri].getFeature(featureID)
c.selected[(uri,featureID)]=featureInstance
# We also need to know which dataset (if any) we are looking at
c.viewedDataset=session.get('viewedDataset',c.selections.keys()[0])
return 0
def __plotops(self):
''' Works out what we can do in the way of plot options and flags the info to the template'''
c.wmsAvailable=0
for i in c.selected:
if 'latitude' and 'longitude' in c.selected[i].getAxisLabels(): c.wmsAvailable=1
def index(self):
s=self.__setup()
if s: return s
c.visible='Granules'
self.__plotops()
return render('visualise')
def tabChange(self,dataset,view):
''' Take ajax request for inpage tab change '''
s=self.__setup()
if s: return s
c.visible=view
formValue=request.params.get('dataset',0)
if formValue: dataset=formValue
#dataset is really a uri ...shame about the variable name we chose ...
# the incoming dataset ought to be in the selections, so this is only
# about telling the interface what variable list to display ... and
# remembering it
c.viewedDataset=dataset
session['viewedDataset']=dataset
session.save()
c.fullpage=0
self.__plotops()
return render('visualise',fragment=True)
def featureChange(self,view):
''' Take an ajax request and update the current list of features '''
self.__setup()
if s: return s
c.visible=view
checkedFeatures=[]
# ok, we know we are getting features from viewedDataset
# let's collect them up a we go so we know which ones we've
# lost (if any), as well as parse them as we go ...
checkedFeatures
for i in request.params:
featureID=request.params[i]
checkedFeatures.append(featureID)
if 'Feature' in i:
if (c.viewedDataset,featureID) not in c.selected:
featureInstance=c.selections[c.viewedDataset].getFeature(featureID)
c.selected[(c.viewedDataset,featureID)]=featureInstance
#ok, now we remove them if necessary
removeList=[]
for suri,sf in c.selected:
if suri==c.viewedDataset and sf not in checkedFeatures:
removeList.append((suri,sf))
for i in removeList: del c.selected[i]
# and update the session
session['selectedVis']=c.selected.keys()
session.save()
c.fullpage=0
self.__plotops()
return render('visualise',fragment=True)
def tabcontent(self):
pass
def plot(self):
pass