Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Write applyTemplate to use in example feature-popups-plus.html

  • Loading branch information...
commit ca9f7a3844d7160af9f3f73378a9cb6d695c3f3f 1 parent 0934ea5
Xavier Mamano authored December 23, 2012
6  examples/feature-popups-plus.js
@@ -34,7 +34,7 @@ var fpControl = new OpenLayers.Control.FeaturePopups({
34 34
                         layerObj0 = layerObj;
35 35
                         count++;
36 36
                         htmlAux.push(
37  
-                            layerObj.renderTemplate(layerObj.templates.item, feature0)
  37
+                            layerObj.applyTemplate.item(feature0)
38 38
                         );
39 39
                     }
40 40
                 }
@@ -52,7 +52,7 @@ var fpControl = new OpenLayers.Control.FeaturePopups({
52 52
                         layer: layerObj.layer,
53 53
                         feature: feature0
54 54
                     }, 
55  
-                    feature0.geometry.getBounds().getCenterLonLat(), 
  55
+                    feature0.geometry.getBounds().getCenterLonLat(),
56 56
                     layerObj0.getSingleHtml(feature0).html, 
57 57
                     true
58 58
                 );
@@ -73,7 +73,7 @@ var fpControl = new OpenLayers.Control.FeaturePopups({
73 73
                 if (true) {
74 74
                     htmlAux.push(
75 75
                         "<hr>" + 
76  
-                        layerObj.renderTemplate(layerObj.templates.hoverItem, sel.features[ii])
  76
+                        layerObj.applyTemplate.hoverItem(sel.features[ii])
77 77
                     );
78 78
                 }
79 79
             }
54  lib/FeaturePopups.js
@@ -681,8 +681,8 @@ OpenLayers.Control.FeaturePopups = OpenLayers.Class(OpenLayers.Control, {
681 681
      * eventListeners - {Object} This object will be registered with
682 682
      *     <OpenLayers.Events.on>, default scope is the control.
683 683
      *
684  
-     * *NOTE*: If the features of the layer may have an *"fid" duplicate* the key
685  
-     *     "fid" of "featureContext" *should be declared*, e.g. as
  684
+     * *NOTE*: If the features of the layer may have an *"fid" duplicate* the
  685
+     *     key "fid" of "featureContext" *should be declared*, e.g. as
686 686
      * (code)
687 687
      * ... },
688 688
      * featureContext: {
@@ -1782,12 +1782,12 @@ OpenLayers.Control.FeaturePopups.Layer = OpenLayers.Class({
1782 1782
 
1783 1783
         // Templates
1784 1784
         var oTemplates = options.templates || {};
1785  
-        var templates = {};
  1785
+        var _templates = {};
1786 1786
         for (var templateName in oTemplates) {
1787  
-            templates[templateName] =
  1787
+            _templates[templateName] =
1788 1788
                                  this.prepareTemplate(oTemplates[templateName]);
1789 1789
         }
1790  
-        this.templates = templates;
  1790
+        this.templates = _templates;
1791 1791
 
1792 1792
         // Events
1793 1793
         this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
@@ -1818,8 +1818,11 @@ OpenLayers.Control.FeaturePopups.Layer = OpenLayers.Class({
1818 1818
             this.layerListeners['featuresremoved'] = this.onFeaturesremoved;
1819 1819
         }
1820 1820
 
  1821
+        // Contexts as a private vars
  1822
+        var _featureContext = this.featureContext || {},
  1823
+            _listContext = this.listContext || {};
1821 1824
         // fid by feature context
1822  
-        var getFid = this.featureContext && this.featureContext.fid;
  1825
+        var getFid = _featureContext.fid;
1823 1826
         if (getFid) {
1824 1827
             this.getFeatureId = getFid;
1825 1828
         } else {
@@ -1837,9 +1840,10 @@ OpenLayers.Control.FeaturePopups.Layer = OpenLayers.Class({
1837 1840
             this.getFeatureId = function(feature) {
1838 1841
                 return feature.fid || feature.id;
1839 1842
             }
1840  
-            this.featureContext = OpenLayers.Util.extend(
1841  
-                                 this.featureContext, {fid: this.getFeatureId});
  1843
+            _featureContext.fid = this.getFeatureId;
1842 1844
         }
  1845
+        this.featureContext = _featureContext;
  1846
+        this.listContext = _listContext;
1843 1847
 
1844 1848
         // Renderer of templates
1845 1849
         // ---------------
@@ -1908,6 +1912,40 @@ OpenLayers.Control.FeaturePopups.Layer = OpenLayers.Class({
1908 1912
                 return '';
1909 1913
             }
1910 1914
         };
  1915
+
  1916
+        /**
  1917
+         * APIProperty: applyTemplate
  1918
+         * The object contains an applicator of the template for each template
  1919
+         *    name. Each applicator returns a {String} with tokens replaced from
  1920
+         *    the context of feature (for names single, item, hover, hoverItem)
  1921
+         *    or context of list (for names list and hoverList)
  1922
+         */
  1923
+        this.applyTemplate = {
  1924
+            single: function(feature) {
  1925
+                return renderTemplate(
  1926
+                                   _templates.single, feature, _featureContext);
  1927
+            },
  1928
+            item: function(feature) {
  1929
+                return renderTemplate(
  1930
+                                     _templates.item, feature, _featureContext);
  1931
+            },
  1932
+            hover: function(feature) {
  1933
+                return renderTemplate(
  1934
+                                    _templates.hover, feature, _featureContext);
  1935
+            },
  1936
+            hoverItem: function(feature) {
  1937
+                return renderTemplate(
  1938
+                                _templates.hoverItem, feature, _featureContext);
  1939
+            },
  1940
+            list: function(listObj) {
  1941
+                return renderTemplate(_templates.list, listObj, _listContext);
  1942
+            },
  1943
+            hoverList: function(listObj) {
  1944
+                return renderTemplate(
  1945
+                                   _templates.hoverList, listObj, _listContext);
  1946
+            }
  1947
+        };
  1948
+
1911 1949
         // published as public function
1912 1950
         this.renderTemplate = renderTemplate;
1913 1951
     },

0 notes on commit ca9f7a3

Please sign in to comment.
Something went wrong with that request. Please try again.