ThinkGeo.com    |     Documentation    |     Premium Support

How to draw line on top of YahooOverlay

I want to draw a railway line on top of a YahooOverlay on a web application. I cannot get the line to show. The following is my code.


private void InitYahooMap(Map map)

        {

            map.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"));

            map.MapUnit = GeographyUnit.DecimalDegree;

            map.Width = Unit.Percentage(98);

            map.StaticOverlay.JpegQuality = 30;

            map.MapTools.MouseCoordinate.Enabled = true;

            map.MapTools.OverlaySwitcher.Enabled = false;

            map.MapTools.ScaleLine.Enabled = false;

            map.MapTools.MiniMap.Enabled = false;

            map.MapTools.Logo.Enabled = false;


            YahooOverlay yahoo = new YahooOverlay("Yahoo Map");

            yahoo.JavaScriptLibraryUri = new Uri("api.maps.yahoo.com/ajaxymap?...openlayers");      

            yahoo.YahooMapType = YahooMapType.Regular;           


            DrawLines(map);

            map.CustomOverlays.Add(yahoo);

        }


        private void DrawLines(Map map)

        {

            LayerOverlay lineLayerOverlay = new LayerOverlay();

            InMemoryFeatureLayer lineFeatureLayer = new InMemoryFeatureLayer();

            LineShape line;

            List<Vertex> vts = new List<Vertex>();


            lineFeatureLayer.Name = "LinesShapeLayer";

            lineFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Railway1;

            lineFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


            vts.Add(new Vertex(-97, 31));

            vts.Add(new Vertex(-93, 35));

            vts.Add(new Vertex(-90, 39));


            line = new LineShape(vts);


            Proj4Projection proj4 = new Proj4Projection();

            proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);

            proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

            lineFeatureLayer.FeatureSource.Projection = proj4;

            proj4.Open();


            lineFeatureLayer.InternalFeatures.Add(new Feature(line));

            lineLayerOverlay.Layers.Add(lineFeatureLayer);

            lineLayerOverlay.IsBaseOverlay = false;

            map.DynamicOverlay.Layers.Add(lineFeatureLayer);


            lineLayerOverlay.Redraw();


            map.CurrentExtent = lineFeatureLayer.GetBoundingBox();

        }

 



Brian, 


First, thanks for joining the community. Hope you enjoy the learning and sharing here.
 
I think you are not using the latest version. DefaultOverlays and CustomOverlays should not be used together in the latest 3.1.16 one, please get the latest version and have another try. About how to use DefaultOverlays and CustomOverlays, please have a look at the following post for more information:
gis.thinkgeo.com/Support/Dis...fault.aspx
 
Another issue is that your base overlay is yahoo map but your map unit is DecimalDegree. If you are using yahoo, map unit should be Meter following its projection. Here we changed you code like following.
 

    private void InitYahooMap(Map map)
        {
            map.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"));
            map.MapUnit = GeographyUnit.Meter;
            map.Width = Unit.Percentage(98);
            map.MapTools.MouseCoordinate.Enabled = true;
            map.MapTools.OverlaySwitcher.Enabled = true;
            map.MapTools.ScaleLine.Enabled = false;
            map.MapTools.MiniMap.Enabled = false;
            map.MapTools.Logo.Enabled = false;

            YahooOverlay yahoo = new YahooOverlay("Yahoo Map");
            yahoo.JavaScriptLibraryUri = new Uri ("api.maps.yahoo.com/ajaxymap?...openlayers");     
            yahoo.YahooMapType = YahooMapType.Regular;

            DrawLines(map);
            map.CustomOverlays.Add(yahoo);
        }

        private void DrawLines(Map map)
        {
            LayerOverlay lineLayerOverlay = new LayerOverlay("LineShapes");
            InMemoryFeatureLayer lineFeatureLayer = new InMemoryFeatureLayer();

            lineFeatureLayer.Name = "LinesShapeLayer";
            lineFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Railway1;
            lineFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            List vts = new List();
            vts.Add(new Vertex(-97, 31));
            vts.Add(new Vertex(-93, 35));
            vts.Add(new Vertex(-90, 39));
            LineShape line = new LineShape(vts);

            Proj4Projection proj4 = new Proj4Projection();
            proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
            proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
            lineFeatureLayer.FeatureSource.Projection = proj4;
           
            lineFeatureLayer.InternalFeatures.Add(new Feature(line));
            lineLayerOverlay.Layers.Add(lineFeatureLayer);
            lineLayerOverlay.IsBaseOverlay = false;
            map.CustomOverlays.Add(lineLayerOverlay);

            lineFeatureLayer.Open();
            map.CurrentExtent = lineFeatureLayer.GetBoundingBox();
            lineFeatureLayer.Close();
        }

 
Let us know for more queries.
 
Ben

Thanks for the quick response! The code works.

That’s great, Brian.