Hi,
I need it to perform automated tests using Selenium which can interact with any
HTML element based on the id.
I did more investigation and I think this is a bug:
The original code was (OpenLayers/layers.js):
/**
* Constructor: OpenLayers.Layer
*
* Parameters:
* name - {String} The layer name
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, options) {
this.addOptions(options);
this.name = name;
if (this.id == null) {
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
this.div = OpenLayers.Util.createDiv(this.id);
this.div.style.width = "100%";
this.div.style.height = "100%";
this.div.dir = "ltr";
this.events = new OpenLayers.Events(this, this.div,
this.EVENT_TYPES);
if(this.eventListeners instanceof Object) {
this.events.on(this.eventListeners);
}
}
So, the condition this.id == null prevent the creation of the events object and
the div itself. I've changed it for:
if (this.id == null) {
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
}
this.div = OpenLayers.Util.createDiv(this.id);
this.div.style.width = "100%";
this.div.style.height = "100%";
this.div.dir = "ltr";
this.events = new OpenLayers.Events(this, this.div,
this.EVENT_TYPES);
if(this.eventListeners instanceof Object) {
this.events.on(this.eventListeners);
}
And it is working now.
Also, a very similar problem occur when you add a control to a panel
(OpenLayers/Control/Panel.js):
addControls: function(controls) {
if (!(controls instanceof Array)) {
controls = [controls];
}
this.controls = this.controls.concat(controls);
// Give each control a panel_div which will be used later.
// Access to this div is via the panel_div attribute of the
// control added to the panel.
// Also, stop mousedowns and clicks, but don't stop mouseup,
// since they need to pass through.
for (var i=0, len=controls.length; i<len; i++) {
var element = document.createElement("div");
controls[i].panel_div = element;
if (controls[i].title != "") {
controls[i].panel_div.title = controls[i].title;
}
OpenLayers.Event.observe(controls[i].panel_div, "click",
OpenLayers.Function.bind(this.onClick, this, controls[i]));
OpenLayers.Event.observe(controls[i].panel_div, "dblclick",
OpenLayers.Function.bind(this.onDoubleClick, this,
controls[i]));
OpenLayers.Event.observe(controls[i].panel_div, "mousedown",
OpenLayers.Function.bindAsEventListener(OpenLayers.Event.stop));
}
if (this.map) { // map.addControl() has already been called on the panel
this.addControlsToMap(controls);
this.redraw();
}
},
The title is set but not the id. I would expect to see:
if (controls[i].id != "") {
controls[i].panel_div.id = controls[i].id;
}
near:
if (controls[i].title != "") {
controls[i].panel_div.title = controls[i].title;
}
Cheers,
Mathieu
-----Original Message-----
From: Eric Lemoine [mailto:[email protected]]
Sent: Saturday, January 15, 2011 12:35 PM
To: Mathieu Lavoie
Cc: [email protected]
Subject: Re: [OpenLayers-Users] Setting layer id for a WMS layer causes an error
On Fri, Jan 14, 2011 at 8:45 PM, Mathieu Lavoie
<[email protected]> wrote:
> If I set the id property for a WMS layer, I get the following error:
>
> Error: this.events is null
> Source File:
> http://localhost:8080/map-service/openLayers/lib/OpenLayers/Layer/Grid.js
> Line: 83
>
> masterMap = new OpenLayers.Layer.WMS("MasterMap",
> "Whatever URL", {
> width : 500,
> srs : projection,
> layers : baseLayer,
> height : 500,
> styles : '',
> format : format
> }, {id: 'test',
> singleTile : true,
> ratio : 1,
> isBaseLayer: true
> });
>
>
> any thoughts?
This may be a bug in the library. Passing an id to a layer constructor
isn't common, why do you need it?
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : [email protected]
http://www.camptocamp.com
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users