Skip to content

Commit 9a9a5ba

Browse files
committed
rely on the Flickr APIs in the strategy-cluster example
1 parent d574f09 commit 9a9a5ba

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

examples/strategy-cluster.html

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,45 @@
7070
<script src="animator.js"></script>
7171
<script type="text/javascript">
7272
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+
});
75108

76109
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();
87112

88113
var style = new OpenLayers.Style({
89114
pointRadius: "${radius}",
@@ -101,22 +126,24 @@
101126
});
102127

103128
var photos = new OpenLayers.Layer.Vector("Photos", {
129+
projection: "EPSG:4326",
104130
strategies: [
105131
new OpenLayers.Strategy.Fixed(),
106132
new OpenLayers.Strategy.Cluster()
107133
],
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",
110136
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,
117143
bbox: [-180, -90, 180, 90]
118144
},
119-
format: new OpenLayers.Format.GML()
145+
callbackKey: 'jsoncallback',
146+
format: new OpenLayers.Format.Flickr()
120147
}),
121148
styleMap: new OpenLayers.StyleMap({
122149
"default": style,
@@ -172,7 +199,7 @@
172199
<body onload="init()">
173200
<h1 id="title">Cluster Strategy Example</h1>
174201
<div id="tags">
175-
vector, feature, stylemap, wfs, cluster, strategy, cleanup
202+
vector, feature, stylemap, cluster, strategy, flickr, script
176203
</div>
177204
<p id="shortdesc">
178205
Uses a cluster strategy to render points representing clusters of features.
@@ -181,6 +208,8 @@ <h1 id="title">Cluster Strategy Example</h1>
181208
<div id="docs">
182209
<p>The Cluster strategy lets you display points representing clusters
183210
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>
184213
</div>
185214
<div id="photos"></div>
186215
<p>Hover over a cluster on the map to see the photos it includes.</p>

0 commit comments

Comments
 (0)