ThinkGeo.com    |     Documentation    |     Premium Support

KML file feature vanishing

Hello,

We are using a KML file from the national hurricane center that shows storm surge watches and warnings. What we are seeing happen is that at lower zoom levels, 10-12 particularly, parts of the data are vanishing. This happens as you zoom in, and also as you pan, where you can see some of the data vanish, and some of the data pop in.

Our map projection is WebMercator, and we are setting the projection for the KMLFeatureLayer to that. I can provide the KML file if needed, or give you the link it can be downloaded from.

Any ideas why this might be happening?

Thanks,
Dib

Hi Dib,

That’s strange because we hadn’t met that before.

Please upload the sample KML or download link is helpful, and please let us know the test extent and detail steps to reproduce it.

Regards,

Don

Don,

The file is located here:

http://www.nhc.noaa.gov/gis/kml/surge/WatchWarningSS_latest.kml

Here is the code that is used to show it. Two things happen here: first, I have to strip out value between any Placemark-name and /name i the KML, so that it doesn’t show on the map. Secondly, the code builds the index files before creating and adding the KMLFeatureLayer

'remove Placemark-name from kml file
Try
Dim reader As New IO.StreamReader(surgeFile)
Dim fileText As String = reader.ReadToEnd
reader.Close()

        Dim plStart As Integer = 0
        Dim plEnd As Integer

        While plStart >= 0
            plStart = fileText.IndexOf("<Placemark><name>", plStart)
            If plStart > 0 Then
                plEnd = fileText.IndexOf("</name>", plStart)
                fileText = fileText.Remove(plStart + 17, plEnd - (plStart + 17))
            End If
            If plStart > 0 Then plStart += 1
        End While

        Dim writer As New IO.StreamWriter(surgeFile)
        writer.Write(fileText)
        writer.Close()

    Catch ex As Exception
        RaiseEvent SendMessage("Error editing Surge Watch/Warnings file")
        Me._kmlShown = False
        Return
    End Try

    Dim layerOverlay As New LayerOverlay()
    KmlFeatureSource.BuildIndexFile(surgeFile)
    Dim kmlLayer As New KmlFeatureLayer(surgeFile) '(surgeFile, KmlStylingType.EmbeddedStyling)
    kmlLayer.FeatureSource.Projection = proj4
    kmlLayer.ZoomLevelSet.ZoomLevel04.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level09
    kmlLayer.IsVisible = Me.MapZoomLevel < 10
    kmlLayer.Transparency = 255
    kmlLayer.Name = "KML255"
    kmlLayer.DrawingQuality = DrawingQuality.HighQuality
    layerOverlay.Layers.Add(kmlLayer.Name, kmlLayer)

    kmlLayer = New KmlFeatureLayer(surgeFile) ', KmlStylingType.EmbeddedStyling)
    kmlLayer.FeatureSource.Projection = proj4
    kmlLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
    kmlLayer.IsVisible = Me.MapZoomLevel >= 10
    kmlLayer.Transparency = 150
    kmlLayer.Name = "KML150"
    kmlLayer.DrawingQuality = DrawingQuality.HighQuality
    layerOverlay.Layers.Add(kmlLayer.Name, kmlLayer)

    layerOverlay.Name = layerName
    Me.Map.Overlays.Add(layerName, layerOverlay)
    Me.Map.Refresh()

Our map unit is Meters, and the projection used is a Proj4Projection. This KML file will be along the Texas coast.

Don,

It seems like it is happening when some portion of the KML file is off screen. If the entirety of the file can be seen in the current extent, everything seems to be fine. But if part of it if outside the map extent, then the pop in/out occurs.

Don,

One more thing I noticed. This KML was two different styles. If there are only items of one style, then it shows up correctly, with no pop in/out. If there are items for each of the styles, that’s when we are seeing the pop in/out.

Hi Dib,

I tested your code with the WatchWarningSS_latest.kml data, it looks that cannot be rendered correct with projection, but it can be rendered correct under decimal degree. And I cannot reproduce something like “the pop in/out”, could you please show us how it looks like?

Regards,

Don

Don,

Figured it out. I was not forcing a rebuild on the index files before showing the layer, so they could be related to an older version of the KML file. By adding the Rebuild parameter to the .BuildIndexFile call, the layer seems to be drawing correctly in all cases.

Thanks

Hi Dib,

I am glad to hear that works and thanks for your share.

Any question please let us know.

Regards,

Don