/// <summary>
        /// This method gets the map object out of the mapfactory with given mapalias and
        /// Adds a point feature into a temp layer, exports it to memory stream and streams it back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            // Extract points from the string
            System.Drawing.Point [] points = this.ExtractPoints(this.DataString);

            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);

            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null)
            {
                return;
            }

            // There will be only one point, convert it to spatial
            MapInfo.Geometry.DPoint point;
            map.DisplayTransform.FromDisplay(points[0], out point);

            IMapLayer lyr = map.Layers[SampleConstants.TempLayerAlias];

            if (lyr == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(SampleConstants.TempTableAlias);
                // Make the table mappable
                ti.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()));
                ti.Columns.Add(ColumnFactory.CreateStyleColumn());

                Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
                map.Layers.Insert(0, new FeatureLayer(table, "templayer", SampleConstants.TempLayerAlias));
            }
            lyr = map.Layers[SampleConstants.TempLayerAlias];
            if (lyr == null)
            {
                return;
            }
            FeatureLayer fLyr = lyr as FeatureLayer;

            MapInfo.Geometry.Point geoPoint = new MapInfo.Geometry.Point(map.GetDisplayCoordSys(), point);
            // Create a Point style which is a red pin point.
            SimpleVectorPointStyle vs = new SimpleVectorPointStyle();

            vs.Code       = 67;
            vs.Color      = Color.Red;
            vs.PointSize  = Convert.ToInt16(24);
            vs.Attributes = StyleAttributes.PointAttributes.BaseAll;
            vs.SetApplyAll();

            // Create a Feature which contains a Point geometry and insert it into temp table.
            Feature pntFeature = new Feature(geoPoint, vs);

            MapInfo.Data.Key key = fLyr.Table.InsertFeature(pntFeature);

            // Send contents back to client.
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
Example #2
0
        private void tsmiAdd_Click(object sender, EventArgs e)
        {
            AddJKINFO frmAddJKINFO = new AddJKINFO();

            if (frmAddJKINFO.ShowDialog() == DialogResult.OK)
            {
                Table   tEditTable = (mapControl1.Map.Layers["JKINFO"] as FeatureLayer).Table;
                Feature f          = new Feature(tEditTable.TableInfo.Columns);
                DPoint  dp         = ConvertTOJWDu(pNodePoint);
                f.Geometry = new MapInfo.Geometry.Point(mapControl1.Map.GetDisplayCoordSys(), dp);
                //f.GeometryIndex = 4;
                f.Style = sDefault;
                foreach (DataRow dr in SysInfo.TypeDataTable.Rows)
                {
                    int iType = Convert.ToInt32(dr["JKType"]);
                    if (frmAddJKINFO.OBJJKINFO.SBLX == iType)
                    {
                        f.Style = new MapInfo.Styles.CompositeStyle(new MapInfo.Styles.BitmapPointStyle(dr["BMPFileName"].ToString(), BitmapStyles.None, Color.Blue, 10));
                    }
                }
                f["NDH"] = frmAddJKINFO.OBJJKINFO.NDH;
                f["SJ"]  = frmAddJKINFO.OBJJKINFO.SJ;
                f["DW"]  = frmAddJKINFO.OBJJKINFO.DW;
                MapInfo.Data.Key ftrkey = tEditTable.InsertFeature(f);
                //MessageBox.Show(f.Key.Value.ToString());

                ///查询方法
                //SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("mi_key='8'");
                //IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(tEditTable, si); //JKINFO

                //frmAddJKINFO.OBJJKINFO.MAPINFO_ID = Convert.ToInt32(ftrkey.Value);

                JKINFOBLL bllJKINFO = new JKINFOBLL();

                String MDBFileName = (SysInfo.HTDBInfo[cbMaps.Text] as DBInfo).MDBPath;
                if (bllJKINFO.AddJKINFO(frmAddJKINFO.OBJJKINFO, MDBFileName))
                {
                    MessageBox.Show("保存成功!");
                }
                else
                {
                    MessageBox.Show("保存失败!");
                    tEditTable.DeleteFeature(ftrkey);
                }
            }
        }