Hello all,<br><br>For starters, I would like to put up a number of vector layers (points and polygons) on an OL application. For now there are 2 vector layers in kml format on my server.<br>Here&#39;s the link:<br><a href="http://99.35.104.33/bangalore/bangalore_osm_kml_popup3.html">http://99.35.104.33/bangalore/bangalore_osm_kml_popup3.html</a><br>
And the script is at bottom.<br><br>My qn is: how do i make a generic SelectFeatureEvent and popUp functions (like the one i have below for borewells vector layer) such that one set of functions will apply to any and all layers? As of now. given my very limited javascript experience,  I only know that I could develop one set of functions for every single layer, which seems inefficient.<br>
<br>FYI, each vector layer has different number and attribute titles. Is it possible maybe to refer to an atttribute column number instead of the attribute title?. <br><br>BTW, if there is an informal OL users meetup or support group in the Davis/Sacramento area please let me know. I&#39;m trying to develop something quite interactive and complex (to me, in terms of web programming) and could use some help over time...<br>
<br>Thanks,<br>Vishal<br><br><br><br>&lt;html&gt;<br>    &lt;head&gt;<br>          &lt;title&gt;OpenLayers Example&lt;/title&gt;<br>            &lt;!--script src=&quot;<a href="http://openlayers.org/api/OpenLayers.js">http://openlayers.org/api/OpenLayers.js</a>&quot;&gt;&lt;/script--&gt;<br>
        &lt;script src=&#39;javascript/OpenLayers-2.10/OpenLayers.js&#39;&gt;&lt;/script&gt;<br>        &lt;link rel=&#39;stylesheet&#39; href=&#39;css/trystyle.css&#39; /&gt;<br>    &lt;/head&gt;<br>        &lt;body&gt;<br>
              &lt;div id=&quot;toppage&quot;&gt;<br>            &lt;h1&gt; this is the top page &lt;/h1&gt;<br>              &lt;/div&gt;<br>        &lt;div id=&quot;rightpage&quot;&gt;<br>            &lt;h1&gt; this is the right page &lt;/h1&gt;<br>
            &lt;p&gt;<br>        &lt;form method=&quot;POST&quot; action=&quot;bangalore3.php&quot;&gt;<br>        &lt;input type=&quot;radio&quot; name=&quot;action&quot; value=&quot;All&quot; /&gt; All&lt;br /&gt;<br>        &lt;input type=&quot;radio&quot; name=&quot;action&quot; value=&quot;Average&quot; /&gt; Average<br>
        &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;<br>        &lt;/form&gt;<br>        &lt;/p&gt;<br>        &lt;/div&gt;<br>      &lt;div id=&quot;map&quot;&gt;<br>      &lt;script defer=&quot;defer&quot; type=&quot;text/javascript&quot;&gt;<br>
            // pink tile avoidance<br>            OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;<br>            // make OL compute scale according to WMS spec<br>            OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;<br><br>        var map = new OpenLayers.Map(<br>
    &#39;map&#39;,<br>    {displayProjection: new OpenLayers.Projection(&quot;EPSG:4326&quot;)}<br>        );<br>        <br><br>    var bounds = new OpenLayers.Bounds(<br>        77.541, 12.935,<br>        77.626, 13.000<br>
    ); <br>       <br>    var osm =   new OpenLayers.Layer.OSM( <br>    &quot;Simple OSM Map&quot;)<br>    //console.log(map.getProjection());<br>        map.addLayer(osm);<br>    //console.log(map.getProjection());<br>     map.setCenter(<br>
                new OpenLayers.LonLat(77.6,13).transform(<br>                    new OpenLayers.Projection(&quot;EPSG:4326&quot;),<br>                    map.getProjectionObject()<br>               ), 13);<br>    //console.log(map.getProjection());<br>
    var borewells = new OpenLayers.Layer.Vector(&#39;borewells&#39;,<br>        {<br>            projection: new OpenLayers.Projection(&#39;EPSG:4326&#39;),<br>            protocol: new OpenLayers.Protocol.HTTP({<br>                url: &quot;borewells.kml&quot;,<br>
                format: new OpenLayers.Format.KML({<br>                    extractAttributes: true,<br>                    extractStyles: true<br>                    })<br>            }),<br>            visibility: true,<br>
            strategies: [new OpenLayers.Strategy.Fixed()]<br>            }<br>        );<br>    <br>    var wards = new OpenLayers.Layer.Vector(&#39;wards&#39;,<br>        {<br>            projection: new OpenLayers.Projection(&#39;EPSG:4326&#39;),<br>
            protocol: new OpenLayers.Protocol.HTTP({<br>                url: &quot;Wards27.kml&quot;,<br>                format: new OpenLayers.Format.KML({<br>                    extractAttributes: true,<br>                    extractStyles: true<br>
                    })<br>            }),<br>            visibility: false,<br>            strategies: [new OpenLayers.Strategy.Fixed()]<br>            }<br>        );<br>    //add it to the map<br>    map.addLayers([borewells,wards]);<br>
    // Add a layer switcher control and mouse poistion control<br>    map.addControls(<br>    [new OpenLayers.Control.LayerSwitcher({}),<br>     new OpenLayers.Control.MousePosition({})]<br>    );<br>    //create a variable for the SelectFeature Control<br>
    selectborewells = new OpenLayers.Control.SelectFeature(borewells);<br>    selectwards = new OpenLayers.Control.SelectFeature(wards);//not implemented yet<br>   // 2 functions will be called when select and unselect events are fired<br>
   borewells.events.on({<br>                &quot;featureselected&quot;: onFeatureSelect,<br>                &quot;featureunselected&quot;: onFeatureUnselect<br>            });<br>    //add the control to the map<br>   <br>
   map.addControl(selectborewells);<br>   //activate it<br>   selectborewells.activate();<br>      <br>   //not sure what evt is      <br>      function onPopupClose(evt) {<br>            selectborewells.unselectAll();<br>
        }  <br>   // this function for what happens when selecting a feature<br>   // not sure exactly whats happening<br>           function onFeatureSelect(event) {<br>            var feature = event.feature;<br>            // Since KML is user-generated, do naive protection against<br>
            // Javascript.<br>            //var content = feature.attributes;<br>            var content = &quot;&lt;h3&gt; Water Depth (metres)&lt;/h3&gt;&quot;+feature.attributes.Code_No.value + &quot;&lt;/br&gt;&quot; + feature.attributes.Water_Leve.value.substr(0,4);<br>
            if (content.search(&quot;&lt;script&quot;) != -1) {<br>                content = &quot;Content contained Javascript! Escaped content below.&lt;br /&gt;&quot; + content.replace(/&lt;/g, &quot;&amp;lt;&quot;);<br>
            }<br>            popup = new OpenLayers.Popup.FramedCloud(&quot;chicken&quot;, <br>                                     feature.geometry.getBounds().getCenterLonLat(),<br>                                     new OpenLayers.Size(100,100),<br>
                                     content,<br>                                     null, true, onPopupClose);<br>            feature.popup = popup;<br>            map.addPopup(popup);<br>        }     <br>   // this function for when unselected<br>
          function onFeatureUnselect(event) {<br>            var feature = event.feature;<br>            if(feature.popup) {<br>                map.removePopup(feature.popup);<br>                feature.popup.destroy();<br>
                delete feature.popup;<br>            }<br>        }                    <br><br>      &lt;/script&gt; <br>    &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br><br><br clear="all"><br>-- <br>Vishal K. Mehta, PhD<br>
Scientist<br>Stockholm Environment Institute - US<br>133 D St Suite F<br>Davis CA 95616<br><a href="http://www.sei-us.org">www.sei-us.org</a><br>