[OpenLayers-Users] Popup closebox and formatting.

Eric Lemoine Eric.Lemoine at camptocamp.com
Sat Jun 2 09:13:53 EDT 2007


On 5/31/07, kaka <drspencer at hotmail.com> wrote:
>
> I am trying to add a closebox to some markers, but I can´t get the close
> boxes to show up. See http://www.villageografica.com/test50/test.html for a
> test. The markers are located in
> http://www.villageografica.com/test50/ProjectLocations.txt . What am I doing
> wrong here?

Unfortunatly I don' think you can have closeboxes with a Text layer.
Indeed, the Text layer uses feature.createPopup()  as opposed to
feature.createPopup(true). What you can do is create a class that
inherits from OpenLayers.Layer.Text and overrides the markerClick()
method - something along these lines (*untested*) :

EnhancedTextLayer = OpenLayers.Class.create();
EnhancedTextLayer.prototype = OpenLayers.Class.inherit( OpenLayers.Layer.Test, {

 	    /**
 	     * @param {Event} evt
 	     */
 	    markerClick: function(evt) {
 	        sameMarkerClicked = (this == this.layer.selectedFeature);
 	        this.layer.selectedFeature = (!sameMarkerClicked) ? this : null;
 	        for(var i=0; i < this.layer.map.popups.length; i++) {
 	            this.layer.map.removePopup(this.layer.map.popups[i]);
 	        }
 	        if (!sameMarkerClicked) {
 	            this.layer.map.addPopup(this.createPopup(true));
 	        }
 	        OpenLayers.Event.stop(evt);
 	    },

 	    /** @final @type String */
 	    CLASS_NAME: "EnhancedTextLayer"
}

Hope this helps...


-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com


More information about the Users mailing list