[OpenLayers-Dev] my first control

Christopher Schmidt crschmidt at metacarta.com
Tue Feb 24 11:25:02 EST 2009


On Tue, Feb 24, 2009 at 04:54:31PM +0100, toni hernández wrote:
> hi,
> 
> I am trying to create a new control called parallelLine.
> 
> When I activate the control I get this error in Openlayers.js line 276
> 
> this.events has no properties
> [Break on this error]
> this.active=true;this.events.triggerEvent("activate");return
> true;},deactivate:f...
> 
> What am I missing? do I need to create an events variable? Isn't it expanded
> from control class?

You didn't call the parent's 'initialize', so the parent 'control' class
never got initialized.


  OpenLayers.Control.prototype.initialize.apply(this, arguments);

Somewhere in your control.initialize.

> 
> This is part of the code of my control (created based on ModifyFeature).
> 
> OpenLayers.Control.ParallelLine = OpenLayers.Class(OpenLayers.Control, {
> 
>     geometryTypes: null,
>     clickout: true,
>     toggle: true,
>     layer: null,
>     feature: null,
>     selectControl: null,
>     handlers: null,
> 
>     initialize: function(layer, options) {
>         this.layer = layer;
>         var control = this;
> 
>         // configure the select control
>         var selectOptions = {
>             geometryTypes: this.geometryTypes,
>             multiple: false,
>             hover: true,
>             clickout: this.clickout,
>             toggle: this.toggle
>         };
> 
> 
>         this.selectControl = new OpenLayers.Control.SelectFeature(
>             layer, selectOptions
>         );
>         this.layer.events.on({
>             "beforefeatureselected": this.beforeSelectFeature,
>             "featureselected": this.selectFeature,
>             "featureunselected": this.unselectFeature,
>             scope: this
>         });
> 
>         // Regiter the events (sigte)
>         this.layer.events.register("mousemove", this, this.mmove );
>         this.layer.events.register("mousedown", this, this.mdown );
> 
> 
>         // configure the keyboard handler
>         var keyboardOptions = {
>             keydown: this.handleKeypress
>         };
>         this.handlers = {
>             keyboard: new OpenLayers.Handler.Keyboard(this, keyboardOptions)
>         };
> 
>     }
> 
> ....

> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev


-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list