ThinkGeo.com    |     Documentation    |     Premium Support

Draw Hashed Line with two specific colors

Hello,
We are trying to create a line, or shape outline with a multi-color hash.
i.e. a dashed line - but with two specific colors, rather than the default - one custom color, one transparent gap.

I have code for creating a dashed line (one color, and a gap) working.
Immediately next to it I have what should work for two custom colors - but receive an “Object Reference Not Set To an Instance of an Object” in several places across the screen.

Just to demonstrate, I’ve setup sample code that works on the first iteration, fails on the second. If you set the counter at the top of the HomeController to 1; then it will reverse, that is, first iteration will fail; second iteration will work.

If you want to see just the very basic code - I’ll paste the If block public here; otherwise download the sample, and look at the HomeController code - fully functional sample.

        if (HomeController.Iteration == 0)
        {
            geoPen = new GeoPen(GeoColor.StandardColors.Green, penWidth);
            geoPen.DashStyle = LineDashStyle.Dash;
            HomeController.Iteration++;
        }
        else
        {
            GeoHatchBrush hatch = new GeoHatchBrush(GeoHatchStyle.BackwardDiagonal, GeoColor.StandardColors.Orange, GeoColor.StandardColors.Blue);
            geoPen = new GeoPen(hatch, penWidth);
            HomeController.Iteration--;
        }

//Bother bother bother - can’t upload the zip file, so here’s the HomeController code
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.MvcEdition;

namespace Mvc_Projection32149Sample.Controllers
{
public class HomeController : Controller
{
private static int iteration = 0;
// GET: Home
public ActionResult Index()
{
var map = GetSampleMap();
return View(map);
}

    public Map GetSampleMap()
    {
        //Setup a map canvas
        Map sampleMap = new Map("SampleMap",
                 new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 500);
        sampleMap.MapBackground = new BackgroundLayer(new GeoSolidBrush(GeoColor.StandardColors.White));

        Uri serverUri = new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export");
        ArcGISServerRestOverlay overlay = new ArcGISServerRestOverlay("sampleId", serverUri);
        overlay.Parameters.Add("format", "jpeg");

        // Sets the projection to EPSG: 32149
        overlay.Projection = "EPSG:32149";

        sampleMap.CurrentExtent = new RectangleShape(187754.6365, 259585.0321, 781043.7173, 30497.7688);  //32149 projection boundaries in meters
        sampleMap.MapUnit = GeographyUnit.Meter;


        LayerOverlay layerOverlay = new LayerOverlay("DynamicOverlay");

        //Example Code Below Here

        InMemoryFeatureLayer featureLayer = AddLine();
        layerOverlay.Layers.Add(featureLayer);

        //Example Code Above Here


        // Adds the ArcGISServerRestOverlay and LayerOverlay into CustomOverlays.
        sampleMap.CustomOverlays.Add(overlay);
        sampleMap.CustomOverlays.Add(layerOverlay);
        sampleMap.ZoomIn();
        return sampleMap;
    }

    public static int Iteration
    {
        get { return HomeController.iteration; }
        set { HomeController.iteration = value; }
    }
    public InMemoryFeatureLayer AddLine()
    {
        InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
        InMemoryFeatureLayer lineFeature = new InMemoryFeatureLayer();

        GeoPen geoPen = null;
        int penWidth = 2;

        if (HomeController.Iteration == 0)
        {
            //This block works
            geoPen = new GeoPen(GeoColor.StandardColors.Green, penWidth);
            geoPen.DashStyle = LineDashStyle.Dash;
            HomeController.Iteration++;
        }
        else
        {
            //This block fails
            GeoHatchBrush hatch = new GeoHatchBrush(GeoHatchStyle.BackwardDiagonal, GeoColor.StandardColors.Orange, GeoColor.StandardColors.Blue);
            geoPen = new GeoPen(hatch, penWidth);
            HomeController.Iteration--;
        }

        LineStyle hatchLineStyle = new LineStyle(geoPen);
        inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = hatchLineStyle;
        LineShape lineShape = new LineShape();
        lineShape.Vertices.Add(new Vertex(-119.5, 46.6));
        lineShape.Vertices.Add(new Vertex(-119.5, 46.5));
        inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        // Convert the feature to Washington State Plane Coordinates, South
        Proj4Projection proj4 = new Proj4Projection(4326, 32149);
        proj4.Open();
        lineShape = (LineShape) proj4.ConvertToExternalProjection(lineShape);

        // Add the feature to the layer
        inMemoryFeatureLayer.Open();
        inMemoryFeatureLayer.FeatureSource.BeginTransaction();
        inMemoryFeatureLayer.FeatureSource.AddFeature(lineShape);
        inMemoryFeatureLayer.FeatureSource.CommitTransaction();
        inMemoryFeatureLayer.Close();
        return inMemoryFeatureLayer;
    }
}

}

Hi Kevin,

Thanks for your code.

That’s because our line style only support GeoSolidBrush now.

If you are using the other brush, it won’t be render succeed even without exception.

Regards,

Don

Is this expected to be fixed in ThinkGeo 10?

Hi Kevin,

That’s not a bug, if we can support that, it should be an enhancement.

I think in 10.0 it won’t be implemented because 10.0 have go into test process.

I think you can vote for this feature here Vote for new features on the Enhancement Tracker

Or you can try to require professional service from your sales to see whether it can be implemented.

Regards,

Don