[OpenLayers-Users] KML layer doesn't display in OL.

Zuhex gmduky at hotmail.com
Sun May 2 03:49:14 EDT 2010


hello

I am new for Openlayer and GeoServer.I was created KML file from ArcGIS by
converted shapefile to KMZ. So I extracted KMZ file and then I got one image
and one KML file. I put them together into my KML folder.
Here this is my code

##################################################

<script type="text/javascript">
        var map, select; 
        function init(){
                format = 'image/png';				
            
                var bounds = new OpenLayers.Bounds(
                    745805.484, 1675119.129,
                    748889.77, 1682234.497
                );
                var options = {
                    controls: [],
                    maxExtent: bounds,
                    maxResolution: 15,
                    projection: "EPSG:24047",
                    units: 'm',
					numZoomLevels:5
                };
                map = new OpenLayers.Map('map', options);
            
                // setup tiled layer
                tiled = new OpenLayers.Layer.WMS(
                    "Tiled", "http://localhost:8080/geoserver/wms",
                    {
                        layers: 'KhaoSomphot',
                        srs: 'EPSG:24047',
                        format: format,
                        tiled: 'true',
                        tilesOrigin : map.maxExtent.left + ',' +
map.maxExtent.bottom
                    },
                    {
                        buffer: 0,
                        displayOutsideMaxExtent: true
                    } ,{isBaseLayer: false}
                );
            
                // setup single tiled layer
                untiled = new OpenLayers.Layer.WMS(
                    "Untiled", "http://localhost:8080/geoserver/wms",
                    {
                        layers: 'KhaoSomphot',
                        srs: 'EPSG:24047',
                        height: '400',
                        format: format
                    },
                    {singleTile: true, ratio: 1} ,{isBaseLayer: false}
                );

            var herb = new OpenLayers.Layer.Vector("KML", {
                projection: map.displayProjection,
                strategies: [new OpenLayers.Strategy.Fixed()],
                protocol: new OpenLayers.Protocol.HTTP({
                    url: "kml/doc.kml",
                    format: new OpenLayers.Format.KML({
                        extractStyles: true,
                        extractAttributes: true
                    })
                })
            });
            
            map.addLayers([tiled, untiled, herb]);
            
            select = new OpenLayers.Control.SelectFeature(herb);
            
            herb.events.on({
                "featureselected": onFeatureSelect,
                "featureunselected": onFeatureUnselect
            });
 
            map.addControl(select);
            select.activate();   
            map.zoomToMaxExtent();
        }
        function onPopupClose(evt) {
            select.unselectAll();
        }
        function onFeatureSelect(event) {
            var feature = event.feature;
            // Since KML is user-generated, do naive protection against
            // Javascript.
            var content = "<h2>"+feature.attributes.name + "</h2>" +
feature.attributes.description;
            if (content.search("<script") != -1) {
                content = "Content contained Javascript! Escaped content
below.<br />" + content.replace(/</g, "&lt;");
            }
            popup = new OpenLayers.Popup.FramedCloud("chicken", 
                                    
feature.geometry.getBounds().getCenterLonLat(),
                                     new OpenLayers.Size(100,100),
                                     content,
                                     null, true, onPopupClose);
            feature.popup = popup;
            map.addPopup(popup);
        }
        function onFeatureUnselect(event) {
            var feature = event.feature;
            if(feature.popup) {
                map.removePopup(feature.popup);
                feature.popup.destroy();
                delete feature.popup;
            }
        }
    </script>

##################################################

This is my KML code

##################################################

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document id="herb">
  <name>herb</name>
  <Snippet></Snippet>
  <Folder id="FeatureLayer0">
    <name>herb</name>
  <Snippet></Snippet>
    <Placemark>
      <name>๎ค„</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.294314,15.181605,0.000000</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>๎ค„</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.294730,15.181329,0.000000</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>๎ค„</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.294675,15.181411,0.000000</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>๎ค„</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.294734,15.178293,0.000000</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>เธชเธฐเนเธเนเธชเธ‡</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.294911,15.179159,0.000000</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>๎ค„</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.294943,15.178653,0.000000</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>๎ค„</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.294714,15.178149,0.000000</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>เธ‚เธญเธšเธŠเธฐเธ™เธฒเธ‡</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.294313,15.178072,0.000000</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>๎ค„</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.294998,15.178616,0.000000</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>hhh</name>
      <Snippet></Snippet>
      <styleUrl>#IconStyle00</styleUrl>
      <Point>
        <extrude>0</extrude>
        <altitudeMode>relativeToGround</altitudeMode>
        <coordinates> 101.293716,15.180359,0.000000</coordinates>
      </Point>
    </Placemark>
  </Folder>
  <Style id="IconStyle00">
    <IconStyle>
      <Icon><href>000000.png</href></Icon>
      <scale>1.000000</scale>
    </IconStyle>
    <LabelStyle>
      <color>ff000000</color>
      <scale>1.333333</scale>
    </LabelStyle>
  </Style>
</Document>
</kml>

######################################################

Thank,

Zuhex
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/KML-layer-doesn-t-display-in-OL-tp4992338p4992338.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list