[OpenLayers-Users] Overwriting OL classes
Christopher Schmidt
crschmidt at metacarta.com
Mon Apr 6 11:43:59 EDT 2009
On Mon, Apr 06, 2009 at 08:40:05AM -0700, Gregor at HostGIS wrote:
> Heidt, Christopher M. wrote:
> > Is there a prefered method for overwriting an ol class?
> > I want to use my own custom cluster strategy,
> > so is it as easy as including my own js file after i include ol?
>
> 1) Get your own copy of OL and use that, instead of using the hosted
> copy. Change your app to use it.
>
> 2) Go into the source and hack away.
Generally, I don't recommend this, because when you want to upgrade,
you're screwed.
Things that I do:
* Create subclasses: If you want to override the onClusterFoo method of
cluster, you can do:
MyCluster = OpenLayers.Class(OpenLayers.Strategy.Cluster, {
onClusterFoo: function() {
// do stuff
}
});
* Override methods:
OpenLayers.Strategy.Cluster.prototype.onClusterFoo = function() { }
* Pass in custom functions to options:
var myc = new OpenLayers.Control.Strategy({onClusterFoo: function() { } });
All of these are reasonable ways to make changes without 'breaking' the
existing code. When you upgrade OL, you'll still have to update your
code, but at least you have a nice clean source of 'diffs', practically
speaking, and don't have to deal with SVN's messy merges.
-- Chris
> 3) Go into the ol build/ directory and "python build.py" to merge all of
> the changes and build a compressed copy of OL. Believe me, running OL
> with hundreds of uncompressed files is not fun.
>
> 4) Copy the resulting build/OpenLayers.js into the OL directory,
> overwriting the old one.
>
> --
> HostGIS, Open Source solutions for the global GIS community
> Greg Allensworth - SysAdmin, Programmer, GIS Person, Security
> Network+ Server+ A+ Security+
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
--
Christopher Schmidt
MetaCarta
More information about the Users
mailing list