Skip to content

Commit 74a34ec

Browse files
committed
rely on the Flickr APIs in the strategy-bbox example
1 parent 032293c commit 74a34ec

File tree

1 file changed

+59
-25
lines changed

1 file changed

+59
-25
lines changed

examples/strategy-bbox.html

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,83 @@
1010
<script src="../lib/OpenLayers.js"></script>
1111
<script type="text/javascript">
1212
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+
1649
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();
2753

2854
var style = new OpenLayers.Style({
2955
externalGraphic: "${img_url}",
3056
pointRadius: 30
3157
});
3258

3359
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",
3764
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
4471
},
45-
format: new OpenLayers.Format.GML()
72+
callbackKey: 'jsoncallback',
73+
format: new OpenLayers.Format.Flickr()
4674
}),
4775
styleMap: new OpenLayers.StyleMap(style)
4876
});
4977

5078
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);
5282
}
5383

5484
</script>
5585
</head>
5686
<body onload="init()">
5787
<h1 id="title">BBOX Strategy Example</h1>
5888
<div id="tags">
59-
vector, feature, stylemap, wfs, bbox, strategy, cleanup
89+
vector, feature, stylemap, bbox, strategy, script, flickr
6090
</div>
6191
<p id="shortdesc">
6292
Uses a BBOX strategy to request features within a bounding box.
@@ -67,6 +97,10 @@ <h1 id="title">BBOX Strategy Example</h1>
6797
previously requested data bounds are invalidated (by browsing to
6898
some area not covered by those bounds), another request for data
6999
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+
70104
</div>
71105
</body>
72106
</html>

0 commit comments

Comments
 (0)