Use OpenLayers-style classes

Coordinator
Dec 16, 2011 at 2:57 PM

I think it would help new (and existing) developers if we add a wrapper or business objects for the ocx that will have more OO-style classes.

I've been working with the OpenLayers classes lately and they look very logic.
No need for us to re-invent the wheel, let's investigate if we can use their class definitions.

Here's some code used by OpenLayers:

 

  var map;
  function init()
  {
    // Create new map object:
    map = new OpenLayers.Map("map", {});
    
    // Add OSM WMS layer as base layer:
    var baselayer = new OpenLayers.Layer.WMS(
      "OpenLayers WMS",
      "http://vmap0.tiles.osgeo.org/wms/vmap0",
      {layers: "basic"}
    );

    // Create new vector layer:
    var vectorLayer = new OpenLayers.Layer.Vector("Overlay");
    
    // Create new points features:
    var point1 = new OpenLayers.Feature.Vector(
      new OpenLayers.Geometry.Point(-47.81, 20.74)
    );
    var point2 = new OpenLayers.Feature.Vector(
      new OpenLayers.Geometry.Point(16.87, 38.32)
    );
    var point3 = new OpenLayers.Feature.Vector(
      new OpenLayers.Geometry.Point(64.68, -3.16)
    );
    var point4 = new OpenLayers.Feature.Vector(
      new OpenLayers.Geometry.Point(-15.46, -31.28)
    );
    
    // Create new linestring geometry:
    var lineString = new OpenLayers.Geometry.LineString(
      [
          new OpenLayers.Geometry.Point(-47.81, 20.74),
          new OpenLayers.Geometry.Point(16.87, 38.32),
          new OpenLayers.Geometry.Point(64.68, -3.16),
          new OpenLayers.Geometry.Point(-15.46, -31.28)
      ]
    ); 
    
    // Use linestring geometry to create new line feature:
    var line = new OpenLayers.Feature.Vector(lineString);
       
    // Create linearring geometry:
    var linearRing = new OpenLayers.Geometry.LinearRing(
      [
          new OpenLayers.Geometry.Point(-47.81, 20.74),
          new OpenLayers.Geometry.Point(16.87, 38.32),
          new OpenLayers.Geometry.Point(64.68, -3.16),
          new OpenLayers.Geometry.Point(-15.46, -31.28)        
      ]
    );
    
    // Use linearring geometry to create new polygon feature:
    var polygon = new OpenLayers.Feature.Vector(
      new OpenLayers.Geometry.Polygon([linearRing]) 
    );
    
    // Add new features to layer:
    vectorLayer.addFeatures([point1, point2, point3, point4, line, polygon]); 
       
    // Add layers to the map:
    map.addLayers([baselayer, vectorLayer]);
    
    // Center the map around this point:
    map.setCenter(new OpenLayers.LonLat(0, 0), 2);
  }

 

The top class OpenLayers needs to be replaced by MapWindow, making this syntax:

    // Create new vector layer:
    var vectorLayer = new MapWindow.Layer.Vector("Overlay");