ThinkGeo.com    |     Documentation    |     Premium Support

KML doesn't refresh after zoom is changed

Hello,


I am getting a strange error with a kml file not displaying after zoom is changed. I have set it up exactly the same way as with other layers which are displaying no problem. Here is my code and i have attached the kml.


 


 Proj4Projection proj_KML = new Proj4Projection();

                proj_KML.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);

                proj_KML.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

                

               

                KmlFeatureLayer kmllayer = new KmlFeatureLayer(@"Data\Efate_GPS.kml");

                kmllayer.FeatureSource.Projection = proj_KML;

             

                kmllayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Black), new GeoSolidBrush(GeoColor.SimpleColors.Yellow));

                kmllayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.SimpleColors.Blue, 5));

                kmllayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.SimpleColors.BrightRed), 10);

                kmllayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;



                

                LayerOverlay KMLOverlay = new LayerOverlay();

              

                KMLOverlay.Layers.Add("KmlLayer", kmllayer);

                wpfMap1.Overlays.Add("KMLOverlay", KMLOverlay);

                wpfMap1.Overlays.MoveToTop("KMLOverlay");

                wpfMap1.Refresh();


thanks


Phil



Efate_GPS.zip (369 KB)

 Phil,


 
Just confirm with you that we are using the same KmlFeatureLayer, is it get from KmlExtention in our code community?  
wiki.thinkgeo.com/wiki/Map_Suite_Wpf_Desktop_Edition_Layers_%26_FeatureSources_Samples#KML_Extension
 
I can recreate your issue, it may cause that this layer not implement projection correct, because if I remove the projection, it works properly.
 
I am doing some deep research on KmlExtension to fix this bug, any progress I will let you know ASAP.
 
Thanks,
James
 

Hi James, 
  
 Any luck finding the problem? 
  
 thanks 
  
 Phil

Here is another kml file with problems, and as a shapefile it also doesnt work. Lines up perfectly in Google earth but cant see it in mapsuite. Here is the shapefile code:




 ShapeFileFeatureLayer shp = new ShapeFileFeatureLayer(@"Data\HH Line Islands.shp");

                shp.RequireIndex = false;

                shp.Open();

                if (shp.UsingSpatialIndex == false)

                {

                    shp.Close();

                    ShapeFileFeatureSource.BuildIndexFile(@"Data\HH Line Islands.shp", BuildIndexMode.Rebuild);

                }



                shp.RequireIndex = true;

                //shp.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));

                shp.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.SimpleColors.BrightRed), 10);

                shp.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;



                Proj4Projection proj_EEZs = new Proj4Projection();

                proj_EEZs.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);

                proj_EEZs.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

                shp.FeatureSource.Projection = proj_EEZs;

                shp.WrappingMode = WrappingMode.WrapDateline;

                shp.WrappingExtent = new RectangleShape(WrapExtentMinX, WrapExtentMaxY, WrapExtentMaxX, WrapExtentMinY); //new RectangleShape(17897271, -1367305, 19514067, -2411741);

                LayerOverlay shpOverlay = new LayerOverlay();



HH_Line_islands.zip (23.5 KB)

 Phil,


The first kml problem you can change the code of GetAllFeatureCore as following:


        protected override Collection<Feature> GetAllFeaturesCore(IEnumerable<string> returningColumnNames)
        {
            Collection<Feature> returnFeatures = new Collection<Feature>();
            foreach (Feature feature in inMemoryFeatureLayer.InternalFeatures)
            {
                Feature newFeature = GetClonedFeature(feature, returningColumnNames);
                returnFeatures.Add(newFeature);
            }

            return returnFeatures;
        }

        private static Feature GetClonedFeature(Feature feature, IEnumerable<string> returningColumnNames)
        {
            Dictionary<string, string> columnValues = new Dictionary<string, string>();
            foreach (string columnName in returningColumnNames)
            {
                if (feature.ColumnValues.ContainsKey(columnName))
                {
                    columnValues.Add(columnName, feature.ColumnValues[columnName]);
                }
                else
                {
                    columnValues.Add(columnName, string.Empty);
                }
            }
            byte[] wellKnownBinary = feature.GetWellKnownBinary();
            byte[] projectedWellKnownBinary = new byte[wellKnownBinary.Length];
            Buffer.BlockCopy(wellKnownBinary, 0, projectedWellKnownBinary, 0, wellKnownBinary.Length);
            Feature insideFeature = new Feature(projectedWellKnownBinary, feature.Id, columnValues);
            insideFeature.Tag = feature.Tag;
            return insideFeature;
        }

Thanks,


James



Phil, 
  
 About the shape file problem, I couldn’t figure out the source reason, could you provide the shape files as well? 
  
 Thanks, 
  
 James

thanks James,


When i paste this into my code i get an error on "inMemoryFeatureLayer.InternalFeatures". Saying it doesnt exist in the current context. What am i missing?


thanks


Phil


 



 Phil,


I think you may changed some code of the orginal code community sample, I have attached the whole project you can look at it.


Thanks,


James



KmlExtensionSample.zip (336 KB)