Ejemplo n.º 1
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);
            }

        }
Ejemplo n.º 2
0
        public void RaisePostBackEvent(string eventArgument)
        {

            GDIMap m = ControlMap;

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

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

            switch (cmd)
            {

                case "CLICK":
                    {

                        if (MapClick != null)
                        {
                            System.Drawing.Point pt1 = new System.Drawing.Point(Convert.ToInt32(arg[2]), Convert.ToInt32(arg[3]));
                            Coordinate pm1 = m.PixelToProj(pt1);

                            MapClickEventArgs mc = new MapClickEventArgs();

                            mc.button = Convert.ToInt32(arg[1]); ;
                            mc.x = pm1.X;
                            mc.y = pm1.Y;

                            MapClick(this, mc);
                        }

                    }
                    break;

                case "ADDFEATURE":
                    {
                        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);
                        }

                        
                        FeatureSet fs = m.Layers.SelectedLayer.DataSet as FeatureSet;
                        Feature f;
                        FeatureType ft = FeatureType.Unspecified;

                        if (m.Layers.SelectedLayer != null)
                        {
                            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);

                                if (AddFeature != null)
                                {
                                    AddFeature(this, fs, f);
                                }
                                else
                                {
                                    fs.AddFeature(f);
                                    fs.InitializeVertices();
                                }
                            }
                        }

                    }
                    break;

                case "DATAGRID":
                    {
                        if (m.Layers.SelectedLayer != null)
                        {
                            //string script=null;

                            if (DataOnGrid != null)
                            {
                                DataGridEventArgs e = new DataGridEventArgs();
                                IMapFeatureLayer MFL = (IMapFeatureLayer)m.Layers.SelectedLayer;

                                int n = MFL.Selection.Count;

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

                                DataOnGrid(this, e);

                            }

                        }

                    }
                    break;

                case "FORCEREFRESH":
                    {
                        //simply do nothing 
                    }
                    break;

            }
        }