ThinkGeo.com    |     Documentation    |     Premium Support

KML Feature Layer Missing File

Hello,

I am looking to show a .kml file on our map, but, after creating the KmlFeatureLayer and adding it to the overlay, when Map.Refresh is called, I get an error about the KmlFileName.IDX file missing. I didn’t think I needed another file other than the .KML file.

I can open the .KML file in Google Earth without any issues.

Thanks,
Dib

Hi Dib,

In our map for KML we required index file, you can build that like this: KmlFeatureSource.BuildIndexFile(your file path).

We guess Google maybe have a similar solution it automatic build the file when loading.

Regards,

Don

Don,

Thanks, I’ve got it showing now. Here is the next issue:

The .kml file has two different Styles with a color defined, and polygons listed using each style, so that the data shows up using that color. You can see it in Google Earth working correctly.

How do I get the two styles to draw on my ThinkGeo map? If I set a default area style, ALL of the data shows up in that color, and not the colors there are supposed to be. If I don’t set a default area style, nothing shows on the map.

I can use .QueryTools to get the different colors, but how do I then set the data/polygons to draw using their correct colors?

The KML file is attached. Surge.zip (21.4 KB)

Hi Dib,

Display KML data no need set any style, the file already contains the style data, MapSuite can know how to render that. We created one simple to display your data, it works fine exactly sample with Google Earth. please refer the attachment sample. if there is any issue, please let us know that.
KmlDemo.zip (32.3 KB)

Here is test result ThinkGeo:


Google Earth:

Thanks
Mark

Don,

I think our problem comes from the fact that our MapUnit is set to Meters, not DecimalDegrees, though I’m still not totally sure what that problem is. This code shows the layer, but all data is in yellow:

    Dim layerOverlay As New LayerOverlay()
    Dim kmlLayer As New KmlFeatureLayer(fileName, KmlStylingType.StandardStyling)
    KmlFeatureSource.BuildIndexFile(fileName)
    kmlLayer.FeatureSource.Projection = proj4
    kmlLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = New AreaStyle(New GeoSolidBrush(GeoColor.SimpleColors.Yellow))
    kmlLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
    layerOverlay.Layers.Add(kmlLayer)
    Me.Map.Overlays.Add(layerOverlay)
    Me.Map.Refresh()

Nothing shows up if I do any of the following:

  1. Remove the styling type
  2. Remove the ZoomLevelSet lines
  3. Remove the Projection line

What is odd is that, in your sample, if I change the MapUnit to Meters, I could see the data as it is supposed to be. Maybe I’m changing a setting in my code that affects this.

Any other thoughts on this? I’ll keep playing with it and let you know if anything changes.

Don,

I have been playing around in a test project, and found out a few things. The test project’s MapUnit is set to Meters.

When I use the following code:

Dim layerOverlay As New LayerOverlay()
Dim kmlLayer As New KmlFeatureLayer(fileName)
KmlFeatureSource.BuildIndexFile(fileName)
layerOverlay.Layers.Add(kmlLayer)
kmlLayer.Open()
Me.Map.CurrentExtent = kmlLayer.GetBoundingBox
Me.Map.Overlays.Add(layerOverlay)
Me.Map.Refresh()

what I see is the data in the correct colors, but only at the most zoomed-in level possible, and not at the correct location on the map. It is very hard to make out, as it is so small on the map. Any zooming out makes it disappear. If return the code that sets the projection, and the ZoomLevelSet lines, plus the StylingType option, then I can see the data as expected, but in the yellow of the DefaultAreaStyle.

This again makes me think it has something to do with the conversion to Meters from DecimalDegrees.

My guess is that when I add the KML layer without the projection line, the ZoomLevelSets lines, and the StandardStyling setting, it is actually showing up on my map, but in the wrong place, and is only visible at the most zoomed in levels, like I am seeing it in the test project.

If you switch to Meter for your MapUnit in your demo project, you can see something similar occurring.

If you would like my test project, I can send it to you.

Hi Dib,

Thanks for your detail information, our developer had reproduced your problem.

As below is the research result and some suggestions:

Our map don’t support embedded style work together with projection, that’s why you cannot get the correct result.

We think you can do something like this:

  1. If you can accept all data with same color (same style), you can use custom style replace embedded style, it can works. Or you can try to split the KML to some separated KML files based on style, then draw them in different layers.

  2. You can try reprojection your base layer to decimal degree, if your baselayer cannot support that, you can try our WorldMapKit, which have 4326 and 900913 two types.

Wish that’s helpful.

Regards,

Don

Don,

I’ll look into splitting this particular KML file into two files. We just spent the last few moths moving our code over to use Web Mercator/Meters for our projection, so going back to decimal degrees is not an option. Can we expect an update that will allow KML files to work correctly with a meters MapUnit in the future?

Hi Dib,

Thanks for your update.

In fact our developer had worked for that, and it should be supported in one or two days.

I think if the split takes long time, maybe you can wait our updated package next Monday and see whether that works for you.

Regards,

Don

Don,

I did get the split working, but would rather use your built-in way. I will test it out next week.

Thanks

Hi Dib,

I think that should works, please test that and let us know if you have any question about it.

Regards,

Don

Don,

The update did the trick. Got the KML layers showing now as expected with a meters MapUnit. Thanks.

Hi Dib,

I am glad to hear that works.

Regards,

Don

Don,

I’ve come up on an issue:

When the layer draws on the map, the < Placemark >< name > values show on the map. Is there a setting that prevents this? They don’t show on something like Google Earth.

Thanks,
Dib

Hi Dib,

When KmlFeatureLayer uses the embedded styling, it doesn’t support to disable place mark, and it will render all things of kml files.

If you don’t want the map displays place mark name, you can modify data source and change the name value to empty string.

If you have any questions, please feel free to let us know.

Thanks,

Don

Don,

We will be getting the KML file from the National Hurricane Center. We could change it if needed, but this seems like something the layer should be able to handle.

Hi Dib,

Just like I mentioned before, because you are using embedded styling, our strategy is render all the node follow the embedded styling.

So I think we cannot handle that in layer side.

But if you met many same requirement for handle that, you should want build a simple XML utility instead of manual replace that.

Regards,

Don