70
70
< script src ="animator.js "> </ script >
71
71
< script type ="text/javascript ">
72
72
var map , template ;
73
- OpenLayers . ProxyHost = ( window . location . host == "localhost" ) ?
74
- "/cgi-bin/proxy.cgi?url=" : "proxy.cgi?url=" ;
73
+
74
+ /**
75
+ * A specific format for parsing Flickr API JSON responses.
76
+ */
77
+ OpenLayers . Format . Flickr = OpenLayers . Class ( OpenLayers . Format , {
78
+ read : function ( obj ) {
79
+ if ( obj . stat === 'fail' ) {
80
+ throw new Error (
81
+ [ 'Flickr failure response (' ,
82
+ obj . code ,
83
+ '): ' ,
84
+ obj . message ] . join ( '' ) ) ;
85
+ }
86
+ if ( ! obj || ! obj . photos ||
87
+ ! OpenLayers . Util . isArray ( obj . photos . photo ) ) {
88
+ throw new Error (
89
+ 'Unexpected Flickr response' ) ;
90
+ }
91
+ var photos = obj . photos . photo , photo ,
92
+ x , y , point ,
93
+ feature , features = [ ] ;
94
+ for ( var i = 0 , l = photos . length ; i < l ; i ++ ) {
95
+ photo = photos [ i ] ;
96
+ x = photo . longitude ;
97
+ y = photo . latitude ;
98
+ point = new OpenLayers . Geometry . Point ( x , y ) ;
99
+ feature = new OpenLayers . Feature . Vector ( point , {
100
+ title : photo . title ,
101
+ img_url : photo . url_s
102
+ } ) ;
103
+ features . push ( feature ) ;
104
+ }
105
+ return features ;
106
+ }
107
+ } ) ;
75
108
76
109
function init ( ) {
77
- map = new OpenLayers . Map ( 'map' , {
78
- restrictedExtent : new OpenLayers . Bounds ( - 180 , - 90 , 180 , 90 )
79
- } ) ;
80
- var base = new OpenLayers . Layer . WMS ( "Imagery" ,
81
- [ "http://t1.hypercube.telascience.org/tiles?" ,
82
- "http://t2.hypercube.telascience.org/tiles?" ,
83
- "http://t3.hypercube.telascience.org/tiles?" ,
84
- "http://t4.hypercube.telascience.org/tiles?" ] ,
85
- { layers : 'landsat7' }
86
- ) ;
110
+ map = new OpenLayers . Map ( 'map' ) ;
111
+ var base = new OpenLayers . Layer . OSM ( ) ;
87
112
88
113
var style = new OpenLayers . Style ( {
89
114
pointRadius : "${radius}" ,
101
126
} ) ;
102
127
103
128
var photos = new OpenLayers . Layer . Vector ( "Photos" , {
129
+ projection : "EPSG:4326" ,
104
130
strategies : [
105
131
new OpenLayers . Strategy . Fixed ( ) ,
106
132
new OpenLayers . Strategy . Cluster ( )
107
133
] ,
108
- protocol : new OpenLayers . Protocol . HTTP ( {
109
- url : "http://labs.metacarta .com/flickrbrowse/flickr.py/flickr " ,
134
+ protocol : new OpenLayers . Protocol . Script ( {
135
+ url : "http://api.flickr .com/services/rest " ,
110
136
params : {
111
- format : "WFS" ,
112
- sort : "interestingness-desc" ,
113
- service : "WFS" ,
114
- request : "GetFeatures" ,
115
- srs : "EPSG:4326" ,
116
- maxfeatures : 150 ,
137
+ api_key : 'b5e8c0e287e678671c3d8b2c0f3ced85' ,
138
+ format : 'json' ,
139
+ method : 'flickr.photos.search' ,
140
+ extras : 'geo,url_s' ,
141
+ per_page : 150 ,
142
+ page : 1 ,
117
143
bbox : [ - 180 , - 90 , 180 , 90 ]
118
144
} ,
119
- format : new OpenLayers . Format . GML ( )
145
+ callbackKey : 'jsoncallback' ,
146
+ format : new OpenLayers . Format . Flickr ( )
120
147
} ) ,
121
148
styleMap : new OpenLayers . StyleMap ( {
122
149
"default" : style ,
172
199
< body onload ="init() ">
173
200
< h1 id ="title "> Cluster Strategy Example</ h1 >
174
201
< div id ="tags ">
175
- vector, feature, stylemap, wfs, cluster, strategy, cleanup
202
+ vector, feature, stylemap, cluster, strategy, flickr, script
176
203
</ div >
177
204
< p id ="shortdesc ">
178
205
Uses a cluster strategy to render points representing clusters of features.
@@ -181,6 +208,8 @@ <h1 id="title">Cluster Strategy Example</h1>
181
208
< div id ="docs ">
182
209
< p > The Cluster strategy lets you display points representing clusters
183
210
of features within some pixel distance.</ p >
211
+ < p > This particular example uses the < a
212
+ href ="http://www.flickr.com/services/api/ "> Flickr API.</ a > </ p >
184
213
</ div >
185
214
< div id ="photos "> </ div >
186
215
< p > Hover over a cluster on the map to see the photos it includes.</ p >
0 commit comments