Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I zoom into a map, then do a screenDisp.DrawPolyline(polyline); Now the line is in the correct place, but the map that is the background of the polyline object is actually the initial map and not the zoomed in map.

Here's a screenshot:

What you are seeing is a really zoomed in map of minnesota with most of the layers turned off, and that interior picture is part of the West Coast from the initial map load.

share|improve this question
up vote 2 down vote accepted

I've seen this sort of behavior before. It was the result of calling IDisplay.StartDrawing, without calling FinishDrawing. How/when are you drawing to the screen? The more common ways to draw your own geometries on the screen are:

  • In response to IActiveViewEvents.AfterDraw
  • Adding IElements to the IGraphicsContainer (implemented by Map class)
  • Adding a custom layer to the map.

Below is code showing how to add a custom layer to the map.

public class CustLayer: BaseCustomLayer 
    private IPolyline m_Polyline = null;
    private ISymbol m_Symbol = null;
    public CustLayer()
        m_Symbol = new SimpleLineSymbolClass();
    public override void Draw(esriDrawPhase drawPhase, IDisplay Display, ITrackCancel trackCancel)
        if (drawPhase != esriDrawPhase.esriDPGeography)
        if (m_Polyline == null)
            IProjectedCoordinateSystem pcs = Display.DisplayTransformation.SpatialReference as IProjectedCoordinateSystem;
            if (pcs != null)
                m_Polyline = MakePolyline(pcs.GeographicCoordinateSystem);
                m_Polyline = MakePolyline(new UnknownCoordinateSystemClass());
            m_extent = m_Polyline.Envelope;  // sets IGeoDataset.Extent
        // startdrawing has already been called, so don't call it again here

    public static IPolyline MakePolyline(ISpatialReference sr)
        IPointCollection pc = new PolylineClass();
        // deal with legacy COM cruft ...
        object missing = Type.Missing; // (not needed with VB.NET)
        pc.AddPoint(MakePoint(-98.0, 29.0, sr), ref missing, ref missing);
        pc.AddPoint(MakePoint(-97.0, 28.0, sr), ref missing, ref missing);
        pc.AddPoint(MakePoint(-96.0, 27.0, sr), ref missing, ref missing);
        pc.AddPoint(MakePoint(-95.0, 26.0, sr), ref missing, ref missing);

        IPolyline polyline = (IPolyline)pc;
        polyline.SpatialReference = sr;
        return polyline;
    public static IPoint MakePoint(double x, double y, ISpatialReference sr)
        IPoint p = new PointClass();
        p.PutCoords(x, y);
        p.SpatialReference = sr;
        return p;

Here's the code that instantiates the layer and adds it to a mapcontrol:

private void testToolStripMenuItem_Click(object sender, EventArgs e)
        CustLayer layer = new CustLayer();
        layer.Name = "my custom layer";
    catch (Exception ex)
        MessageBox.Show(this, ex.Message);
share|improve this answer
@Kirk Kuykendall Thanks again for the code. I can't seem to hit a breakpoint in the the CustLayer Draw function. Do I need to do some additional wiring? – patrick Sep 1 '10 at 14:21
Do you see the layer in your TOC? Is it checked? – Kirk Kuykendall Sep 1 '10 at 14:47
@Kirk Kuykendall layer is in TOC and its is checked, but breakpoint in Draw is still not hit... – patrick Sep 1 '10 at 14:49
Have you tried panning/zooming? This should cause ILayer.Draw to be called. In visual studio have you set Debug>Exceptions to break when an exception is thrown? Maybe there's an exception firing before your layer has a chance to draw. – Kirk Kuykendall Sep 1 '10 at 15:29
@Kirk Kuykendall I tried panning and zooming but it didn't hit the breakpont, no exceptions are thrown my code is set to break. – patrick Sep 1 '10 at 16:16

You could also try calling IActiveView:PartialRefresh to refesh the graphics container or the layer. To test whether refresh has anything to do with your problem call IActiveView:Refresh which is a full refresh. If it does use partial refresh instead.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.