[OpenLayers-Users] Simple KML layer help

Arnd Wippermann arnd.wippermann at web.de
Tue Dec 18 15:29:30 PST 2012


The Coordinate is lon, lat

<coordinates>-96.80933013, 32.77874075, 0.</coordinates> Elm St in Dallas?

With your coordinates lat is -96 and thats outside projection.

Arnd



-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Bill
Schoolfield
Gesendet: Dienstag, 18. Dezember 2012 22:45
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] Simple KML layer help

Sorry for the last post: Here is my request in its entirety:


I'm trying to add a simple KML layer to a OL Map. I assume I have to worry
about projection of the lat/longs in the KML file. The following runs w/o
error but I don't see my KML layer. The rest of the map is fine. I know this
is very close to other posts and topics but I can't quite seem to get
anything to work.

Here is the php file that takes lat long arguments and produces a map:

<html><body>
   <div id="map"></div>
   <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
   <script>
         map = new OpenLayers.Map("map");
         map.addLayer(new OpenLayers.Layer.OSM("map"));

         var l =  new OpenLayers.Layer.Vector("KML", {
             strategies: [new OpenLayers.Strategy.Fixed()],
             protocol: new OpenLayers.Protocol.HTTP({
                 url: "test.kml",
                 format: new OpenLayers.Format.KML({
                     extractStyles: true,
                     extractAttributes: true,
                     maxDepth: 2,
                 'internalProjection': new
OpenLayers.Projection("EPSG:900913"),
                 'externalProjection': new
OpenLayers.Projection("EPSG:4326")
                 })
             })
         });

         map.addLayer(l);

         map.addControl(
                 new OpenLayers.Control.MousePosition({
                     prefix: '<a target="_blank" ' +
 
'href="http://spatialreference.org/ref/epsg/4326/">' +
                         'EPSG:4326</a> coordinates: ',
                     separator: ' | ',
                     numDigits: 2,
                     emptyString: 'Mouse is not over map.'
                 })
             );

         var proj = new OpenLayers.Projection("EPSG:4326");
         var point = new OpenLayers.LonLat(<?php echo $_GET["long"]; ?> ,
<?php echo $_GET["lat"]; ?>);
         point.transform(proj, map.getProjectionObject());

         map.setCenter(point, 13);

   </script>
</body></html>

And here is the test.kml file:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
   <name>MY POINT</name>
   <description>My Point</description>
   <Point>
     <coordinates>32.77874075,-96.80933013, 0.</coordinates>
         <Icon>
         <href>http://maps.google.com/mapfiles/kml/shapes/sunny.png</href>
         </Icon>
   </Point>
</Placemark>
</Document>
</kml>
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list