rely on the Flickr APIs in the strategy-bbox example

This commit is contained in:
Éric Lemoine
2012-03-24 00:13:06 +01:00
parent 032293c26f
commit 74a34ec14b

View File

@@ -10,20 +10,46 @@
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, photos;
OpenLayers.ProxyHost = (window.location.host == "localhost") ?
"/cgi-bin/proxy.cgi?url=" : "proxy.cgi?url=";
/**
* A specific format for parsing Flickr API JSON responses.
*/
OpenLayers.Format.Flickr = OpenLayers.Class(OpenLayers.Format, {
read: function(obj) {
if(obj.stat === 'fail') {
throw new Error(
['Flickr failure response (',
obj.code,
'): ',
obj.message].join(''));
}
if(!obj || !obj.photos ||
!OpenLayers.Util.isArray(obj.photos.photo)) {
throw new Error(
'Unexpected Flickr response');
}
var photos = obj.photos.photo, photo,
x, y, point,
feature, features = [];
for(var i=0,l=photos.length; i<l; i++) {
photo = photos[i];
x = photo.longitude;
y = photo.latitude;
point = new OpenLayers.Geometry.Point(x, y);
feature = new OpenLayers.Feature.Vector(point, {
title: photo.title,
img_url: photo.url_s
});
features.push(feature);
}
return features;
}
});
function init() {
map = new OpenLayers.Map('map', {
restrictedExtent: new OpenLayers.Bounds(-180, -90, 180, 90)
});
var base = new OpenLayers.Layer.WMS("Imagery",
["http://t1.hypercube.telascience.org/tiles?",
"http://t2.hypercube.telascience.org/tiles?",
"http://t3.hypercube.telascience.org/tiles?",
"http://t4.hypercube.telascience.org/tiles?"],
{layers: 'landsat7'}
);
map = new OpenLayers.Map('map');
var base = new OpenLayers.Layer.OSM();
var style = new OpenLayers.Style({
externalGraphic: "${img_url}",
@@ -31,24 +57,28 @@
});
photos = new OpenLayers.Layer.Vector("Photos", {
strategies: [new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.HTTP({
url: "http://labs.metacarta.com/flickrbrowse/flickr.py/flickr",
projection: "EPSG:4326",
strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1})],
protocol: new OpenLayers.Protocol.Script({
url: "http://api.flickr.com/services/rest",
params: {
format: "WFS",
sort: "interestingness-desc",
service: "WFS",
request: "GetFeatures",
srs: "EPSG:4326",
maxfeatures: 10
api_key: 'b5e8c0e287e678671c3d8b2c0f3ced85',
format: 'json',
method: 'flickr.photos.search',
extras: 'geo,url_s',
per_page: 10,
page: 1
},
format: new OpenLayers.Format.GML()
callbackKey: 'jsoncallback',
format: new OpenLayers.Format.Flickr()
}),
styleMap: new OpenLayers.StyleMap(style)
});
map.addLayers([base, photos]);
map.setCenter(new OpenLayers.LonLat(-116.45, 35.42), 5);
map.setCenter(
new OpenLayers.LonLat(-567468.5392481,
4950672.5471436), 5);
}
</script>
@@ -56,7 +86,7 @@
<body onload="init()">
<h1 id="title">BBOX Strategy Example</h1>
<div id="tags">
vector, feature, stylemap, wfs, bbox, strategy, cleanup
vector, feature, stylemap, bbox, strategy, script, flickr
</div>
<p id="shortdesc">
Uses a BBOX strategy to request features within a bounding box.
@@ -67,6 +97,10 @@
previously requested data bounds are invalidated (by browsing to
some area not covered by those bounds), another request for data
is issued.</p>
<p>This particular example uses the <a
href="http://www.flickr.com/services/api/">Flickr API.</a></p>
</div>
</body>
</html>