allow for custom popup class on a feature. (Closes #947)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@4128 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+3
-3
@@ -85,9 +85,6 @@
|
|||||||
"OpenLayers/Marker/Box.js",
|
"OpenLayers/Marker/Box.js",
|
||||||
"OpenLayers/Popup.js",
|
"OpenLayers/Popup.js",
|
||||||
"OpenLayers/Tile.js",
|
"OpenLayers/Tile.js",
|
||||||
"OpenLayers/Feature.js",
|
|
||||||
"OpenLayers/Feature/Vector.js",
|
|
||||||
"OpenLayers/Feature/WFS.js",
|
|
||||||
"OpenLayers/Tile/Image.js",
|
"OpenLayers/Tile/Image.js",
|
||||||
"OpenLayers/Tile/WFS.js",
|
"OpenLayers/Tile/WFS.js",
|
||||||
"OpenLayers/Layer/Image.js",
|
"OpenLayers/Layer/Image.js",
|
||||||
@@ -113,6 +110,9 @@
|
|||||||
"OpenLayers/Layer/TileCache.js",
|
"OpenLayers/Layer/TileCache.js",
|
||||||
"OpenLayers/Popup/Anchored.js",
|
"OpenLayers/Popup/Anchored.js",
|
||||||
"OpenLayers/Popup/AnchoredBubble.js",
|
"OpenLayers/Popup/AnchoredBubble.js",
|
||||||
|
"OpenLayers/Feature.js",
|
||||||
|
"OpenLayers/Feature/Vector.js",
|
||||||
|
"OpenLayers/Feature/WFS.js",
|
||||||
"OpenLayers/Handler.js",
|
"OpenLayers/Handler.js",
|
||||||
"OpenLayers/Handler/Point.js",
|
"OpenLayers/Handler/Point.js",
|
||||||
"OpenLayers/Handler/Path.js",
|
"OpenLayers/Handler/Path.js",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
/**
|
/**
|
||||||
* @requires OpenLayers/Util.js
|
* @requires OpenLayers/Util.js
|
||||||
* @requires OpenLayers/Marker.js
|
* @requires OpenLayers/Marker.js
|
||||||
|
* @requires OpenLayers/Popup/AnchoredBubble.js
|
||||||
*
|
*
|
||||||
* Class: OpenLayers.Feature
|
* Class: OpenLayers.Feature
|
||||||
* Features are combinations of geography and attributes. The OpenLayers.Feature
|
* Features are combinations of geography and attributes. The OpenLayers.Feature
|
||||||
@@ -43,6 +44,13 @@ OpenLayers.Feature = OpenLayers.Class({
|
|||||||
*/
|
*/
|
||||||
marker: null,
|
marker: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: popupClass
|
||||||
|
* {<OpenLayers.Class>} The class which will be used to instantiate
|
||||||
|
* a new Popup. Default is <OpenLayers.Popup.AnchoredBubble>.
|
||||||
|
*/
|
||||||
|
popupClass: OpenLayers.Popup.AnchoredBubble,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: popup
|
* Property: popup
|
||||||
* {<OpenLayers.Popup>}
|
* {<OpenLayers.Popup>}
|
||||||
@@ -168,11 +176,12 @@ OpenLayers.Feature = OpenLayers.Class({
|
|||||||
var id = this.id + "_popup";
|
var id = this.id + "_popup";
|
||||||
var anchor = (this.marker) ? this.marker.icon : null;
|
var anchor = (this.marker) ? this.marker.icon : null;
|
||||||
|
|
||||||
this.popup = new OpenLayers.Popup.AnchoredBubble(id,
|
this.popup = new this.popupClass(id,
|
||||||
this.lonlat,
|
this.lonlat,
|
||||||
this.data.popupSize,
|
this.data.popupSize,
|
||||||
this.data.popupContentHTML,
|
this.data.popupContentHTML,
|
||||||
anchor, closeBox);
|
anchor,
|
||||||
|
closeBox);
|
||||||
}
|
}
|
||||||
return this.popup;
|
return this.popup;
|
||||||
},
|
},
|
||||||
|
|||||||
+67
-1
@@ -7,7 +7,7 @@
|
|||||||
var feature, layer;
|
var feature, layer;
|
||||||
|
|
||||||
function test_01_Feature_constructor (t) {
|
function test_01_Feature_constructor (t) {
|
||||||
t.plan( 6 );
|
t.plan( 7 );
|
||||||
|
|
||||||
var layer = {};
|
var layer = {};
|
||||||
var lonlat = new OpenLayers.LonLat(2,1);
|
var lonlat = new OpenLayers.LonLat(2,1);
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
t.ok( feature.lonlat.equals(lonlat), "feature.lonlat set correctly" );
|
t.ok( feature.lonlat.equals(lonlat), "feature.lonlat set correctly" );
|
||||||
t.eq( feature.data.iconURL, iconURL, "feature.data.iconURL 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" );
|
t.ok( feature.data.iconSize.equals(iconSize), "feature.data.iconSize set correctly" );
|
||||||
|
t.ok( feature.popupClass == OpenLayers.Popup.AnchoredBubble, "default popupClass is AnchoredBubble");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_02_Feature_createMarker (t) {
|
function test_02_Feature_createMarker (t) {
|
||||||
@@ -103,6 +104,71 @@
|
|||||||
t.ok( !feature2.onScreen(), "feature knows it's offscreen" );
|
t.ok( !feature2.onScreen(), "feature knows it's offscreen" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_04_Feature_createPopup(t) {
|
||||||
|
t.plan(15);
|
||||||
|
|
||||||
|
//no lonlat
|
||||||
|
var f = {
|
||||||
|
'popup': null
|
||||||
|
};
|
||||||
|
|
||||||
|
var ret = OpenLayers.Feature.prototype.createPopup.apply(f, []);
|
||||||
|
t.ok((ret == f.popup) && (f.popup == null), "if no 'lonlat' set on feature, still returns reference to this.popup (though it is null)");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
f.popupClass = OpenLayers.Class({
|
||||||
|
initialize: function(id, lonlat, size, contentHTML, anchor, closeBox) {
|
||||||
|
t.eq(id, "Campion_popup", "correctly generates new popup id from feature's id");
|
||||||
|
t.eq(lonlat, f.lonlat, "correctly passes feature's lonlat to popup constructor");
|
||||||
|
t.eq(size, f.data.popupSize, "correctly passes feature's data.popupSize to popup constructor");
|
||||||
|
t.eq(contentHTML, f.data.popupContentHTML, "correctly passes feature's data.popupContentHTML to popup constructor");
|
||||||
|
t.eq(anchor, g_ExpectedAnchor, "passes correct anchor to popup constructor");
|
||||||
|
t.eq(closeBox, g_CloseBox, "correctly relays closeBox argument to popup constructor");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//valid lonlat but no anchor
|
||||||
|
f.popup = null;
|
||||||
|
|
||||||
|
f.id = "Campion";
|
||||||
|
f.lonlat = {};
|
||||||
|
f.data = {
|
||||||
|
'popupSize': {},
|
||||||
|
'popupContentHTML': {}
|
||||||
|
};
|
||||||
|
g_ExpectedAnchor = null;
|
||||||
|
g_CloseBox = {};
|
||||||
|
|
||||||
|
ret = OpenLayers.Feature.prototype.createPopup.apply(f, [g_CloseBox]);
|
||||||
|
|
||||||
|
t.ok((ret == f.popup) && (f.popup != null), "a valid popup has been set and returned")
|
||||||
|
|
||||||
|
|
||||||
|
//valid lonlat with anchor
|
||||||
|
|
||||||
|
f.marker = {
|
||||||
|
'icon': {}
|
||||||
|
};
|
||||||
|
g_ExpectedAnchor = f.marker.icon;
|
||||||
|
ret = OpenLayers.Feature.prototype.createPopup.apply(f, [g_CloseBox]);
|
||||||
|
t.ok((ret == f.popup) && (f.popup != null), "a valid popup has been set and returned")
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_04_Feature_destroyPopup(t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
var f = {
|
||||||
|
'popup': {
|
||||||
|
'destroy': function() {
|
||||||
|
t.ok(true, "default destroyPopup() calls popup.destroy");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
OpenLayers.Feature.prototype.destroyPopup.apply(f, []);
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user