[OpenLayers-Commits] r10892 - in sandbox/sonxurxo/wctravel:
examples lib lib/OpenLayers/Layer
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Fri Nov 12 04:37:09 EST 2010
Author: sonxurxo
Date: 2010-11-12 01:37:09 -0800 (Fri, 12 Nov 2010)
New Revision: 10892
Added:
sandbox/sonxurxo/wctravel/lib/OpenLayers/Layer/WCTravel.js
Modified:
sandbox/sonxurxo/wctravel/examples/wctravel.html
sandbox/sonxurxo/wctravel/lib/OpenLayers.js
Log:
Created a WCTravel Layer class, by now map must have a center when added
Modified: sandbox/sonxurxo/wctravel/examples/wctravel.html
===================================================================
--- sandbox/sonxurxo/wctravel/examples/wctravel.html 2010-11-12 08:13:40 UTC (rev 10891)
+++ sandbox/sonxurxo/wctravel/examples/wctravel.html 2010-11-12 09:37:09 UTC (rev 10892)
@@ -12,73 +12,21 @@
var devid = "ENTER_A_VALID_webcam.travel_DEV_ID";
+ OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
+
function init(){
map = new OpenLayers.Map( 'map' );
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
map.addLayer(layer);
-
+
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
- map.addControl( new OpenLayers.Control.LayerSwitcher() );
- var webcamsLayer = new OpenLayers.Layer.Markers('webcams');
- map.addLayer(webcamsLayer);
-
- OpenLayers.Request.issue({
- method: "GET",
- proxy: "/cgi-bin/proxy.cgi?url=",
- url: "http://api.webcams.travel/rest?devid=" + devid + "&method=wct.webcams.list_nearby&lat=43.384965&lng=-8.392181&radius=2&per_page=100&format=json",
- callback: function(response) {
- var JSONReader = new OpenLayers.Format.JSON();
- var result = JSONReader.read(response.responseText);
- 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);
- var offset = new OpenLayers.Pixel(-(size.w / 2) - 3, -size.h);
-
- var icon = new OpenLayers.Icon(
- //"../img/marker-blue.png",
- webcam.icon_url,
- size, offset);
-
- var lonlat = new OpenLayers.LonLat(webcam.longitude, webcam.latitude);
-
- var marker = new OpenLayers.Marker(lonlat, icon);
- webcamsLayer.addMarker(marker);
-
- var wrapper = {webcam : webcam, marker: marker};
-
- marker.events.register("click", wrapper, function() {
- for (var i = 0; i < map.popups.length; i++) {
- map.removePopup(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;
- map.addPopup(popup);
- });
- }
- }
- }
- });
+ var wcTravel = new OpenLayers.Layer.WCTravel('webcams', devid);
+
+ map.addLayer(wcTravel);
+
+ map.addControl( new OpenLayers.Control.LayerSwitcher());
}
</script>
</head>
Added: sandbox/sonxurxo/wctravel/lib/OpenLayers/Layer/WCTravel.js
===================================================================
--- sandbox/sonxurxo/wctravel/lib/OpenLayers/Layer/WCTravel.js (rev 0)
+++ sandbox/sonxurxo/wctravel/lib/OpenLayers/Layer/WCTravel.js 2010-11-12 09:37:09 UTC (rev 10892)
@@ -0,0 +1,172 @@
+OpenLayers.Layer.WCTravel = OpenLayers.Class(OpenLayers.Layer.Markers, {
+
+ WCTRAVEL_METHOD: 'wct.webcams.list_nearby',
+
+ WCTRAVEL_URL: 'http://api.webcams.travel/rest?',
+
+ /**
+ * APIProperty: isBaseLayer
+ * {Boolean} WFS layer is not a base layer by default.
+ */
+ isBaseLayer: false,
+
+ devid: null,
+
+ format: new OpenLayers.Format.JSON(),
+
+ protocol: null,
+
+ per_page: 100,
+
+ initialize: function(name, devid, options) {
+ if (options == undefined) { options = {}; }
+
+ this.devid = devid;
+
+ // Turn off error reporting, browsers like Safari may work
+ // depending on the setup, and we don't want an unneccesary alert.
+ OpenLayers.Util.extend(options, {'reportError': false});
+ var newArguments = [];
+ newArguments.push(name, options);
+
+ OpenLayers.Layer.Markers.prototype.initialize.apply(this, newArguments);
+ },
+
+ addCams: function(response) {
+ 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);
+ var offset = new OpenLayers.Pixel(-(size.w / 2) - 3, -size.h);
+
+ var icon = new OpenLayers.Icon(
+ //"../img/marker-blue.png",
+ webcam.icon_url,
+ size, offset);
+
+ var lonlat = new OpenLayers.LonLat(webcam.longitude, webcam.latitude);
+
+ var marker = new OpenLayers.Marker(lonlat, icon);
+ 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);
+ });
+ }
+ }
+ },
+
+ /**
+ * APIMethod: destroy
+ */
+ destroy: function() {
+ OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments);
+ this.formatObject.destroy();
+ this.format = null;
+ },
+
+ /**
+ * Method: setMap
+ *
+ * Parameters:
+ * map - {<OpenLayers.Map>}
+ */
+ setMap: function(map) {
+
+ var options = {};
+
+ if (this.map && !this.projection.equals(this.map.getProjectionObject())) {
+ options.externalProjection = this.projection;
+ options.internalProjection = this.map.getProjectionObject();
+ }
+
+ OpenLayers.Layer.Markers.prototype.setMap.apply(this, arguments);
+
+ var radius = this.map.getExtent().getWidth() / 2 | 0;
+
+ 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.protocol.read();
+
+ map.events.register("moveend", this, this.reloadCams);
+ },
+
+ reloadCams: function(scope) {
+ this.clearMarkers();
+ var radius = this.map.getExtent().getWidth() / 2 | 0;
+ 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.protocol.read();
+ },
+ /**
+ * Method: onMapResize
+ * Call the onMapResize method of the appropriate parent class.
+ */
+ onMapResize: function() {
+ OpenLayers.Layer.Markers.prototype.onMapResize.apply(this, arguments);
+ },
+
+ /**
+ * Method: display
+ * Call the display method of the appropriate parent class.
+ */
+ display: function() {
+ OpenLayers.Layer.Markers.prototype.display.apply(this, arguments);
+ },
+
+ CLASS_NAME: "OpenLayers.Layer.WCTravel"
+});
Modified: sandbox/sonxurxo/wctravel/lib/OpenLayers.js
===================================================================
--- sandbox/sonxurxo/wctravel/lib/OpenLayers.js 2010-11-12 08:13:40 UTC (rev 10891)
+++ sandbox/sonxurxo/wctravel/lib/OpenLayers.js 2010-11-12 09:37:09 UTC (rev 10892)
@@ -294,6 +294,7 @@
"OpenLayers/Format/WMTSCapabilities.js",
"OpenLayers/Format/WMTSCapabilities/v1_0_0.js",
"OpenLayers/Layer/WFS.js",
+ "OpenLayers/Layer/WCTravel.js",
"OpenLayers/Control/GetFeature.js",
"OpenLayers/Control/MouseToolbar.js",
"OpenLayers/Control/NavToolbar.js",
More information about the Commits
mailing list