Talk:OpenLayers Class Diagrams

From OpenStreetMap Wiki
Jump to navigation Jump to search

Graphics were produced with mediawiki-graphviz-extension. Unfortunately this is not installed in this wiki.

To create a wiki-Page with graphviz I used the following html-page in Chrome. It creates the wiki-page in an textarea.

<html>
  <head>
    <title>OpenLayers Example</title>
    <script src="http://openlayers.org/api/OpenLayers.js"></script>
    <script type="text/javascript">

    function printOpenLayersHierarchy() {
      var classes = {};
      appendClass(OpenLayers,classes,5);
      var partitions = split2Partitions(classes);
      for (var v in partitions) {
        if (partitions[v] && partitions[v].length>1) {
          print(partitions[v],classes,v);
        }
      }
    }
    
    function split2Partitions(classes) {
      var result = {};
      for (cn in classes) {
        var baseClass = getBaseClass(cn,classes);
        if (baseClass) {
          if (!result[baseClass]) {
            result[baseClass]=[];
          }
          result[baseClass].push(cn);
        }   
      }
      return result;
    }
    
    function getBaseClass(cn,classes) {
      var result = cn;
      while (classes[result]) {
        result = classes[result];
      }
      return result;
    }
    
    function print(sorted,classes,name) {
      var s = "=" + name + "=\n"+
              "<graphviz>\n"+
              "DIGRAPH " + name.replace(/\./g, "_") + "{\n" +
              'rankdir="RL";\n'+
              "node[shape=rectangle]\n";
      sorted.sort();      
      for (var i=0; i < sorted.length; i++) {
        var cn = sorted[i];
        var superClass = classes[cn];
        s += "\""+cn+"\"";
        if (superClass) {
          s += "->" +  "\""+superClass+"\"";
        }
        s += "\n";
      }
      s +="}\n";
      s +="</graphviz>";
      document.getElementById("aTextArea").value= document.getElementById("aTextArea").value + "\n" + s;
    }
    function appendClass(aClass,classes,searchDepth) {
      if (searchDepth>0) {
        for (var v in aClass) {
          var aClass2 = aClass[v];
          if (aClass2 ) {
            appendClass(aClass2,classes,searchDepth-1);
          }
        }
      }
      if (aClass.prototype && aClass.prototype.CLASS_NAME) {
        var className  = aClass.prototype.CLASS_NAME;
        if (!classes[className]) {
          var superclass = null;
          if (aClass.prototype && aClass.prototype.__proto__ && aClass.prototype.__proto__.CLASS_NAME) {
            superclass = aClass.prototype.__proto__.CLASS_NAME;
          }
          classes[className] = superclass;
        }
      }
    }
    </script>
  </head>
  <body onload="printOpenLayersHierarchy()">
    <form name="aForm">
      <textarea name="aTextArea" id="aTextArea"  style="width:100%; height:100%" > </textarea>
    </form>
  </body>
</html>

User:Benedikt 20:46, 15 September 2012‎


Belongs on an OpenLayers website

This seems quite in-depth into the workings of OpenLayers, so would normally expect to be found on the OpenLayers website(s) rather than on this OpenStreetMap wiki. Not that it's doing any harm here, I just think we could find a better home for it.

I see there's already some class diagrams here on osgeo trac

Nowadays there's a git repo ver OL v3, also with a wiki attached. These diagrams must be from an earlier version though

-- Harry Wood (talk) 16:36, 11 March 2015 (UTC)