[OpenLayers-Users] Creating KML layer from PHP file...random
display issues
Jackson J. Gilman
jgilman at memphis.edu
Wed Jun 3 16:11:07 EDT 2009
Hi all,
First off, I'm new to OpenLayers so go gentle if I ask something dumb.
I'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'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.
Here is what the KML document looks like:
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document id="2000 Census Tracts">
<name>2000 Census Tracts</name>
<Snippet></Snippet>
<Folder id="FeatureLayer0">
<name>2000 Census Tracts</name>
<Snippet></Snippet><Placemark>
<name>frayser</name>
<Snippet></Snippet>
<styleUrl>#PolyStyle00</styleUrl>
<Polygon>
<tessellate>1</tessellate>
<extrude>0</extrude>
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs><LinearRing><coordinates>
((coordinates go here...they are in State-Plane Feet (EPSG:2274) ))
</coordinates></LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark></Folder>
<Style id="PolyStyle00">
<LabelStyle>
<color>fff333333</color>
<scale>0.000000</scale>
</LabelStyle>
<LineStyle>
<color>ffc000000</color>
<width>0.400000</width>
</LineStyle>
<PolyStyle>
<color>ffffff000</color>
<outline>1</outline>
</PolyStyle>
</Style>
<Style id="Boundary">
<LabelStyle>
<color>ff000000</color>
<scale>0.000000</scale>
</LabelStyle>
<LineStyle>
<color>ff000000</color>
<width>0.400000</width>
</LineStyle>
<PolyStyle>
<color>ff000000</color>
<outline>1</outline>
</PolyStyle>
</Style>
</Document>
</kml>
... and here's what the map script looks like:
map = new OpenLayers.Map('map', {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m"
});
var osm = new OpenLayers.Layer.TMS(
"OpenStreetMap (Mapnik)",
"http://tile.openstreetmap.org/",
{
type: 'png', getURL: osm_getTileURL,
displayOutsideMaxExtent: true,
attribution: '<a href="http://www.openstreetmap.org/
">OpenStreetMap</a>',
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(-20037508.34,
-20037508.34,
20037508.34, 20037508.34)
}
);
map.addLayer(osm);
// This works:
kmlLayer = new OpenLayers.Layer.GML("KML", "includes/mapfactory.php", {
format: OpenLayers.Format.KML,
projection: new OpenLayers.Projection("EPSG:2274"),
formatOptions: {
extractStyles: true,
extractAttributes: true
}
}
);
map.addLayer(kmlLayer);
map.zoomToExtent(new OpenLayers.Bounds(-90.31272, 34.98697,
-89.62608, 35.40779).transform(new OpenLayers.Projection("EPSG:4326"), new
OpenLayers.Projection("EPSG:900913")));
// This may or may not work (the get parameter tells the database to
retrieve only the feature with that name)
kmlLayer = new OpenLayers.Layer.GML("KML",
"includes/mapfactory.php?featurename=overtonpark", {
format: OpenLayers.Format.KML,
projection: new OpenLayers.Projection("EPSG:2274"),
formatOptions: {
extractStyles: true,
extractAttributes: true
}
}
);
...it gets better:
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's div so that when clicked,
the map layer is added, it displays correctly every time.
So I'm assuming that map.addLayer() is sometimes called prematurely (the
layer may not have been finished constructing / kml document wasn't
comlpetely loaded?)
Any help would be most appreciated
--
Jackson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090603/b9dbf911/attachment.html
More information about the Users
mailing list