Map 组件接口,用以访问 SuperMap iServer 地图服务组件中的REST服务,封装了与地图相关的一系列功能。
只能对 SuperMap REST 接口类型服务的访问。 实例化Map对象时需要使用明确的地图服务组件地址(例如:http://localhost:8090/iserver/services/map-world/rest/")
 private void btnCheck_Click(object sender, EventArgs e)
 {
     try
     {
         Map map = new Map(this.tbUrl.Text);
         List<string> mapNames = map.GetMapNames();
         if (mapNames != null && mapNames.Count > 0)
         {
             this.cbnMapNames.Items.Clear();
             foreach(string mapName in mapNames)
             {
                 this.cbnMapNames.Items.Add(mapName);
             }
             this.cbnMapNames.SelectedIndex = 0;
             this.btnOk.Enabled = true;
         }
     }
     catch (ArgumentNullException argumengNullException)
     {
         MessageBox.Show(argumengNullException.Message);
     }
     catch (ServiceException serviceException)
     {
         MessageBox.Show(serviceException.Message);
     }
 }
Beispiel #2
0
        public void GetDefaultMapParameterTest_Normal()
        {
            Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
            MapParameter mapParameter = map.GetDefaultMapParameter("世界地图");

            Assert.IsTrue(mapParameter.Name == "世界地图");
            Assert.IsTrue(mapParameter.Layers.Count == 14);
        }
Beispiel #3
0
        public void GetMapNamesTest_Normal()
        {
            Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
            List<string> mapNames = map.GetMapNames();

            Assert.IsTrue(mapNames.Count == 5);
            Assert.IsTrue(mapNames[0] == "World");
            Assert.IsTrue(mapNames[1] == "世界地图_Day");
        }
        public QuerySettingForm(string mapUrl, string mapName)
        {
            InitializeComponent();

            this._mapName = mapName;
            this._mapUrl = mapUrl;

            Map map = new Map(_mapUrl);
            MapParameter defaultMapParameter = map.GetDefaultMapParameter(mapName);
            InitLayer(defaultMapParameter);
        }
        public SQLForm(string mapUrl, string mapName)
        {
            InitializeComponent();
            this._mapName = mapName;
            this._mapUrl = mapUrl;

            _map = new Map(_mapUrl);
            defaultMapParameter = _map.GetDefaultMapParameter(mapName);

            InitializeSQL();
        }
 private void InitLayer(MapParameter mapParameter)
 {
     this.clbLayers.Items.Clear();
     Map map = new Map(_mapUrl);
     if (mapParameter != null)
     {
         for (int i = 0; i < mapParameter.Layers.Count; i++)
         {
             this.clbLayers.Items.Add(new LayerItem(mapParameter.Layers[i].Name, mapParameter.Layers[i].Caption));
         }
     }
 }
        public SQLForm(string mapUrl, string mapName, MapControl mapControl)
        {
            InitializeComponent();
            this._mapName = mapName;
            this._mapUrl = mapUrl;

            _map = new Map(_mapUrl);
            defaultMapParameter = _map.GetDefaultMapParameter(mapName);
            _mapControl = mapControl;
            publicResultForm = new PublicResultForm();
            publicResultForm.Name = "QueryBySql";
            publicResultForm.Text = "SQL查询结果";
            publicResultForm.MapControl = mapControl;
            InitializeSQL();
        }
Beispiel #8
0
 public void MapConstructTest()
 {
     string paramName = string.Empty;
     try
     {
         Map map = new Map(null);
     }
     catch (ArgumentNullException e)
     {
         paramName = e.ParamName;
     }
     finally
     {
         Assert.IsTrue(string.Equals(paramName, "serviceUrl", StringComparison.InvariantCulture));
     }
 }
Beispiel #9
0
 public void GetDefaultMapParameterTest_NoMapName()
 {
     Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
     string paramName = string.Empty;
     try
     {
         MapParameter mapParameter = map.GetDefaultMapParameter("");
     }
     catch (ArgumentNullException e)
     {
         paramName = e.ParamName;
     }
     finally
     {
         Assert.IsTrue(string.Equals(paramName, "mapName", StringComparison.CurrentCulture));
     }
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string strMapUrl = this.NavigationContext.QueryString["url"];

            _tileLayer = new TiledDynamicRESTLayer();
            _tileLayer.Url = strMapUrl;
            this.myMap.Layers.Add(_tileLayer);
            _queryLayer = new FeaturesLayer();
            _queryLayer.ID = "QueryLayer";
            this.myMap.Layers.Add(_queryLayer);

            string[] splitItems = _tileLayer.Url.Split(new char[] { '/' });
            mapName = _tileLayer.Url.Substring(_tileLayer.Url.LastIndexOf('/') + 1);
            int restIndex = _tileLayer.Url.LastIndexOf("maps");
            string compomentUrl = _tileLayer.Url.Substring(0, restIndex);
            _queryMap = new Connector.Map(compomentUrl);
        }
        public QuerySettingForm(string mapUrl, string mapName)
        {
            InitializeComponent();

            this._mapName = mapName;
            this._mapUrl = mapUrl;

            Map map = new Map(_mapUrl);
            MapParameter defaultMapParameter = map.GetDefaultMapParameter(mapName);

            bool isNew = false;
            if (QuerySetting.MapUrl != mapUrl || QuerySetting.MapName != mapName)
            {
                isNew = true;
                QuerySetting.MapName = mapName;
                QuerySetting.MapUrl = mapUrl;
            }

            InitLayer(defaultMapParameter,isNew);
        }
Beispiel #12
0
        public void GetTileTest_Normal()
        {
            Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");

            TileInfo tileInfo = new TileInfo();
            tileInfo.TileIndex = new TileIndex() { ColIndex = 2, RowIndex = 1 };
            tileInfo.Height = 256;
            tileInfo.Width = 256;
            tileInfo.Scale = 0.0000002;

            MapImage mapImage = map.GetTile("世界地图", tileInfo, null);

            using (MemoryStream memoryStream = new MemoryStream(mapImage.ImageData))
            {
                Bitmap bmp = new Bitmap(memoryStream);
                System.Drawing.Color systemColor = bmp.GetPixel(136, 48);
                Assert.IsTrue(systemColor.R == 153);
                Assert.IsTrue(systemColor.G == 179);
                Assert.IsTrue(systemColor.B == 204);
            }
        }
Beispiel #13
0
 public void GetResourceTest_Marker()
 {
     Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
     string mapName = "世界地图";
     ResourceParameter parameter = new ResourceParameter();
     parameter.Type = ResourceType.SYMBOLMARKER;
     ImageOutputOption option = new ImageOutputOption();
     option.ImageOutputFormat = ImageOutputFormat.PNG;
     option.ImageReturnType = ImageReturnType.URL;
     ResourceImage image = map.GetResource(mapName, parameter, option);
     Assert.AreEqual(image.ImageUrl, "http://192.168.116.114:8090/iserver/output/resources/%E4%B8%96%E7%95%8C%E5%9C%B0%E5%9B%BE/SYMBOLMARKER/0_1160020228.png");
 }
        private void tsbOpen_Click(object sender, EventArgs e)
        {
            if (this._initForm == null)
            {
                this._initForm = new InitForm();
            }
            if (this._initForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Map map = new Map(this._initForm.MapUrl);
                MapParameter defaultMapParameter = map.GetDefaultMapParameter(this._initForm.SelectedMapName);
                double[] mapScales = new double[21];
                mapScales[0] = defaultMapParameter.Scale / 6;
                mapScales[1] = defaultMapParameter.Scale / 4;
                mapScales[2] = defaultMapParameter.Scale / 2;
                mapScales[3] = defaultMapParameter.Scale;
                for (int i = 0; i < 17; i++)
                {
                    mapScales[i + 4] = mapScales[i + 3] * 2;
                }
                _gMapProvider = new SuperMapProvider(this._initForm.MapUrl, this._initForm.SelectedMapName, mapScales);
                //_gMapProvider = new SuperMapProvider(this._initForm.MapUrl, this._initForm.SelectedMapName, 256, "png", null);
                this.mapControl1.Init();
                this.mapControl1.MapProvider = _gMapProvider;
                this._mapUrl = this._initForm.MapUrl;
                this._mapName = this._initForm.SelectedMapName;
                this.mapControl1.DragButton = System.Windows.Forms.MouseButtons.Left;
                this.mapControl1.Position = new PointLatLng(defaultMapParameter.Center.Y, defaultMapParameter.Center.X);
                this.mapControl1.MinZoom = 0;
                this.mapControl1.MaxZoom = mapScales.Length - 1;
                this.mapControl1.Zoom = 3;
                this.mapControl1.ReloadMap();

                //工具条按钮可见。
                for (int i = 0; i < this.toolStrip1.Items.Count; i++)
                {
                    this.toolStrip1.Items[i].Enabled = true;
                }
                for (int i = 0; i < this.tsbDropdownbtn.DropDownItems.Count; i++)
                {
                    if (this.tsbDropdownbtn.DropDownItems[i].Name == "tsbtnQuerySetting")
                        this.tsbDropdownbtn.DropDownItems[i].Enabled = true;
                    else this.tsbDropdownbtn.DropDownItems[i].Enabled = false;
                    this.tsbDropdownbtn.DropDownItems["sQLQuery"].Enabled = true;
                }
            }
        }
        public iServerSchema(string serviceUrl, string mapName, uint tileSize, string format, double[] scales)
        {
            Name = "iServer";
            Format = format;
            Srs = "EPSG:4326";

            Map map = new Map(serviceUrl);
            SuperMap.Connector.Utility.MapParameter mapParameter = map.GetDefaultMapParameter(mapName);

            this.Extent = new Extent(mapParameter.Bounds.LeftBottom.X, mapParameter.Bounds.LeftBottom.Y,
                mapParameter.Bounds.RightTop.X, mapParameter.Bounds.RightTop.Y);
            this.Width = (int)tileSize;
            this.Height = (int)tileSize;
            this.Format = format;
            this.OriginX = mapParameter.Bounds.LeftBottom.X;
            this.OriginY = mapParameter.Bounds.RightTop.Y;
            this.Axis = AxisDirection.InvertedY;

            for (int i = 0; i < scales.Length; i++)
            {
                double referViewBoudnsWidth = mapParameter.ViewBounds.RightTop.X - mapParameter.ViewBounds.LeftBottom.X;
                double referViewBoundsHeight = mapParameter.ViewBounds.RightTop.Y - mapParameter.ViewBounds.LeftBottom.X;
                double referViewerWidth = mapParameter.Viewer.RightBottom.X - mapParameter.Viewer.LeftTop.X;
                double referViewerHeight = mapParameter.Viewer.RightBottom.Y - mapParameter.Viewer.LeftTop.Y;
                double resolutionX = (mapParameter.Scale * referViewBoudnsWidth) / (scales[i] * referViewerWidth);
                double resolutionY = (mapParameter.Scale * referViewBoundsHeight) / (scales[i] * referViewerHeight);

                this.Resolutions.Add(new Resolution() { Id = i.ToString(), UnitsPerPixel = resolutionX });
            }
        }
        public byte[] GetTile(TileInfo tileInfo)
        {
            int iLevel = 0;
            if (!int.TryParse(tileInfo.Index.LevelId, out iLevel)) return null;
            double scale = _scales[iLevel];

            SuperMap.Connector.Utility.TileInfo iserverTileInfo = new SuperMap.Connector.Utility.TileInfo();
            iserverTileInfo.Height = this._tileSize;
            iserverTileInfo.Width = this._tileSize;
            iserverTileInfo.TileIndex = new SuperMap.Connector.Utility.TileIndex();
            iserverTileInfo.TileIndex.ColIndex = tileInfo.Index.Col;
            iserverTileInfo.TileIndex.RowIndex = tileInfo.Index.Row;
            iserverTileInfo.Scale = scale;

            SuperMap.Connector.Utility.ImageOutputOption option = new Utility.ImageOutputOption();
            option.Transparent = false;
            if (mapParameter != null)
            {
                option.Transparent = true;
            }

            Map map = new Map(this._serviceUrl);
            return map.GetTile(this._mapName, iserverTileInfo, option, this.mapParameter).ImageData;
        }
        public override void OnMapMouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (!_start) return;
            PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y);
            double mercatorX, mercatorY;
            Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mercatorX, out mercatorY);
            Point2D point2D = new Point2D(mercatorX, mercatorY);
            _point2Ds.Add(point2D);
            Map map = new Map(_mapUrl);

            QueryParameterSet queryParameterSet = new QueryParameterSet();
            queryParameterSet.ReturnContent = true;
            queryParameterSet.QueryOption = QuerySetting.QueryOption;
            queryParameterSet.ExpectCount = QuerySetting.ExceptionCount;
            queryParameterSet.QueryParams = new QueryParameter[QuerySetting.LayerNames.Count];
            for (int i = 0; i < QuerySetting.LayerNames.Count; i++)
            {
                queryParameterSet.QueryParams[i] = new QueryParameter();
                queryParameterSet.QueryParams[i].Name = QuerySetting.LayerNames[i];
            }

            Geometry geo = new Geometry();
            geo.Parts = new int[1] { _point2Ds.Count };
            geo.Points = _point2Ds.ToArray();
            geo.Type = GeometryType.REGION;
            QueryResult queryResult = null;
            try
            {
                queryResult = map.QueryByGeometry(_mapName, geo, SpatialQueryMode.INTERSECT, queryParameterSet);
            }
            catch (ServiceException serviceException)
            {
                MessageBox.Show(serviceException.Message);
            }

            //高亮显示查询结果。
            if (queryResult != null && queryResult.Recordsets != null && queryResult.Recordsets.Length > 0)
            {
                for (int i = 0; i < queryResult.Recordsets.Length; i++)
                {
                    if (queryResult.Recordsets[i] != null && queryResult.Recordsets[i].Features != null &&
                        queryResult.Recordsets[i].Features.Length > 0)
                    {
                        for (int j = 0; j < queryResult.Recordsets[i].Features.Length; j++)
                        {
                            if (queryResult.Recordsets[i].Features[j].Geometry != null && (
                                queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.POINT
                            || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.TEXT))
                            {
                                double lat, lng;
                                Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[0].X, queryResult.Recordsets[i].Features[j].Geometry.Points[0].Y, out lng, out lat);
                                PointLatLng pointLatLng = new PointLatLng(lat, lng);
                                GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(pointLatLng);
                                _highLightOverlay.Markers.Add(marker);
                            }
                            else if (queryResult.Recordsets[i].Features[j].Geometry != null &&
                                (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.REGION
                            || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.RECTANGLE))
                            {
                                if (queryResult.Recordsets[i].Features[j].Geometry.Parts != null)
                                //queryResult.Recordsets[i].Features[j].Geometry.Parts.Length > 1)
                                {
                                    int startIndex = 0;
                                    for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++)
                                    {
                                        List<PointLatLng> regionClient = new List<PointLatLng>();
                                        for (int n = startIndex; n < queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++)
                                        {
                                            double lat, lng;
                                            Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat);
                                            regionClient.Add(new PointLatLng(lat, lng));
                                        }
                                        GMapPolygonExtension hight = new GMapPolygonExtension("", regionClient, 2.0F,
               System.Drawing.Color.FromArgb(125, 255, 0, 0), System.Drawing.Color.FromArgb(50, 255, 0, 0));
                                        _highLightOverlay.Polygons.Add(hight);
                                        startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k];

                                    }
                                }
                            }
                            else if (queryResult.Recordsets[i].Features[j].Geometry != null &&
                                (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.LINE))
                            {
                                int startIndex = 0;
                                for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++)
                                {
                                    List<PointLatLng> regionClient = new List<PointLatLng>();
                                    for (int n = startIndex; n < startIndex + queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++)
                                    {
                                        double lat, lng;
                                        Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat);
                                        regionClient.Add(new PointLatLng(lat, lng));
                                    }
                                    GMapRouteExtension hight = new GMapRouteExtension("", regionClient,
               System.Drawing.Color.FromArgb(125, 255, 0, 0), 5.0F, false);
                                    _highLightOverlay.Routes.Add(hight);
                                    startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k];

                                }
                            }
                        }
                    }
                }
            }

            _gMapOverlay.Polygons.Clear();
            _points.Clear();
            _point2Ds.Clear();
            flag = false;
            _start = false;
            base.OnMapMouseDoubleClick(sender, e);
        }
        public override void OnLoad(GMapControl gMapControl)
        {
            _gMapControl = gMapControl;
            _gMapControl.Overlays.Add(_gMapOverlay);

            if (!_gMapControl.Overlays.Contains(_gMapOverlay))
                _gMapControl.Overlays.Add(_gMapOverlay);
            if (!_gMapControl.Overlays.Contains(_highLightOverlay))
                _gMapControl.Overlays.Add(_highLightOverlay);
            this._mapUrl = ((SuperMapProvider)gMapControl.MapProvider).ServiceUrl;
            this._mapName = ((SuperMapProvider)gMapControl.MapProvider).MapName;
            this._map = new Map(this._mapUrl);
        }
Beispiel #19
0
 public void GetResourceTest_LineID()
 {
     Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
     string mapName = "世界地图";
     ResourceParameter parameter = new ResourceParameter();
     parameter.Style = new Style();
     parameter.Style.LineSymbolID = 5;
     parameter.Type = ResourceType.SYMBOLLINE;
     ImageOutputOption option = new ImageOutputOption();
     option.ImageOutputFormat = ImageOutputFormat.PNG;
     option.ImageReturnType = ImageReturnType.URL;
     ResourceImage image = map.GetResource(mapName, parameter, option);
     Assert.AreEqual(image.ImageUrl, "http://192.168.116.114:8090/iserver/output/resources/%E4%B8%96%E7%95%8C%E5%9C%B0%E5%9B%BE/SYMBOLLINE/5_781806645.png");
 }
Beispiel #20
0
 public void MeasureDistanceTest_point2DsISEmply()
 {
     Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
     List<Point2D> point2Ds = new List<Point2D>();
     MeasureDistanceResult result = null;
     try
     {
         result = map.MeasureDistance("世界地图", point2Ds, Unit.KILOMETER);
     }
     catch (ArgumentException e)
     {
         Assert.AreEqual(e.Message, "参数 point2Ds 不合法,必须至少包含两个二维点。");
     }
 }
        private void InitLayer(MapParameter mapParameter,bool isNew)
        {
            this.clbLayers.Items.Clear();
            Map map = new Map(_mapUrl);
            if (mapParameter != null)
            {
                for (int i = 0; i < mapParameter.Layers.Count; i++)
                {
                    this.clbLayers.Items.Add(new LayerItem(mapParameter.Layers[i].Name, mapParameter.Layers[i].Caption));
                }
            }

            if (!isNew)
            {
                if (QuerySetting.LayerNames != null && QuerySetting.LayerNames.Count > 0)
                {
                    var v = (from item in this.clbLayers.Items.Cast<LayerItem>()
                             join l in QuerySetting.LayerNames
                                 on item.Name equals l
                             select item).ToList();
                    foreach (var i in v)
                    {
                        clbLayers.SetItemChecked(clbLayers.Items.IndexOf(i), true);
                    }
                }
                this.tbExceptionCount.Text = QuerySetting.ExceptionCount.ToString();
                if (QuerySetting.QueryOption == QueryOption.ATTRIBUTE)
                {
                    this.radioButton2.Checked = true;
                }
                else if (QuerySetting.QueryOption == QueryOption.GEOMETRY)
                {
                    this.radioButton1.Checked = true;
                }
                else
                {
                    this.radioButton3.Checked = true;
                }
            }
            else
            {
                clbLayers.SetItemChecked(0, true);
            }
            QuerySetting.Layers = mapParameter.Layers;
        }
Beispiel #22
0
 public void MeasureDistanceTest_KILOMETER()
 {
     Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
     string mapName = "World Map";
     List<Point2D> point2Ds = new List<Point2D>();
     Point2D point1 = new Point2D(23.00, 34.00);
     Point2D point2 = new Point2D(53.55, 12.66);
     Point2D point3 = new Point2D(73.88, 12.6);
     point2Ds.Add(point1);
     point2Ds.Add(point2);
     point2Ds.Add(point3);
     MeasureDistanceResult result = map.MeasureDistance(mapName, point2Ds, Unit.KILOMETER);
     Assert.AreEqual(result.Distance, 6098.3555766137142);
     Assert.AreEqual(result.Unit.ToString(), "KILOMETER");
 }
        public override void OnMapMouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (!_start) return;
            PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y);
            double mercatorX, mercatorY;
            Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mercatorX, out mercatorY);
            Point2D point2D = new Point2D(mercatorX, mercatorY);
            _point2Ds.Add(point2D);
            Map map = new Map(_mapUrl);

            QueryParameterSet queryParameterSet = new QueryParameterSet();
            queryParameterSet.ReturnContent = true;
            queryParameterSet.QueryOption = QueryOption;
            queryParameterSet.ExpectCount = this.ExceptionCount;
            queryParameterSet.QueryParams = new QueryParameter[this.clbLayers.CheckedItems.Count];
            for (int i = 0; i < this.clbLayers.CheckedItems.Count; i++)
            {
                queryParameterSet.QueryParams[i] = new QueryParameter();
                queryParameterSet.QueryParams[i].Name = (this.clbLayers.CheckedItems[i] as LayerItem).Name;
            }

            Geometry geo = new Geometry();
            geo.Parts = new int[1] { 1 };
            geo.Points = _point2Ds.ToArray();
            QueryResult queryResult = null;
            try
            {
                queryResult = map.QueryByGeometry(_mapName, geo, SpatialQueryMode.INTERSECT, queryParameterSet);
            }
            catch (ServiceException serviceException)
            {
                MessageBox.Show(serviceException.Message);
            }

            ShowResultSet(queryResult);
            _gMapOverlay.Polygons.Clear();
            _points.Clear();
            _point2Ds.Clear();
            flag = false;
            _start = false;

            base.OnMapMouseDoubleClick(sender, e);
        }
Beispiel #24
0
        public void GetTileTest_ByTempLayer()
        {
            Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");

            TileInfo tileInfo = new TileInfo();
            tileInfo.Scale = 0.00000002;
            tileInfo.Height = 512;
            tileInfo.Width = 512;
            TileIndex tileIndex = new TileIndex() { RowIndex = 2, ColIndex = 1 };
            tileInfo.TileIndex = tileIndex;

            MapParameter mapParameter = map.GetDefaultMapParameter("世界地图");

            List<Layer> tempLayer = new List<Layer>();
            tempLayer.Add(mapParameter.Layers[12]);
            mapParameter.Layers = tempLayer;

            ImageOutputOption imageOutputOption = new ImageOutputOption();
            imageOutputOption.ImageReturnType = ImageReturnType.BINARY;
            imageOutputOption.Transparent = false;
            imageOutputOption.ImageOutputFormat = ImageOutputFormat.PNG;

            MapImage mapImage = map.GetTile("世界地图", tileInfo, imageOutputOption, mapParameter);
            using (MemoryStream memoryStream = new MemoryStream(mapImage.ImageData))
            {
                Bitmap bmp = new Bitmap(memoryStream);
                Assert.IsTrue(bmp.Width == 512);
                Assert.IsTrue(bmp.Height == 512);
                System.Drawing.Color color = bmp.GetPixel(240, 389);
                Assert.IsTrue(color.R == 242);
                Assert.IsTrue(color.G == 239);
                Assert.IsTrue(color.B == 233);
            }

            Assert.IsNull(null);
        }
Beispiel #25
0
        public void MeasureDistanceTest_point2DsISNULL()
        {
            Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");

            MeasureDistanceResult result = null;
            try
            {
                result = map.MeasureDistance("世界地图", null, Unit.KILOMETER);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual(e.Message, "参数不能为空。\r\n参数名: point2Ds");
            }
        }
        public override void OnLoad(GMapControl gMapControl)
        {
            _gMapControl = gMapControl;
            _gMapControl.Overlays.Add(_gMapOverlay);

            _points = new List<PointLatLng>();
            _gMapControl.Overlays.Add(_gMapOverlay);
            _start = false;

            this._mapUrl = ((SuperMapProvider)gMapControl.MapProvider).ServiceUrl;
            this._mapName = ((SuperMapProvider)gMapControl.MapProvider).MapName;
            this._map = new Map(this._mapUrl);
        }
Beispiel #27
0
 public void MeasureAreaResultTest_KILOMETER()
 {
     Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
     string mapName = "World Map";
     List<Point2D> point2Ds = new List<Point2D>();
     Point2D point1 = new Point2D(23.00, 34.00);
     Point2D point2 = new Point2D(53.55, 12.66);
     Point2D point3 = new Point2D(73.88, 12.6);
     point2Ds.Add(point1);
     point2Ds.Add(point2);
     point2Ds.Add(point3);
     MeasureAreaResult areaResult = map.MeasureArea(mapName, point2Ds, Unit.KILOMETER);
     Assert.AreEqual(areaResult.Area, 3157590.9302391531);
     Assert.AreEqual(areaResult.Unit.ToString(), "KILOMETER");
 }
Beispiel #28
0
 public void GetResourceTest_MarkerIDError()
 {
     Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
     string mapName = "世界地图";
     ResourceParameter parameter = new ResourceParameter();
     parameter.Style = new Style();
     parameter.Style.MarkerSymbolID = 200;
     parameter.Type = ResourceType.SYMBOLMARKER;
     ImageOutputOption option = new ImageOutputOption();
     option.ImageOutputFormat = ImageOutputFormat.BMP;
     option.ImageReturnType = ImageReturnType.URL;
     ResourceImage image = null;
     try
     {
         image = map.GetResource(mapName, parameter, option);
     }
     catch (ServiceException e)
     {
         Assert.AreEqual(e.Message, "获取资源图片的符号 ID 超出范围。");
     }
 }
        public override void OnMapMouseMove(object sender, MouseEventArgs e)
        {
            if (!_start) return;
            PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y);

            if (flag)
            {
                _points.RemoveAt(_points.Count - 1);
            }
            if (!flag) flag = true;
            _points.Add(currentPoint);
            _polygon = new GMapPolygonExtension("", _points, 2.0F,
               System.Drawing.Color.FromArgb(100, 0, 0, 255), System.Drawing.Color.FromArgb(25, 0, 0, 255));

            if (_point2Ds.Count > 1)
            {
                List<Point2D> tempPoints = new List<Point2D>();
                tempPoints.AddRange(_point2Ds);
                double mercatorX, mercatorY;
                Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mercatorX, out mercatorY);
                Point2D point2D = new Point2D(mercatorX, mercatorY);
                tempPoints.Add(point2D);
                Map map = new Map(_mapUrl);
                MeasureAreaResult areaResult = map.MeasureArea(_mapName, tempPoints, Unit.KILOMETER);
                if (_resultMarker == null || _gMapOverlay.Markers.Count < 1)
                {
                    _resultMarker = new GMapMarkerExtension(currentPoint);
                    _resultMarker.ToolTipMode = MarkerTooltipMode.Always;
                    _gMapOverlay.Markers.Add(_resultMarker);
                }
                _resultMarker.Position = currentPoint;
                _resultMarker.ToolTipText = string.Format("{0:f1}平方千米", areaResult.Area);
            }
            if (_gMapOverlay.Polygons.Count > 0)
            {
                _gMapOverlay.Polygons[0] = _polygon;
            }
            else
            {
                _gMapOverlay.Polygons.Add(_polygon);
            }
        }
Beispiel #30
0
        public void MeasureDistanceTest_mapNameISNULL()
        {
            Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");

            List<Point2D> point2Ds = new List<Point2D>();
            Point2D point1 = new Point2D(23.00, 34.00);
            Point2D point2 = new Point2D(53.55, 12.66);
            Point2D point3 = new Point2D(73.88, 12.6);
            point2Ds.Add(point1);
            point2Ds.Add(point2);
            point2Ds.Add(point3);
            MeasureDistanceResult result = null;
            try
            {
                result = map.MeasureDistance(string.Empty, point2Ds, Unit.KILOMETER);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual(e.Message, "参数不能为空。\r\n参数名: mapName");
            }
        }