10
10
< script src ="../lib/OpenLayers.js "> </ script >
11
11
< script type ="text/javascript ">
12
12
var map , photos ;
13
- OpenLayers . ProxyHost = ( window . location . host == "localhost" ) ?
14
- "/cgi-bin/proxy.cgi?url=" : "proxy.cgi?url=" ;
15
-
13
+
14
+ /**
15
+ * A specific format for parsing Flickr API JSON responses.
16
+ */
17
+ OpenLayers . Format . Flickr = OpenLayers . Class ( OpenLayers . Format , {
18
+ read : function ( obj ) {
19
+ if ( obj . stat === 'fail' ) {
20
+ throw new Error (
21
+ [ 'Flickr failure response (' ,
22
+ obj . code ,
23
+ '): ' ,
24
+ obj . message ] . join ( '' ) ) ;
25
+ }
26
+ if ( ! obj || ! obj . photos ||
27
+ ! OpenLayers . Util . isArray ( obj . photos . photo ) ) {
28
+ throw new Error (
29
+ 'Unexpected Flickr response' ) ;
30
+ }
31
+ var photos = obj . photos . photo , photo ,
32
+ x , y , point ,
33
+ feature , features = [ ] ;
34
+ for ( var i = 0 , l = photos . length ; i < l ; i ++ ) {
35
+ photo = photos [ i ] ;
36
+ x = photo . longitude ;
37
+ y = photo . latitude ;
38
+ point = new OpenLayers . Geometry . Point ( x , y ) ;
39
+ feature = new OpenLayers . Feature . Vector ( point , {
40
+ title : photo . title ,
41
+ img_url : photo . url_s
42
+ } ) ;
43
+ features . push ( feature ) ;
44
+ }
45
+ return features ;
46
+ }
47
+ } ) ;
48
+
16
49
function init ( ) {
17
- map = new OpenLayers . Map ( 'map' , {
18
- restrictedExtent : new OpenLayers . Bounds ( - 180 , - 90 , 180 , 90 )
19
- } ) ;
20
- var base = new OpenLayers . Layer . WMS ( "Imagery" ,
21
- [ "http://t1.hypercube.telascience.org/tiles?" ,
22
- "http://t2.hypercube.telascience.org/tiles?" ,
23
- "http://t3.hypercube.telascience.org/tiles?" ,
24
- "http://t4.hypercube.telascience.org/tiles?" ] ,
25
- { layers : 'landsat7' }
26
- ) ;
50
+ map = new OpenLayers . Map ( 'map' ) ;
51
+
52
+ var base = new OpenLayers . Layer . OSM ( ) ;
27
53
28
54
var style = new OpenLayers . Style ( {
29
55
externalGraphic : "${img_url}" ,
30
56
pointRadius : 30
31
57
} ) ;
32
58
33
59
photos = new OpenLayers . Layer . Vector ( "Photos" , {
34
- strategies : [ new OpenLayers . Strategy . BBOX ( ) ] ,
35
- protocol : new OpenLayers . Protocol . HTTP ( {
36
- url : "http://labs.metacarta.com/flickrbrowse/flickr.py/flickr" ,
60
+ projection : "EPSG:4326" ,
61
+ strategies : [ new OpenLayers . Strategy . BBOX ( { resFactor : 1 } ) ] ,
62
+ protocol : new OpenLayers . Protocol . Script ( {
63
+ url : "http://api.flickr.com/services/rest" ,
37
64
params : {
38
- format : "WFS" ,
39
- sort : "interestingness-desc" ,
40
- service : "WFS" ,
41
- request : "GetFeatures" ,
42
- srs : "EPSG:4326" ,
43
- maxfeatures : 10
65
+ api_key : 'b5e8c0e287e678671c3d8b2c0f3ced85' ,
66
+ format : 'json' ,
67
+ method : 'flickr.photos.search' ,
68
+ extras : 'geo,url_s' ,
69
+ per_page : 10 ,
70
+ page : 1
44
71
} ,
45
- format : new OpenLayers . Format . GML ( )
72
+ callbackKey : 'jsoncallback' ,
73
+ format : new OpenLayers . Format . Flickr ( )
46
74
} ) ,
47
75
styleMap : new OpenLayers . StyleMap ( style )
48
76
} ) ;
49
77
50
78
map . addLayers ( [ base , photos ] ) ;
51
- map . setCenter ( new OpenLayers . LonLat ( - 116.45 , 35.42 ) , 5 ) ;
79
+ map . setCenter (
80
+ new OpenLayers . LonLat ( - 567468.5392481 ,
81
+ 4950672.5471436 ) , 5 ) ;
52
82
}
53
83
54
84
</ script >
55
85
</ head >
56
86
< body onload ="init() ">
57
87
< h1 id ="title "> BBOX Strategy Example</ h1 >
58
88
< div id ="tags ">
59
- vector, feature, stylemap, wfs, bbox, strategy, cleanup
89
+ vector, feature, stylemap, bbox, strategy, script, flickr
60
90
</ div >
61
91
< p id ="shortdesc ">
62
92
Uses a BBOX strategy to request features within a bounding box.
@@ -67,6 +97,10 @@ <h1 id="title">BBOX Strategy Example</h1>
67
97
previously requested data bounds are invalidated (by browsing to
68
98
some area not covered by those bounds), another request for data
69
99
is issued.</ p >
100
+
101
+ < p > This particular example uses the < a
102
+ href ="http://www.flickr.com/services/api/ "> Flickr API.</ a > </ p >
103
+
70
104
</ div >
71
105
</ body >
72
106
</ html >
0 commit comments