add layer as first param to base OpenLayers.Feature class. Redo createMarker() and add createPopup(). Redo famous WFS loop so that now it just creates features (according to the feature class passed in) and stores those features in an array. update tests
git-svn-id: http://svn.openlayers.org/trunk/openlayers@407 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -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 += "<div style='margin: 0.25em'>"
|
||||
|
||||
contentHTML += "<div style='height: 1.5em; overflow: hidden'>"
|
||||
contentHTML += "<span style='font-size: 1.2em; font-weight: bold'>"
|
||||
contentHTML += this.data.title;
|
||||
contentHTML += "</span>"
|
||||
contentHTML += "</div>"
|
||||
|
||||
contentHTML += "</div>"
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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"
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user