source: branches/geomap/gui/scripts/geomapdataprovider.tcl @ 5949

Last change on this file since 5949 was 5949, checked in by dkearney, 8 years ago

adding data provider and layer objects, updating mapviewer to remove layers from client and server.

File size: 6.2 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
3#  COMPONENT: geomapdataprovider -
4#               holds data source information for a geomap layer
5#
6# ======================================================================
7#  AUTHOR:  Derrick Kearney, Purdue University
8#  Copyright (c) 2004-2015  HUBzero Foundation, LLC
9#
10#  See the file "license.terms" for information on usage and
11#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12# ======================================================================
13package require Itcl
14package require BLT
15
16namespace eval Rappture {
17    # forward declaration
18}
19
20
21itcl::class Rappture::GeoMapDataProvider {
22    constructor {type driver url args} {
23        # defined below
24    }
25    destructor {
26        # defined below
27    }
28
29    private variable _type ""
30    private variable _driver ""
31    private variable _url ""
32
33    public variable attribution ""
34    public variable cache "true"
35
36    protected method Type { args }
37    protected method Driver { args }
38    protected method Url { args }
39
40    public method type { }
41    public method driver { }
42    public method url { }
43
44    public method exportToBltTree { tree }
45}
46
47# ----------------------------------------------------------------------
48# CONSTRUCTOR
49# ----------------------------------------------------------------------
50itcl::body Rappture::GeoMapDataProvider::constructor {type driver url args} {
51
52    Type $type
53    Driver $driver
54    Url $url
55
56    eval configure $args
57}
58
59
60# ----------------------------------------------------------------------
61# DESTRUCTOR
62# ----------------------------------------------------------------------
63itcl::body Rappture::GeoMapDataProvider::destructor {} {
64
65}
66
67
68# ----------------------------------------------------------------------
69# Type: get/set type of layer
70# ----------------------------------------------------------------------
71itcl::body Rappture::GeoMapDataProvider::Type {args} {
72
73    set valids {image elevation feature icon line point polygon text}
74
75
76    if {[llength $args] > 1} {
77        error "wrong # of arguments: should be ?type?"
78    }
79
80    if {[llength $args] == 1} {
81
82        set value [lindex $args 0]
83
84        if {[string compare "" $value] == 0} {
85            error "bad value \"$value\": should be a non-empty string"
86        }
87
88        if {[lsearch $valids $value] < 0} {
89            error "bad value \"$value\": should be one of \"$valids\""
90        }
91
92        set _type $value
93    }
94
95    return $_type
96}
97
98
99# ----------------------------------------------------------------------
100# Driver: get/set driver for layer
101# ----------------------------------------------------------------------
102itcl::body Rappture::GeoMapDataProvider::Driver {args} {
103
104    set valids {arcgis colorramp debug gdal ogr tfs tms wcs wfs wms xyz}
105
106    if {[llength $args] > 1} {
107        error "wrong # of arguments: should be ?driver?"
108    }
109
110    if {[llength $args] == 1} {
111
112        set value [lindex $args 0]
113
114        if {[string compare "" $value] == 0} {
115            error "bad value \"$value\": should be a non-empty string"
116        }
117
118        if {[lsearch $valids $value] < 0} {
119            error "bad value \"$value\": should be one of \"$valids\""
120        }
121
122        set _driver $value
123    }
124
125    return $_driver
126}
127
128
129# ----------------------------------------------------------------------
130# Url: get/set url of the layer
131# ----------------------------------------------------------------------
132itcl::body Rappture::GeoMapDataProvider::Url {args} {
133
134    if {[llength $args] > 1} {
135        error "wrong # of arguments: should be ?url?"
136    }
137
138    if {[llength $args] == 1} {
139
140        set value [lindex $args 0]
141
142        if {[string compare "" $value] == 0} {
143            error "bad value \"$value\": should be a non-empty string"
144        }
145
146        # this re is fragile when some urls are missing ending forward slashes:
147        # http://myurl.com vs. http://myurl.com/
148        set re {[^:]+://([^:/]+(:[0-9]+)?)?/.*}
149        if {[regexp $re $value] == 0} {
150            error "bad value \"$value\": should be a valid url or url pattern"
151        }
152
153        set _url $value
154    }
155
156    return $_url
157}
158
159
160# ----------------------------------------------------------------------
161# attribution: get/set the attribution text for the layer
162#
163# Tells the server what copyright text to show for layer.
164# ----------------------------------------------------------------------
165itcl::configbody Rappture::GeoMapDataProvider::attribution {
166    # empty
167}
168
169
170# ----------------------------------------------------------------------
171# cache: get/set the cache flag for the layer
172#
173# Tells the server whether or not to cache images from
174# external sources.
175# ----------------------------------------------------------------------
176itcl::configbody Rappture::GeoMapDataProvider::cache {
177
178    if {[string is bool $cache] == 0} {
179        error "bad value \"$cache\": should be a boolean"
180    }
181}
182
183
184# ----------------------------------------------------------------------
185# type: clients use this public method to query type of this layer
186#
187# ----------------------------------------------------------------------
188itcl::body Rappture::GeoMapDataProvider::type {} {
189    return [Type]
190}
191
192
193# ----------------------------------------------------------------------
194# driver: clients use this public method to query the driver for this layer
195#
196# ----------------------------------------------------------------------
197itcl::body Rappture::GeoMapDataProvider::driver {} {
198    return [Driver]
199}
200
201
202# ----------------------------------------------------------------------
203# url: clients use this public method to query the initial
204#      value of the url or this layer
205#
206# ----------------------------------------------------------------------
207itcl::body Rappture::GeoMapDataProvider::url {} {
208    return [Url]
209}
210
211
212# ----------------------------------------------------------------------
213# ExportToBltTree: export object to a blt::tree
214#
215# ExportToBltTree $tree
216#
217# ----------------------------------------------------------------------
218itcl::body Rappture::GeoMapDataProvider::exportToBltTree {tree} {
219
220    $tree set root \
221        type $_type \
222        driver $_driver \
223        cache $cache \
224        attribution $attribution
225}
226
Note: See TracBrowser for help on using the repository browser.