Hi all,<br><br>First off, I&#39;m new to OpenLayers so go gentle if I ask something dumb.<br><br>I&#39;ve
been generating a KML document from a php file and opening it with
OpenLayers...strange thing is that sometimes the geometry shows up in
the right place, and sometimes it shows up at 0,0 degrees.  This
happens completely at random for any size feature.  But what&#39;s even
stranger is that if I generate a KML doc with more than one feature,
the chances of it rendering properly are increased greatly.  <br>
<br>Here is what the KML document looks like:<br><br><pre><span>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;</span><br>&lt;<span>kml</span><span> xmlns</span>=<span>&quot;<a href="http://earth.google.com/kml/2.2" target="_blank">http://earth.google.com/kml/2.2</a>&quot;</span>&gt;<br>
<br>&lt;<span>Document</span><span> id</span>=<span>&quot;2000 Census Tracts&quot;</span>&gt;<br>&lt;<span>name</span>&gt;2000 Census Tracts&lt;/<span>name</span>&gt;<br><br>&lt;<span>Snippet</span>&gt;&lt;/<span>Snippet</span>&gt;<br>
&lt;<span>Folder</span><span> id</span>=<span>&quot;FeatureLayer0&quot;</span>&gt;<br><br>&lt;<span>name</span>&gt;2000 Census Tracts&lt;/<span>name</span>&gt;<br>&lt;<span>Snippet</span>&gt;&lt;/<span>Snippet</span>&gt;&lt;<span>Placemark</span>&gt;<br>
<br>      &lt;<span>name</span>&gt;frayser&lt;/<span>name</span>&gt;<br>      &lt;<span>Snippet</span>&gt;&lt;/<span>Snippet</span>&gt;<br>      &lt;<span>styleUrl</span>&gt;#PolyStyle00&lt;/<span>styleUrl</span>&gt;<br><br>
</pre><pre>        &lt;<span>Polygon</span>&gt;<br>          &lt;<span>tessellate</span>&gt;1&lt;/<span>tessellate</span>&gt;<br>          &lt;<span>extrude</span>&gt;0&lt;/<span>extrude</span>&gt;<br><br>          &lt;<span>altitudeMode</span>&gt;clampToGround&lt;/<span>altitudeMode</span>&gt;<br>
          &lt;<span>outerBoundaryIs</span>&gt;&lt;<span>LinearRing</span>&gt;&lt;<span>coordinates</span>&gt;<br><br>((coordinates go here...they are in State-Plane Feet (EPSG:2274) ))<br>&lt;/<span>coordinates</span>&gt;&lt;/<span>LinearRing</span>&gt;<br>
          &lt;/<span>outerBoundaryIs</span>&gt;<br><br></pre><pre>        &lt;/<span>Polygon</span>&gt;<br>    &lt;/<span>Placemark</span>&gt;&lt;/<span>Folder</span>&gt;<br>&lt;<span>Style</span><span> id</span>=<span>&quot;PolyStyle00&quot;</span>&gt;<br>
<br>    &lt;LabelStyle&gt;<br>      &lt;color&gt;fff333333&lt;/color&gt;<br>      &lt;scale&gt;0.000000&lt;/scale&gt;<br>    &lt;/LabelStyle&gt;<br>    &lt;LineStyle&gt;<br>      &lt;color&gt;ffc000000&lt;/color&gt;<br>      &lt;width&gt;0.400000&lt;/width&gt;<br>
<br>    &lt;/LineStyle&gt;<br>    &lt;PolyStyle&gt;<br>      &lt;color&gt;ffffff000&lt;/color&gt;<br>      &lt;outline&gt;1&lt;/outline&gt;<br>    &lt;/PolyStyle&gt;<br>  &lt;/<span>Style</span>&gt;<br>&lt;<span>Style</span><span> id</span>=<span>&quot;Boundary&quot;</span>&gt;<br>
<br>    &lt;LabelStyle&gt;<br>      &lt;color&gt;ff000000&lt;/color&gt;<br>      &lt;scale&gt;0.000000&lt;/scale&gt;<br>    &lt;/LabelStyle&gt;<br>    &lt;LineStyle&gt;<br>      &lt;color&gt;ff000000&lt;/color&gt;<br>      &lt;width&gt;0.400000&lt;/width&gt;<br>
<br>    &lt;/LineStyle&gt;<br>    &lt;PolyStyle&gt;<br>      &lt;color&gt;ff000000&lt;/color&gt;<br>      &lt;outline&gt;1&lt;/outline&gt;<br>    &lt;/PolyStyle&gt;<br>&lt;/<span>Style</span>&gt;<br>&lt;/<span>Document</span>&gt;<br>
<br>&lt;/<span>kml</span>&gt;</pre><br>... and here&#39;s what the map script looks like:<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">map = new OpenLayers.Map(&#39;map&#39;, {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                projection: new OpenLayers.Projection(&quot;EPSG:900913&quot;),</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                displayProjection: new OpenLayers.Projection(&quot;EPSG:4326&quot;),</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                units: &quot;m&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            });</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            var osm = new OpenLayers.Layer.TMS(</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                &quot;OpenStreetMap (Mapnik)&quot;,</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                &quot;<a href="http://tile.openstreetmap.org/" target="_blank">http://tile.openstreetmap.org/</a>&quot;,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                    type: &#39;png&#39;, getURL: osm_getTileURL,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    displayOutsideMaxExtent: true,</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                    attribution: &#39;&lt;a href=&quot;<a href="http://www.openstreetmap.org/" target="_blank">http://www.openstreetmap.org/</a>&quot;&gt;OpenStreetMap&lt;/a&gt;&#39;,</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                    maxResolution: 156543.0339,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                                                 20037508.34, 20037508.34)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            );</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">map.addLayer(osm);</span><br><br>// This works:<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">kmlLayer = new OpenLayers.Layer.GML(&quot;KML&quot;, &quot;includes/mapfactory.php&quot;,  {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                format: OpenLayers.Format.KML,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                projection: new OpenLayers.Projection(&quot;EPSG:2274&quot;),</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                formatOptions: {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        extractStyles: true,</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                        extractAttributes: true</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            );</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            </span><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            map.addLayer(kmlLayer);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">           
map.zoomToExtent(new OpenLayers.Bounds(-90.31272, 34.98697, -89.62608,
35.40779).transform(new OpenLayers.Projection(&quot;EPSG:4326&quot;), new OpenLayers.Projection(&quot;EPSG:900913&quot;)));</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">// This may or may not work (the get parameter tells the database to retrieve only the feature with that name)<br><span style="font-family: courier new,monospace;">kmlLayer = new OpenLayers.Layer.GML(&quot;KML&quot;, &quot;includes/mapfactory.php?featurename=overtonpark&quot;,  {</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                format: OpenLayers.Format.KML,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                projection: new OpenLayers.Projection(&quot;EPSG:2274&quot;),</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                formatOptions: {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                        extractStyles: true,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                        extractAttributes: true</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                    }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">            );</span><br><br><br>...it gets better:<br><br>If
I tell the init() script to create the kmlLayer but NOT add it to the
map, and then create an onclick event on the map&#39;s div so that when
clicked, the map layer is added, it displays correctly every time.<br>
<br>So I&#39;m assuming that map.addLayer() is sometimes called prematurely
(the layer may not have been finished constructing / kml document
wasn&#39;t comlpetely loaded?)<br><br>Any help would be most appreciated<br><br>
-- <br><font color="#888888">Jackson</font>