Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

At version 2.12 some functionality has been changed and moved to the "deprecated.js" I have the following code which I want to be able to run without "deprecated.js". how can I convert it ?

OpenLayers.Layer.MapInfoRESTHandler = OpenLayers.Class.create();
OpenLayers.Layer.MapInfoRESTHandler.prototype = 
    OpenLayers.Class.inherit( OpenLayers.Layer.Grid, {...

I know OpenLayers.Class() is funtion now , but I'm not sure how to use it in current syntax so it will create the same class as the code above (and same with inherit)

share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

if you want to create a new class which inherits from one class, you can use this structure:

OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
    CLASS_NAME: "OpenLayers.Layer.WMS
    });

writing a class for openlayers you should check out OpenLayers Coding Standards here. it has an example too. beside this you can check out peterrobins Class structure here.

if you want to altering a class method, you can use this structure:

OpenLayers.Control.KeyboardDefaults.prototype.defaultKeyPress = function...

i hope it helps you...

share|improve this answer
    
Thank you Aragon , Question is , In my code example , what do I replace "OpenLayers.Class.create();" with ? because OpenLayers.Class(...) need to get argument , but in the example code I wrote , there isn't any argument. –  Alophind Nov 19 '12 at 20:01
    
if you want to use prototype you can change only one or two methods of your class, but if you want to create new class which is inherited from one class, you have to use first code that i have shared with you. i dont think you need create() method. –  Aragon Nov 19 '12 at 20:34
add comment

It seems that you are trying to create a class that inherits from a parent one. I would do it using the function OpenLayers.Util.extend().

If you want to see examples of the usage of OpenLayers.Util.extend(), you can see the source code of OpenLayers controls, which inherit from OpenLayers.Control.

share|improve this answer
add comment

I believe the example I'm going to provide here is exactly what you asked for, I know it's a late answer but this might help others.

I had the same problem with the pgRouting module in OpenLayers 2.12, in which the starting routing-application code doesn't work with OL 2.12:

var SinglePoint = OpenLayers.Class.create();
SinglePoint.prototype = OpenLayers.Class.inherit(OpenLayers.Handler.Point, {
createFeature: function(evt) { this.control.layer.removeFeatures(this.control.layer.features);
OpenLayers.Handler.Point.prototype.createFeature.apply(this, arguments);
}
});

The changes it needs in order to replace the deprecated component and add functionality with OL 2.12 is as follows:

var SinglePoint = OpenLayers.Class(OpenLayers.Handler.Point);
SinglePoint.prototype = OpenLayers.inherit(SinglePoint, {
createFeature: function(evt) { this.control.layer.removeFeatures(this.control.layer.features);
OpenLayers.Handler.Point.prototype.createFeature.apply(this, arguments);
}
});

It's true that the OpenLayers.Class.create(); is deprecated from OL 2.12 but this is a way to make it work. For more info about deprecated components in OpenLayers 2.12, have a look here: Deprecated components in OL 2.12

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.