[OpenLayers-Commits] r10896 - in sandbox/sonxurxo/wctravel:
examples lib/OpenLayers/Layer
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Mon Nov 15 03:11:38 EST 2010
Author: sonxurxo
Date: 2010-11-15 00:11:38 -0800 (Mon, 15 Nov 2010)
New Revision: 10896
Modified:
sandbox/sonxurxo/wctravel/examples/wctravel.html
sandbox/sonxurxo/wctravel/lib/OpenLayers/Layer/WCTravel.js
Log:
improved reload of web cams
Modified: sandbox/sonxurxo/wctravel/examples/wctravel.html
===================================================================
--- sandbox/sonxurxo/wctravel/examples/wctravel.html 2010-11-12 14:22:10 UTC (rev 10895)
+++ sandbox/sonxurxo/wctravel/examples/wctravel.html 2010-11-15 08:11:38 UTC (rev 10896)
@@ -10,7 +10,7 @@
var zoom = 8;
var map, layer;
- var devid = "ENTER_A_VALID_webcam.travel_DEV_ID";
+ var devid = "ENTER _A_VALID_webcam.travel_DEV_ID;
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
@@ -20,10 +20,10 @@
"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
map.addLayer(layer);
+ var wcTravel = new OpenLayers.Layer.WCTravel('webcams', devid, {reloadOnMove: true});
+
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
- var wcTravel = new OpenLayers.Layer.WCTravel('webcams', devid);
-
map.addLayer(wcTravel);
map.addControl( new OpenLayers.Control.LayerSwitcher());
Modified: sandbox/sonxurxo/wctravel/lib/OpenLayers/Layer/WCTravel.js
===================================================================
--- sandbox/sonxurxo/wctravel/lib/OpenLayers/Layer/WCTravel.js 2010-11-12 14:22:10 UTC (rev 10895)
+++ sandbox/sonxurxo/wctravel/lib/OpenLayers/Layer/WCTravel.js 2010-11-15 08:11:38 UTC (rev 10896)
@@ -17,9 +17,17 @@
protocol: null,
per_page: 100,
+
+ addClickControl: true,
+
+ center: null,
+
+ reloadOnMove: false,
+
+ radius: null,
initialize: function(name, devid, options) {
- if (options == undefined) { options = {}; }
+ if (options == undefined) { options = {}; }
this.devid = devid;
@@ -36,7 +44,7 @@
var result = response.features;
for (var i = 0; i < result.webcams.count; i++) {
var webcam = result.webcams.webcam[i];
-
+
if (webcam != null) {
var size = new OpenLayers.Size(32, 32);
@@ -53,31 +61,34 @@
this.addMarker(marker);
var wrapper = {webcam : webcam, marker: marker};
-
- marker.events.register("click", wrapper, function() {
- for (var i = 0; i < this.marker.map.popups.length; i++) {
- this.marker.map.removePopup(this.marker.map.popups[i]);
- }
- var imageURL = this.webcam.thumbnail_url.replace("thumbnail", "webcam");
- var popup = new OpenLayers.Popup.FramedCloud(
- "test",
- this.marker.lonlat,
- new OpenLayers.Size(400, 350),
- '<img style="width:320px" src="' + imageURL + '"/>',
- {
- size: new OpenLayers.Size(0, 0),
- offset: new OpenLayers.Pixel(-18, -17)
- },
- true,
- function() {
- popup.destroy();
- }
- );
- popup.minSize = new OpenLayers.Size(400, 350);
- popup.maxSize = new OpenLayers.Size(400, 350);
- popup.autosize = true;
- this.marker.map.addPopup(popup);
- });
+
+ if (this.addClickControl) {
+
+ marker.events.register("click", wrapper, function() {
+ for (var i = 0; i < this.marker.map.popups.length; i++) {
+ this.marker.map.removePopup(this.marker.map.popups[i]);
+ }
+ var imageURL = this.webcam.thumbnail_url.replace("thumbnail", "webcam");
+ var popup = new OpenLayers.Popup.FramedCloud(
+ "test",
+ this.marker.lonlat,
+ new OpenLayers.Size(400, 350),
+ '<img style="width:320px" src="' + imageURL + '"/>',
+ {
+ size: new OpenLayers.Size(0, 0),
+ offset: new OpenLayers.Pixel(-18, -17)
+ },
+ true,
+ function() {
+ popup.destroy();
+ }
+ );
+ popup.minSize = new OpenLayers.Size(400, 350);
+ popup.maxSize = new OpenLayers.Size(400, 350);
+ popup.autosize = true;
+ this.marker.map.addPopup(popup);
+ });
+ }
}
}
},
@@ -108,40 +119,28 @@
OpenLayers.Layer.Markers.prototype.setMap.apply(this, arguments);
- var radius = this.map.getExtent().getWidth() / 2 | 0;
+ if (!this.center) {
+ this.center = map.getCenter();
+ }
- this.protocol = new OpenLayers.Protocol.HTTP({
- url: this.WCTRAVEL_URL,
- params: {
- devid: this.devid,
- method: this.WCTRAVEL_METHOD,
- lat: map.getCenter().lat,
- lng: map.getCenter().lon,
- radius: radius,
- per_page: this.per_page,
- format: 'json'
- },
- format: this.format,
- callback: this.addCams,
- scope: this
- });
+ this.radius = this.map.getExtent().getWidth() / 2 | 0;
+
+ this.drawCams();
- this.protocol.read();
-
- map.events.register("moveend", this, this.reloadCams);
+ if (this.reloadOnMove) {
+ map.events.register("moveend", this, this.reloadCams);
+ }
},
- reloadCams: function(scope) {
- this.clearMarkers();
- var radius = this.map.getExtent().getWidth() / 2 | 0;
+ drawCams: function() {
this.protocol = new OpenLayers.Protocol.HTTP({
url: this.WCTRAVEL_URL,
params: {
devid: this.devid,
method: this.WCTRAVEL_METHOD,
- lat: map.getCenter().lat,
- lng: map.getCenter().lon,
- radius: radius,
+ lat: this.center.lat,
+ lng: this.center.lon,
+ radius: this.radius,
per_page: this.per_page,
format: 'json'
},
@@ -152,6 +151,16 @@
this.protocol.read();
},
+
+ reloadCams: function() {
+ var lastCenter = new OpenLayers.Geometry.Point(this.center.lat, this.center.lon);
+ var newCenter = new OpenLayers.Geometry.Point(this.map.getCenter().lat, this.map.getCenter().lon);
+ if (lastCenter.distanceTo(newCenter) > this.radius / 2) {
+ this.clearMarkers();
+ this.center = this.map.getCenter();
+ this.drawCams();
+ }
+ },
/**
* Method: onMapResize
* Call the onMapResize method of the appropriate parent class.
More information about the Commits
mailing list