Beispiel #1
0
        /// <summary>
        /// This will draw any features that intersect this region. To specify the features
        /// directly, use OnDrawFeatures. This will not clear existing buffer content.
        /// For that call Initialize instead.
        /// </summary>
        /// <param name="args">A GeoArgs clarifying the transformation from geographic to image space</param>
        /// <param name="regions">The geographic regions to draw</param>
        /// <param name="selected">If this is true, nothing is painted, because selected labels get painted together with not selected labels.</param>
        public void DrawRegions(MapArgs args, List <Extent> regions, bool selected)
        {
            if (FeatureSet == null || selected)
            {
                return;
            }
#if DEBUG
            var sw = new Stopwatch();
            sw.Start();
#endif

            if (FeatureSet.IndexMode)
            {
                // First determine the number of features we are talking about based on region.
                List <int> drawIndices = new List <int>();
                foreach (Extent region in regions)
                {
                    if (region != null)
                    {
                        // We need to consider labels that go off the screen. Figure a region that is larger.
                        Extent sur = region.Copy();
                        sur.ExpandBy(region.Width, region.Height);

                        // Use union to prevent duplicates. No sense in drawing more than we have to.
                        drawIndices = drawIndices.Union(FeatureSet.SelectIndices(sur)).ToList();
                    }
                }

                List <Rectangle> clips = args.ProjToPixel(regions);
                DrawFeatures(args, drawIndices, clips, true);
            }
            else
            {
                // First determine the number of features we are talking about based on region.
                List <IFeature> drawList = new List <IFeature>();
                foreach (Extent region in regions)
                {
                    if (region != null)
                    {
                        // We need to consider labels that go off the screen. Figure a region that is larger.
                        Extent r = region.Copy();
                        r.ExpandBy(region.Width, region.Height);

                        // Use union to prevent duplicates. No sense in drawing more than we have to.
                        drawList = drawList.Union(FeatureSet.Select(r)).ToList();
                    }
                }

                List <Rectangle> clipRects = args.ProjToPixel(regions);
                DrawFeatures(args, drawList, clipRects, true);
            }

#if DEBUG
            sw.Stop();
            Debug.WriteLine("MapLabelLayer {0} DrawRegions: {1} ms", FeatureSet.Name, sw.ElapsedMilliseconds);
#endif
        }
Beispiel #2
0
 /// <summary>
 /// This will draw any features that intersect this region.  To specify the features
 /// directly, use OnDrawFeatures.  This will not clear existing buffer content.
 /// For that call Initialize instead.
 /// </summary>
 /// <param name="args">A GeoArgs clarifying the transformation from geographic to image space</param>
 /// <param name="regions">The geographic regions to draw</param>
 public void DrawRegions(MapArgs args, List <Extent> regions)
 {
     if (FeatureSet == null)
     {
         return;
     }
     if (FeatureSet.IndexMode)
     {
         // First determine the number of features we are talking about based on region.
         List <int> drawIndices = new List <int>();
         foreach (Extent region in regions)
         {
             if (region != null)
             {
                 // We need to consider labels that go off the screen.  figure a region
                 // that is larger.
                 Extent sur = region.Copy();
                 sur.ExpandBy(region.Width, region.Height);
                 // Use union to prevent duplicates.  No sense in drawing more than we have to.
                 drawIndices = drawIndices.Union(FeatureSet.SelectIndices(sur)).ToList();
             }
         }
         List <Rectangle> clips = args.ProjToPixel(regions);
         DrawFeatures(args, drawIndices, clips, true);
     }
     else
     {
         // First determine the number of features we are talking about based on region.
         List <IFeature> drawList = new List <IFeature>();
         foreach (Extent region in regions)
         {
             if (region != null)
             {
                 // We need to consider labels that go off the screen.  figure a region
                 // that is larger.
                 Extent r = region.Copy();
                 r.ExpandBy(region.Width, region.Height);
                 // Use union to prevent duplicates.  No sense in drawing more than we have to.
                 drawList = drawList.Union(FeatureSet.Select(r)).ToList();
             }
         }
         List <Rectangle> clipRects = args.ProjToPixel(regions);
         DrawFeatures(args, drawList, clipRects, true);
     }
 }
Beispiel #3
0
        public void RaiseCallbackEvent(String eventArgument)
//        public virtual void RaiseCallbackEvent(String eventArgument)  //to override in subclass
        {
//            returnCommand = "REFRESH";  //unsightly refresh when change legend selection
            returnCommand = "NOTHING";

//            string Nm = SessionName;  //not used

            GDIMap m = (GDIMap)System.Web.HttpContext.Current.Session[(string)ViewState[ClientID]];

            if (m == null)
            {
                return;
            }

            string[] arg = eventArgument.Split('|');

            string cmd = arg[0].ToUpper();

            switch (cmd)
            {
            case "ZOOMALL":
            {
                ZoomAll(ref m);
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "SELECT":
            {
                if (m.Layers.SelectedLayer != null)
                {
                    System.Drawing.Point pt1 = new System.Drawing.Point(Convert.ToInt32(arg[1]), Convert.ToInt32(arg[2]));
                    System.Drawing.Point pt2 = new System.Drawing.Point(Convert.ToInt32(arg[3]), Convert.ToInt32(arg[4]));

                    Coordinate pm1 = m.PixelToProj(pt1);
                    Coordinate pm2 = m.PixelToProj(pt2);

                    Extent ex = new Extent(Math.Min(pm1.X, pm2.X), Math.Min(pm1.Y, pm2.Y),
                                           Math.Max(pm1.X, pm2.X), Math.Max(pm1.Y, pm2.Y));

                    IEnvelope MapEnv = m.Extent.ToEnvelope();

                    m.Layers.SelectedLayer.ClearSelection(out MapEnv);


                    m.Layers.SelectedLayer.ClearSelection();

                    IEnvelope affectedarea = null;

//                                m.Layers.SelectedLayer.Select(m.ViewExtents.ToEnvelope(), ex.ToEnvelope(), Symbology.SelectionMode.IntersectsExtent, out affectedarea);
                    m.Layers.SelectedLayer.Select(ex.ToEnvelope(), ex.ToEnvelope(), Symbology.SelectionMode.Intersects, out affectedarea);

                    returnCommand = "STRUCTURE";
                }
                else
                {
                    returnValue   = "<table><tr><td>Select a layer first.<p></td></tr><table>";
                    returnCommand = "POPUP";
//                                returnValue = "Select a layer first.";
//                                returnCommand = "ALERT";
                }
            }
            break;

            case "INFO":
            {
                System.Drawing.Point pt = new System.Drawing.Point(Convert.ToInt32(arg[2]), Convert.ToInt32(arg[3]));
                Coordinate           pm = m.PixelToProj(pt);

                Extent ex = new Extent(pm.X, pm.Y, pm.X, pm.Y);

                if (m.Layers.SelectedLayer != null)
                {
                    FeatureSet fs = m.Layers.SelectedLayer.DataSet as FeatureSet;

//                                List<IFeature> flist = fs.Select(ex);  //returns empty list when IndexMode == false
                    List <int> flist = fs.SelectIndices(ex);

                    int n = flist.Count;

//                                returnValue = "<table border='1'>";  //looks goofy
                    returnValue = "<table>";

                    if (n > 0)
                    {
                        for (int i = 0; i < fs.DataTable.Columns.Count; i++)
                        {
                            returnValue += "<tr><td>" + fs.DataTable.Columns[i].ColumnName +
//                                                       "</td><td>" + flist[0].DataRow[i].ToString() + "</td></tr>";
                                           "</td><td>" + fs.GetFeature(flist[0]).DataRow[i].ToString() + "</td></tr>";
                        }

                        returnValue  += "</table>";
                        returnCommand = "POPUP";
                    }
                }
                else
                {
                    returnValue   = "<table><tr><td>Select a layer first.<p></td></tr><table>";
                    returnCommand = "POPUP";
//                                returnValue = "Select a layer first.";
//                                returnCommand = "ALERT";
                }
            }
            break;


            case "RESIZE":
            {
                Size NewSz    = new Size(Convert.ToInt32(arg[2]), Convert.ToInt32(arg[3]));
                Size ActualSz = ControlSize;

                if (ActualSz.Width == 0 || ActualSz.Height == 0)
                {
                    ControlSize = NewSz;

                    ZoomAll(ref m);

                    returnCommand = "STRUCTURE";
                }
                else
                {
                    if (NewSz != ActualSz)
                    {
                        ControlSize = NewSz;

                        returnCommand = "STRUCTURE";
                    }
                    else
                    {
                        returnCommand = "NOTHING";
                    }
                }
            }
            break;

            case "ZOOMRECT":
            {
                System.Drawing.Point pt1 = new System.Drawing.Point(Convert.ToInt32(arg[1]), Convert.ToInt32(arg[2]));
                System.Drawing.Point pt2 = new System.Drawing.Point(Convert.ToInt32(arg[3]), Convert.ToInt32(arg[4]));

                Coordinate pm1 = m.PixelToProj(pt1);
                Coordinate pm2 = m.PixelToProj(pt2);

                Extent x = new Extent(Math.Min(pm1.X, pm2.X),
                                      Math.Min(pm1.Y, pm2.Y),
                                      Math.Max(pm1.X, pm2.X),
                                      Math.Max(pm1.Y, pm2.Y));

                m.ViewExtents = x;
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "ZOOMIN":
            {
                int x = Convert.ToInt32(arg[1]);
                int y = Convert.ToInt32(arg[2]);

                System.Drawing.Point pntZoomAndCenter = new System.Drawing.Point((x - m.Size.Width / 2), (y - m.Size.Height / 2));
                m.MapFrame.Pan(pntZoomAndCenter);
                m.ZoomIn();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "ZOOMOUT":
            {
                int x = Convert.ToInt32(arg[1]);
                int y = Convert.ToInt32(arg[2]);

                System.Drawing.Point pnt = new System.Drawing.Point((x - m.Size.Width / 2), (y - m.Size.Height / 2));

                m.MapFrame.Pan(pnt);
                m.ZoomOut();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "PAN":
            {
                int x = Convert.ToInt32(arg[1]);
                int y = Convert.ToInt32(arg[2]);

// not used:                System.Drawing.Point pnt = new System.Drawing.Point((x - m.Size.Width / 2), (y - m.Size.Height / 2));

                m.MapFrame.Pan(new System.Drawing.Point(x, y));
                returnCommand = "REFRESH";
            }
            break;

            case "WHEELIN":
            {
                m.ZoomIn();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "WHEELOUT":
            {
                m.ZoomOut();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "DATAGRID":          //moved to here from RaisePostBackEvent
            {
                if (m.Layers.SelectedLayer != null)
                {
                    //string script=null;

                    IMapFeatureLayer MFL = (IMapFeatureLayer)m.Layers.SelectedLayer;

                    int n = MFL.Selection.Count;

                    FeatureSet fs;
                    DataTable  rs;
                    if (n > 0)
                    {
                        fs = MFL.Selection.ToFeatureSet();
                        rs = fs.DataTable;
                    }
                    else
                    {
                        fs = MFL.DataSet as FeatureSet;
                        rs = fs.DataTable;
                    }

                    if (DataOnGrid != null)              //Let event handler display grid?
                    {
                        DataGridEventArgs e = new DataGridEventArgs();
                        e.Recordsource = rs;
                        DataOnGrid(this, e);
                    }
                    else              //Display default HTML grid
                    {
                        returnValue = "<table border='1'><tr>";

                        for (int h = 0; h < rs.Columns.Count; h++)
                        {
                            returnValue += "<th>" + rs.Columns[h].ColumnName + "</th>";
                        }
                        returnValue += "</tr>";

                        string rowHtml;
                        for (int r = 0; r < rs.Rows.Count; r++)
                        {              //note: _much_ faster if build each row separately
                            rowHtml = "<tr>";
                            for (int c = 0; c < rs.Columns.Count; c++)
                            {
                                rowHtml += "<td>" + fs.GetFeature(r).DataRow[c].ToString() + "</td>";
                            }
                            rowHtml     += "</tr>";
                            returnValue += rowHtml;
                        }
                        returnValue  += "</table>";
                        returnCommand = "POPUP";
                    }
                }
                else
                {
                    returnValue   = "<table><tr><td>Select a layer first.<p></td></tr><table>";
                    returnCommand = "POPUP";
                }
            }
            break;

            case "ADDFEATURE":          //moved to here from RaisePostBackEvent
            {
                int num = Convert.ToInt32(arg[1]);

                System.Drawing.Point pt = new System.Drawing.Point();
                Coordinate[]         pm = new Coordinate[num];

                for (int i = 0; i < num; i++)
                {
                    pt.X = Convert.ToInt32(arg[(i + 1) * 2]);
                    pt.Y = Convert.ToInt32(arg[(i + 1) * 2 + 1]);

                    pm[i] = m.PixelToProj(pt);
                }

                if (m.Layers.SelectedLayer != null)
                {
                    FeatureSet  fs = m.Layers.SelectedLayer.DataSet as FeatureSet;
                    Feature     f;
                    FeatureType ft = FeatureType.Unspecified;

                    IMapFeatureLayer MFL = (IMapFeatureLayer)m.Layers.SelectedLayer;

                    if (MFL.GetType() == typeof(MapPointLayer))
                    {
                        ft = FeatureType.Point;
                    }
                    if (MFL.GetType() == typeof(MapLineLayer))
                    {
                        ft = FeatureType.Line;
                    }
                    if (MFL.GetType() == typeof(MapPolygonLayer))
                    {
                        ft = FeatureType.Polygon;
                    }

                    if (ft != FeatureType.Unspecified)
                    {
                        f = new Feature(ft, pm);

                        try
                        {
                            if (AddFeature != null)
                            {
                                AddFeature(this, fs, f);
                            }
                            else
                            {
                                try
                                {
                                    fs.AddFeature(f);
                                    fs.Save();
                                }
                                catch
                                {
                                    fs.Features.Remove(f);
                                    throw;              //re-throw exception
                                }
                                fs.InitializeVertices();
                            }
                            //Apparently have to force recreating labels when add feature.
                            if (MFL.LabelLayer != null)
                            {
                                // Recreating label layer works.
//                                            MapLabelLayer NewLabels = new MapLabelLayer();
//                                            NewLabels.Symbology = MFL.LabelLayer.Symbology;
//                                            NewLabels.Symbolizer = MFL.LabelLayer.Symbolizer;
//                                            MFL.LabelLayer = NewLabels;
                                // Recreating just labels also works.
                                MFL.LabelLayer.CreateLabels();
                            }
                            returnCommand = "FORCEREFRESH";
                        }
                        catch (Exception e)
                        {
                            returnValue   = "Unable to save feature.<p>" + e.Message;
                            returnCommand = "POPUPANDREFRESH";              //erase new shape too
                        }

//                                    fs.IndexMode = true;
                        //Adding a feature sets FeatureSet.IndexMode to false,
                        // causing fs.Select above in INFO case to return a list
                        // with Count == 0. One workaround is to set IndexMode
                        // back to true. This does cause all existing labels
                        // to disapper with refresh, but recreating label layer
                        // above fixed that. (Also tried InitializeVertices,
                        // InvalidateEnvelope, InvalidateVertices, UpdateExtents, etc.)
                        // Oops, setting IndexMode back to true corrupts shapes...
                    }
                }
            }
            break;
            }

            //ControlMap = m;
            System.Web.HttpContext.Current.Session[(string)ViewState[ClientID]] = m;

            if (returnCommand == "STRUCTURE")
            {
                returnValue = redraw(ref m);

                if (OnRedraw != null)
                {
                    OnRedraw(this);
                }
            }

            if (returnCommand == "REFRESH" | returnCommand == "REFRESHANDHIDEBUFFER")
            {
                returnValue = refresh(ref m);

                if (OnRedraw != null)
                {
                    OnRedraw(this);
                }
            }
        }