[OpenLayers-Dev] using custom renderer on Layer.Vector
christopher.schmidt at nokia.com
christopher.schmidt at nokia.com
Thu Jun 10 06:59:29 EDT 2010
On Jun 10, 2010, at 3:32 AM, ext Bart van den Eijnden wrote:
> Hi list,
>
> I am trying to use a custom renderer for a Vector Layer. However, if I interpret the code correctly, there is an issue there right now. Hopefully somebody can clarify if I am doing something wrong.
Bart:
I would say that this is not the right way to go about it. Instead,
the right thing to do is to pass in a renderers array like so:
Layer.Vector("", {
renderers: [Geozet.Renderer.Anchor]
})
Setting 'renderers' in a Vector layer's option is documented (in the
form of an example) and is the only way I had originally considered
allowing users to control the renderer code; this was to ensure that
by default, OpenLayers would check things like the .supported()
call, etc.
However, the current code requires renderers to be in OpenLayers.Renderer
namespace, so clearly this won't work for you.
While the suggestion you had is not unreasonable, my first suggestion
would be to change the .renderers array to support storing
actual classnames. The reason that we don't do that in *general* is
because we wanted to be able to allow users to exclude renderers,
and not have their OL file break, which would not work with actual
classnames. However, there's no reason we can't check if the passed
in thing is a string or an object, and do the right thing either way.
If you look in the assignRenderer function, you can see that the
renderer is instantiated with a div and rendererOptions.
In reality, there's no reason not to pursue both of these -- however,
if I were mucking about with making things APIProperties, the .renderers
array is the one that I would go for first.
-- Chris
> I am defining my layer in the following way:
>
> vectorLayer = new OpenLayers.Layer.Vector("Bekendmakingen", {
> styleMap: new OpenLayers.StyleMap({'default':{
> cssClass: "${category}"
> }}),
> renderer: new Geozet.Renderer.Anchor(),
> strategies: [new Geozet.Strategy.PrintList()]
> });
>
> However, the constructor of the renderer normally gets the root div as the first argument, but since the vectorLayer has not yet been rendered, I cannot assign it as yet.
>
> If I look in the Vector.js code I see in the initialize function:
>
> OpenLayers.Layer.prototype.initialize.apply(this, arguments);
>
> // allow user-set renderer, otherwise assign one
> if (!this.renderer || !this.renderer.supported()) {
> this.assignRenderer();
> }
>
> So after the prototype initialize has been called, this.div is there, and I need to "assign' it to my custom renderer.
>
> So I would expect:
>
> Renderer to have a setContainer function, and the constructor of the Vector layer to use that function if a user-set renderer has been used.
>
> TIA.
>
> Best regards,
> Bart
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
Regards,
--
Christopher Schmidt
Nokia
More information about the Dev
mailing list