diff --git a/lib/OpenLayers/Feature.js b/lib/OpenLayers/Feature.js
index bdf567f7ff..e891899d29 100644
--- a/lib/OpenLayers/Feature.js
+++ b/lib/OpenLayers/Feature.js
@@ -6,7 +6,10 @@ OpenLayers.Feature.prototype= {
/** @type OpenLayers.Events */
events:null,
-
+
+ /** @type OpenLayers.Layer */
+ layer: null,
+
/** @type String */
id: null,
@@ -16,59 +19,79 @@ OpenLayers.Feature.prototype= {
/** @type Object */
data:null,
+ /** @type OpenLayers.Icon */
+ icon: null,
+
+ /** @type OpenLayers.Marker */
+ marker: null,
+
+ /** @type OpenLayers.Popup */
+ popup: null,
+
/**
* @constructor
*
+ * @param {OpenLayers.Layer} layer
* @param {String} id
* @param {OpenLayers.LonLat} lonlat
* @param {Object} data
*/
- initialize: function(id, lonlat, data) {
+ initialize: function(layer, id, lonlat, data) {
+ this.layer = layer;
this.id = id;
this.lonlat = lonlat;
this.data = data;
},
+ /**
+ *
+ */
destroy: function() {
+ this.layer = null;
},
- createMarker: function(layer) {
- if (this.lonlat && this.data.iconURL
- && this.data.iconW
- && this.data.iconH) {
- var size = new OpenLayers.Size(this.data.iconW, this.data.iconH);
- var icon = new OpenLayers.Icon(this.data.iconURL, size);
- var marker = new OpenLayers.Marker(this.lonlat,icon);
- if (this.title) {
- var popup = new OpenLayers.Popup(this.latlon,
- this.getContentHTML());
- marker.events.register('click', this, popup.open());
- }
- this.marker = marker;
- layer.addMarker(marker);
+ /**
+ *
+ */
+ createMarker: function() {
+
+ var imgLocation = OpenLayers.Util.getImagesLocation();
+
+ if (this.lonlat != null) {
+
+ var imgURL = (this.data.iconURL) ? this.data.iconURL
+ : imgLocation + "marker.png";
+
+ var imgSize = (this.data.iconSize) ? this.data.iconSize
+ : new OpenLayers.Size(25, 25);
+
+ this.icon = new OpenLayers.Icon(imgURL, imgSize);
+
+ this.marker = new OpenLayers.Marker(this.lonlat,
+ this.icon);
}
},
-
- /** html content based on feature information
- *
- * ret(str):
- */
- getContentHTML:function() {
-
- var contentHTML = "";
-
- contentHTML += "
"
-
- contentHTML += "
"
- contentHTML += ""
- contentHTML += this.data.title;
- contentHTML += ""
- contentHTML += "
"
- contentHTML += "
"
+ /**
+ *
+ */
+ createPopup: function() {
- return contentHTML;
+ if (this.lonlat != null) {
+
+ if (this.marker) {
+ var anchorSize = this.marker.icon.size;
+ }
+
+ this.popup =
+ new OpenLayers.Popup.AnchoredBubble(this.id + "_popup",
+ this.lonlat,
+ this.data.popupSize,
+ this.data.popupContentHTML,
+ anchorSize);
+ }
+
},
CLASS_NAME: "OpenLayers.Feature"
diff --git a/lib/OpenLayers/Tile/WFS.js b/lib/OpenLayers/Tile/WFS.js
index e8cbffbdac..c44fa45ea9 100644
--- a/lib/OpenLayers/Tile/WFS.js
+++ b/lib/OpenLayers/Tile/WFS.js
@@ -9,8 +9,8 @@ OpenLayers.Tile.WFS.prototype =
/** @type Array of Function */
handlers: null,
- /** @type Array of */
- markers: null,
+ /** @type Array(OpenLayers.Feature)*/
+ features: null,
/**
@@ -25,7 +25,7 @@ OpenLayers.Tile.WFS.prototype =
initialize: function(layer, position, bounds, url, size) {
OpenLayers.Tile.prototype.initialize.apply(this, arguments);
- this.markers = new Array();
+ this.features = new Array();
this.handlers = new Array();
this.handlers["requestSuccess"] = this.requestSuccess;
@@ -83,20 +83,13 @@ OpenLayers.Tile.WFS.prototype =
for (var i=0; i < resultFeatures.length; i++) {
- var feature = new this.layer.featureClass(resultFeatures[i]);
- var icon = new OpenLayers.Icon(feature.markerImage, feature.size);
- var marker = new OpenLayers.Marker(feature.lonlat, icon, feature);
-
- //add to local collection
- this.markers.append(marker);
-
- //add to layer
- this.layer.addMarker(marker);
- }
+ var feature = new this.layer.featureClass(this.layer,
+ resultFeatures[i]);
+ this.features.append(feature);
+ }
},
-
/** @final @type String */
CLASS_NAME: "OpenLayers.Tile.WFS"
}
diff --git a/tests/test_Feature.html b/tests/test_Feature.html
index aaa01cbd8d..f4f0ee8c84 100644
--- a/tests/test_Feature.html
+++ b/tests/test_Feature.html
@@ -7,20 +7,25 @@
var feature, layer;
function test_01_Feature_constructor (t) {
- t.plan( 5 );
+ t.plan( 6 );
+
+ var layer = new Object();
+ var id = "myfeature";
+ var lonlat = new OpenLayers.LonLat(2,1);
+ var iconURL = 'http://boston.openguides.org/features/ORANGE.png';
+ var iconSize = new OpenLayers.Size(12, 17);
+ var data = { iconURL: iconURL,
+ iconSize: iconSize
+ };
+
+ feature = new OpenLayers.Feature(layer, id, lonlat, data);
- feature = new OpenLayers.Feature("myfeature",
- new OpenLayers.LonLat(2,1),
- {
- iconURL:'http://boston.openguides.org/features/ORANGE.png',
- iconW: 12,
- iconH: 17
- });
t.ok( feature instanceof OpenLayers.Feature, "new OpenLayers.Feature returns Feature object" );
- t.ok( feature.lonlat instanceof OpenLayers.LonLat, "new feature.lonlat returns LonLat object" );
- t.eq( feature.lonlat.lon, 2, "feature.lonlat.lon returns correct lon" );
- t.eq( feature.lonlat.lat, 1, "feature.lonlat.lat returns correct lat" );
- t.eq( feature.data.iconW, 12, "feature.data.iconW set correctly" );
+ t.eq( feature.layer, layer, "feature.layer set correctly" );
+ t.eq( feature.id, id, "feature.id set correctly" );
+ t.ok( feature.lonlat.equals(lonlat), "feature.lonlat set correctly" );
+ t.eq( feature.data.iconURL, iconURL, "feature.data.iconURL set correctly" );
+ t.ok( feature.data.iconSize.equals(iconSize), "feature.data.iconSize set correctly" );
}
function test_02_Feature_createMarker (t) {