Esempio n. 1
0
        /// <summary>
        /// Selects all of the features whose centroids lie within a given polygon.
        /// </summary>
        /// <remarks>This method searches for all features whose centroids are within the given polygon and updates the
        /// default selection.</remarks>
        /// <param name="mapAlias">MapAlias of the map.</param>
        /// <param name="points">Array of points forming the polygon.</param>
        public virtual void PolygonSelection(string mapAlias, System.Drawing.Point[] points)
        {
            Map map = GetMapObj(mapAlias);

            // Convert them to map coordinates
            MapInfo.Geometry.DPoint [] dpnts = new MapInfo.Geometry.DPoint[points.Length];
            for (int indx = 0; indx < points.Length; indx++)
            {
                map.DisplayTransform.FromDisplay(points[indx], out dpnts[indx]);
            }

            // Create a polygon from these points
            CoordSys dispCSys = map.GetDisplayCoordSys();
            CoordSys geomCSys =
                Session.Current.CoordSysFactory.CreateCoordSys(dispCSys.Type, dispCSys.Datum, dispCSys.Units, dispCSys.OriginLongitude, dispCSys.OriginLatitude, dispCSys.StandardParallelOne, dispCSys.StandardParallelTwo, dispCSys.Azimuth, dispCSys.ScaleFactor, dispCSys.FalseEasting, dispCSys.FalseNorthing, dispCSys.Range, map.Layers.Bounds, dispCSys.AffineTransform);

            MapInfo.Geometry.MultiPolygon mp = new MapInfo.Geometry.MultiPolygon(geomCSys, MapInfo.Geometry.CurveSegmentType.Linear, dpnts);

            // Search and select
            SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWithinGeometry(mp, ContainsType.Centroid);

            Session.Current.Selections.DefaultSelection.Clear();
            IMapLayerFilter _selFilter = MapLayerFilterFactory.FilterForTools(
                map, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true),
                "MapInfo.Tools.MapToolsDefault.SelectLayers", null);

            ITableEnumerator table = map.Layers.GetTableEnumerator(_selFilter);

            if (table != null)                 // null will be returned is select enabled layer is not visible, thus non-selectable
            {
                Session.Current.Catalog.Search(table, si, Session.Current.Selections.DefaultSelection, ResultSetCombineMode.AddTo);
            }
        }
Esempio n. 2
0
        void mapControl1_MouseMove(object sender, MouseEventArgs e)
        {
            if (false)
            {
                System.Drawing.PointF DisplayPoint = new PointF(e.X, e.Y);
                MapInfo.Geometry.DisplayTransform converter = this.mapControl1.Map.DisplayTransform;
                MapInfo.Geometry.DPoint MapPoint = new MapInfo.Geometry.DPoint();

                converter.FromDisplay(DisplayPoint, out MapPoint);
                double pX = Math.Round(MapPoint.x, 6);
                double pY = Math.Round(MapPoint.y, 6);
                string East = "��";
                string West = "��";
                string Longitude = "����";
                string North = "  ��";
                string South = "  ��";
                string Latitude = "��";

                DPoint p = MapPoint;// selectionFeature[0].Geometry.Centroid;
                //// mapControl1.Map.SetView(new DPoint(p.x, p.y),
                ////Session.Current.CoordSysFactory.CreateLongLat(DatumID.WGS84),
                ////108851.80);

                System.Drawing.Point pntClick = new System.Drawing.Point(e.X, e.Y);
                DPoint pntCenter = new DPoint(0, 0);
                this.mapControl1.Map.DisplayTransform.FromDisplay(pntClick, out pntCenter);
                this.mapControl1.Map.Center = pntCenter;

                if (pX > 0)
                {
                    if (pX <= 180)
                    {
                        toolStripStatusLabel1.Text = string.Format(East + Longitude + ":{0}", pX);
                    }
                    else
                    {
                        toolStripStatusLabel1.Text = string.Format(East + Longitude + ":");
                    }
                }
                else if (pX < 0)
                {
                    if (pX >= -180)
                    {
                        toolStripStatusLabel1.Text = string.Format(West + Longitude + ":{0}", Math.Abs(pX));
                    }
                    else
                    {
                        toolStripStatusLabel1.Text = string.Format(West + Longitude + ":");
                    }
                }
                else
                {
                    toolStripStatusLabel1.Text = string.Format(Longitude + ":{0}", Math.Abs(pX));
                }

                if (pY > 0)
                {
                    if (pY <= 90)
                    {
                        toolStripStatusLabel1.Text += string.Format(North + Latitude + ":{0}", pY);
                    }
                    else
                    {
                        toolStripStatusLabel1.Text += string.Format(North + Latitude + ":");
                    }
                }
                else if (pY < 0)
                {
                    if (pY >= -90)
                    {
                        toolStripStatusLabel1.Text += string.Format(South + Latitude + ":{0}", Math.Abs(pY));
                    }
                    else
                    {
                        toolStripStatusLabel1.Text += string.Format(South + Latitude + ":");
                    }
                }
                else
                {
                    toolStripStatusLabel1.Text += string.Format(Latitude + ":{0}", Math.Abs(pY));
                }
            }
        }
Esempio n. 3
0
        public override void Process()
        {
            MapControlModel model = MapControlModel.GetModelFromSession();

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

            string strUID  = HttpContext.Current.Request["uid"];
            string strText = HttpContext.Current.Request["Name"];

            System.Drawing.Point[] points = this.ExtractPoints(this.DataString);
            System.Drawing.Color   clr    = UserMap.stringToColor(HttpContext.Current.Request["Color"]);
            int lineWidth = Int32.Parse(HttpContext.Current.Request["LineWidth"]);

            if (lineWidth <= 0)
            {
                lineWidth = 2;
            }

            int    cnt = 0;
            int    len = points.Length;
            double x   = 0;
            double y   = 0;

            MapInfo.Geometry.DPoint[] dPoints = new MapInfo.Geometry.DPoint[len];

            for (cnt = 0; cnt < len; cnt++)
            {
                x            = (double)points[cnt].X / 10000;
                y            = (double)points[cnt].Y / 10000;
                dPoints[cnt] = new MapInfo.Geometry.DPoint(x, y);
            }

            UserMap.DeleteFeature(map, Constants.TempLayerAlias, strUID);
            UserMap.AddLine(map, Constants.TempLayerAlias, strUID, strText, dPoints, clr, lineWidth);

            /*
             * FeatureLayer layer = map.Layers[Constants.TempLayerAlias] as FeatureLayer;
             * if (layer == null)
             * {
             *  return;
             * }
             *
             * int cnt = 0;
             * int len = points.Length;
             * double x =0;
             * double y = 0;
             *
             * MapInfo.Geometry.DPoint[] dPoints = new MapInfo.Geometry.DPoint[len];
             *
             * for (cnt = 0; cnt < len; cnt++)
             * {
             *          x = points[cnt].X/10000;
             *          y = points[cnt].Y/10000;
             *  dPoints[cnt] = new MapInfo.Geometry.DPoint(x, y);
             * }
             *
             *
             * //创建线图元及其样式
             * FeatureGeometry fg = new MultiCurve(layer.CoordSys, CurveSegmentType.Linear, dPoints);
             * CompositeStyle cs = new MapInfo.Styles.CompositeStyle(
             *  new SimpleLineStyle(new LineWidth(linewidth, LineWidthUnit.Pixel), 2, Color.Red)
             * );
             *
             * MapInfo.Data.Feature feature = new MapInfo.Data.Feature(layer.Table.TableInfo.Columns);
             *
             * feature.Geometry = fg;
             * feature.Style = cs;
             * feature["name"] = name;
             *
             * //将线图元加入图层
             * layer.Table.InsertFeature(feature);
             */
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
            return;
        }