Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        private bool InitWorkingLayer()
        {
            MapInfo.Mapping.Map map = null;

            // Get the map
            if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
                (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
            {
                return(false);
            }

            // Make sure the Find layer's MemTable exists
            MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(_workingLayerName);
            if (table == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(_workingLayerName);
                ti.Temporary = true;
                // Add the Geometry column
                Column col = new MapInfo.Data.GeometryColumn(map.GetDisplayCoordSys());
                col.Alias    = "obj";
                col.DataType = MIDbType.FeatureGeometry;
                ti.Columns.Add(col);
                // Add the Style column
                col          = new MapInfo.Data.Column();
                col.Alias    = "MI_Style";
                col.DataType = MIDbType.Style;
                ti.Columns.Add(col);
                table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
            }
            if (table == null)
            {
                return(false);
            }

            // Make sure the Find layer exists
            MapInfo.Mapping.FeatureLayer layer = (MapInfo.Mapping.FeatureLayer)map.Layers[_workingLayerName];
            if (layer == null)
            {
                layer = new MapInfo.Mapping.FeatureLayer(table, _workingLayerName, _workingLayerName);
                map.Layers.Insert(0, layer);
            }
            if (layer == null)
            {
                return(false);
            }

            // Delete the find object.  There should only be one object in this table.
            (layer.Table as ITableFeatureCollection).Clear();

            return(true);
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            MapInfo.Mapping.Map myMap = GetMapObj();
            if (Session.IsNewSession)
            {
                AppStateManager stateManager = new AppStateManager();
                stateManager.ParamsDictionary[AppStateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;
                MapInfo.WebControls.StateManager.PutStateManagerInSession(stateManager);

                // Add customized web tools
                // Below line will put controlModel into HttpSessionState.
                MapInfo.WebControls.MapControlModel controlModel = MapControlModel.SetDefaultModelInSession();
                controlModel.Commands.Add(new AddPinPointCommand());
                controlModel.Commands.Add(new ClearPinPointCommand());
                controlModel.Commands.Add(new ModifiedRadiusSelectionCommand());

                /****** Set the initial state of the map  *************/
                // Clear up the temp layer left by other customer requests.
                if (myMap != null)
                {
                    if (myMap.Layers[SampleConstants.TempLayerAlias] != null)
                    {
                        myMap.Layers.Remove(SampleConstants.TempLayerAlias);
                    }
                }
                // Need to clean up "dirty" temp table left by other customer requests.
                MapInfo.Engine.Session.Current.Catalog.CloseTable(SampleConstants.TempTableAlias);
                // Need to clear the DefautlSelection.
                MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();

                // Creat a temp table and AddPintPointCommand will add features into it.
                MapInfo.Data.TableInfoMemTable ti = new MapInfo.Data.TableInfoMemTable(SampleConstants.TempTableAlias);
                // Make the table mappable
                ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
                ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());

                MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
                // Create a new FeatureLayer based on the temp table, so we can see the temp table on the map.
                myMap.Layers.Insert(0, new FeatureLayer(table, "templayer", SampleConstants.TempLayerAlias));

                // This step is needed because you may get a dirty map from mapinfo Session.Current which is retrived from session pool.
                myMap.Zoom   = new MapInfo.Geometry.Distance(25000, MapInfo.Geometry.DistanceUnit.Mile);
                myMap.Center = new MapInfo.Geometry.DPoint(27775.805792979896, -147481.33999999985);
            }

            MapInfo.WebControls.StateManager.GetStateManagerFromSession().RestoreState();
        }
Ejemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="map"></param>
 /// <returns></returns>
 public static bool ZoomAll(MapInfo.Mapping.Map map)
 {
     map.SetView(map.Layers.Bounds, map.GetDisplayCoordSys());
     return(true);
 }