0
votes

I am using geoxml3 in order to be able to parse number of kml layers. Now for some reason it is working only for points and not for polygon kml files. The following is the code I am using;

function displayKml() {
        geo = new geoXML3.parser({
            map: map,
            zoom: false,
            singleInfoWindow: true,
            infoWindowOptions: { maxWidth: 100 },
            processStyles: true,
            markerOptions: { shadow: '' }
        });
        geo.parse("Resources/" + document.getElementById('<%= text2.ClientID %>').value);
    }

The followinh is a snippet from the polygon kml file;

<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>polygon_road</name>
<Schema name="polygon_road" id="polygon_road">
    <SimpleField name="Name" type="string"></SimpleField>
    <SimpleField name="Description" type="string"></SimpleField>
    <SimpleField name="id" type="int"></SimpleField>
    <SimpleField name="road_id" type="int"></SimpleField>
</Schema>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
    <ExtendedData><SchemaData schemaUrl="#polygon_road">
        <SimpleData name="id">1</SimpleData>
        <SimpleData name="road_id">8</SimpleData>
    </SchemaData></ExtendedData>
      <Polygon><outerBoundaryIs><LinearRing><coordinates>14.517292705321212,35.901268542738997 14.517607913551563,35.901660659810574 14.517685853364705,35.901598006913375 14.517365353364706,35.901199306913377 14.517359591135264,35.901193253552186 14.517352901130216,35.901188244530104 14.508563647353409,35.895689849334943 14.508510612009246,35.895774626998687 14.517292705321212,35.901268542738997</coordinates></LinearRing></outerBoundaryIs></Polygon>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
    <ExtendedData><SchemaData schemaUrl="#polygon_road">
        <SimpleData name="id">2</SimpleData>
        <SimpleData name="road_id">10</SimpleData>
    </SchemaData></ExtendedData>
      <Polygon><outerBoundaryIs><LinearRing><coordinates>14.518412050213227,35.900771848093811 14.518465407563996,35.900687272724355 14.510931707563996,35.895934372724355 14.510878350213227,35.896018948093811 14.518412050213227,35.900771848093811</coordinates></LinearRing></outerBoundaryIs></Polygon>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
    <ExtendedData><SchemaData schemaUrl="#polygon_road">
        <SimpleData name="id">3</SimpleData>
        <SimpleData name="road_id">12</SimpleData>
    </SchemaData></ExtendedData>
      <Polygon><outerBoundaryIs><LinearRing><coordinates>14.515100381551473,35.90111915074295 14.515153218448528,35.901034249257044 14.509212818448528,35.89733734925705 14.509159981551473,35.897422250742956 14.515100381551473,35.90111915074295</coordinates></LinearRing></outerBoundaryIs></Polygon>
  </Placemark>
1
What version of geoxml3 are you using? Polygons are only supported in the poly and kmz branches. If you are not using the trunk version of geoxml3 and points (markers) work, but not polygons, there is likely something wrong with your KML, not the way you are loading it. Can you provide KML that exhibits the problem (it doesn't have to be your real file). - geocodezip
is there a geoxml3 version that support all the three types of objects (point, line and polygon)? @geocodezip - IT_info
Yes. Both the polys and kmz branches support those. If you don't need zip compression (kmz files support), use the version in the polys branch, that is the latest and greatest. Where you using the trunk? - geocodezip
Yes I think I was using the trunk. I will try the poly one. - IT_info

1 Answers

2
votes

Don't use the trunk version of geoxml3 it is fairly old and only supports markers. Both the polys and the kmz branches support Polygons, Polylines and Markers. If you don't need zip compression (kmz file support), use the polys branch. If you need more standards compliant support in KML, the kmz branch better supports the documented standard but isn't well tested for non-kmz files.

(from the geoxml3 project page)

History

trunk - (old, not currently maintained) original version
network_link branch - (old, not currently maintained) development branch for network link functionality, not well tested
polys branch - development branch for polylines, polygons, current active development branch. Supports polylines, polygons, markers and groundoverlays
kmz branch - development branch for kmz support, built off of the polys branch. Supports external styles, and is more standards compliant. See  issue 53  for details (http://code.google.com/p/geoxml3/issues/detail?id=53) and current status. 

Your KML was missing the <width> property of <LineStyle> so the boundaries of the Polygons did not have a width (so you couldn't see them). The kmz branch has a better set of defaults. If I add the width, you can see them:

http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linktoB.html?filename=http://www.geocodezip.com/geoxml3_test/SO_IT_info_kmlA.xml