[OpenLayers-Users] Simple KML layer help

Arnd Wippermann arnd.wippermann at web.de
Thu Dec 20 13:44:50 PST 2012


It should work. Here to see:

http://gis.ibbeck.de/ginfo/apps/OLExamples/OL212/Simple%20Map%20OSM%20-%20KM
L.asp

Arnd 

-----Ursprüngliche Nachricht-----
Von: Bill Schoolfield [mailto:bill at billmax.com] 
Gesendet: Donnerstag, 20. Dezember 2012 21:13
An: arnd.wippermann at web.de
Cc: openlayers-users at lists.osgeo.org
Betreff: Re: AW: [OpenLayers-Users] Simple KML layer help

Now have another problem. This kml file displays just fine at google. 
But using OL the layer/icon does not show up:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="sh_sunny_copy70">
<IconStyle>
<scale>1.4</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/shapes/sunny.png</href>
</Icon>
<hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/> </IconStyle>
<LabelStyle> <color>ff00aaff</color> </LabelStyle> </Style> <Placemark>
<name>MY POINT</name> <description>My Point</description>
<address>101 Elm</address>
<Point>
<coordinates>-97.14879049,32.89119839, 0.</coordinates> </Point>
<styleUrl>#sh_sunny_copy70</styleUrl>
</Placemark>
</Document>
</kml>

Any suggestions???? I'm using the same code below. Note that the very same
script but with different lat/long works just fine in OL.

Bill


On 12/19/2012 9:19 AM, Arnd Wippermann wrote:
> Instead in- and externalProjection you can use projection in the layer 
> options.
>
> var l =  new OpenLayers.Layer.Vector("KML", {
>      strategies: [new OpenLayers.Strategy.Fixed()],
>      projection: new OpenLayers.Projection("EPSG:4326"), //projection 
> of the data
>      protocol: new OpenLayers.Protocol.HTTP({
>          url: "test.kml",
>          format: new OpenLayers.Format.KML({
>              extractStyles: true,
>              extractAttributes: true,
>              maxDepth: 2
>          })
>      })
> });
>
> -----Ursprüngliche Nachricht-----
> Von: Bill Schoolfield [mailto:bill at billmax.com]
> Gesendet: Mittwoch, 19. Dezember 2012 00:46
> An: arnd.wippermann at web.de
> Betreff: Re: AW: [OpenLayers-Users] Simple KML layer help
>
> Arnd,
>
> Thanks. I made your change and it works. Gesh, Looked at that forever.
> Is the code correct otherwise? Seems like I may have done unnecessary 
> things while trying to sort this out.
>
> Bill
>
>
> On 12/18/2012 5:29 PM, Arnd Wippermann wrote:
>> 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