[Geoprisma-dev] Layer loading problem

Yves Moisan yves.moisan at boreal-is.com
Fri Dec 4 13:47:40 EST 2009


Hi All,

This is an Openlayers question.  I'm customizing the initialview to
highlight the zoomed to feature(s) and I find that in some cases the
layer is not fully loaded before the select is done.  In the code below,
things work if I leave the alert (the layer is given time to load) but
if I take it out the case with 1 feature works but not when there are
many :

 var oFormat = new OpenLayers.Format.GeoJSON();
     var oFeatures = oFormat.read(response.responseText);
     var layers = objGPWidget]]><xsl:value-of select="$pMapName" /><![CDATA[.getLayersByResource("]]><xsl:value-of select="$resourceName" /><![CDATA[","featureserver");

      // Next line used to check if there is a featureserver layer; for initialview, this is required so no need to alert
      // (!layers[0]) ? alert("no FS layer"): alert("FS layer = " + layers[0].name);

      ]]><xsl:if test="./options/highlight = 'true'"><![CDATA[
         // alert("Highlight on")

         function selectFeature(layer, fid)
                    { 
                            for(var i = 0; i<layer.features.length;++i)
                                  {         
                                        if (layer.features[i].fid == fid)
                                        {         
                                            FeatureSelectControl.select(layer.features[i]);
                                            alert("Highlight on");
                                            break;             
                                        }
                                  }
                    }

           FeatureSelectControl = new OpenLayers.Control.SelectFeature( layers[0], {}); 
            objGPWidget]]><xsl:value-of select="$pMapName" /><![CDATA[.addControl(FeatureSelectControl);

           ]]></xsl:if><![CDATA[

           if(oFeatures && oFeatures.length > 0)                  

                  { // THIS CASE WORKS
                      var bounds = oFeatures[0].geometry.getBounds();

                    ]]><xsl:if test="./options/highlight = 'true'"><![CDATA[
                            selectFeature(layers[0],oFeatures[0].fid);
                    ]]></xsl:if><![CDATA[
 
                      for(var i = 1; i<oFeatures.length;++i)
                      {      // THIS CASE DOES NOT WORK   
                            bounds.extend(oFeatures[i].geometry.getBounds());

                        ]]><xsl:if test="./options/highlight = 'true'"><![CDATA[
                            selectFeature(layers[0],oFeatures[i].fid);
                        ]]></xsl:if><![CDATA[

                           
               }  

How can I wait for the layer to display before selecting ?

TIA,

Yves




More information about the Geoprisma-dev mailing list