Guys, I'm forwarding this as I think what I'm trying to do is limited by actual OL code.
Basically I'm trying to use an "instance object" as the 'context' for a Style. The idea is to have generic style handlers exposed in the drupal OpenLayers module. The genericity would be obtained by defining classes which take parameters in the constructor and expose methods basing their working on the passed parameters. Example code is in the forwarded message. The actual code I'm using is tested to work in a normal (out of OpenLayers) context, that is I can instanciate the class and access the parameters passed by the constructor trough 'this' from the methods. Problem is, when attaching the instance in the 'context' property of a Style, later call to the methods don't resolve 'this' to the object itself, but to the top of DOM. Can this be due to the Style.clone method ? That method (lib/OpenLayers/Style.js) does: // clone context options.context = this.context && OpenLayers.Util.extend({}, this.context); Would the OpenLayers.Util.extent call change the nature of the context object ? If so, is there anything required on the context class itself to retain the nature ? (the reference to 'this') ? Or, do you have other suggestions for workarounds ? Thanks in advance. --strk; ----- Forwarded message from strk <s...@keybit.net> ----- Date: Mon, 5 Jul 2010 17:41:51 +0200 From: strk <s...@keybit.net> Subject: [OpenLayers-Users] Style context as an object ? To: us...@openlayers.org X-BeenThere: us...@openlayers.org List-Id: OpenLayers User discussion <users.openlayers.org> Did anyone ever tried using a "proper" object as a Style context ? What I'm trying to do is create a class of style contexts and pass instances of them (for parametrized styles) as a Style.context, but 'this', within the callbacks, seem to always evaluate to the top of DOM. Example code: MyContextClass = function(radius) { this.radius = radius; }; MyContextClass.prototype.getRadius() { alert(this.radius); }; myContext = new MyContextClass(4); myStyle = OpenLayers.Style( { pointRadius: '${getRadius)' }, { context: myContext } ); --strk; () Free GIS & Flash consultant/developer /\ http://strk.keybit.net/services.html _______________________________________________ Users mailing list us...@openlayers.org http://openlayers.org/mailman/listinfo/users ----- End forwarded message ----- _______________________________________________ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev