public GraphicMapPoint(LocationTask task) { var merc = new ESRI.ArcGIS.Client.Projection.WebMercator(); //for esri Lat = Y Long = X var extent = merc.FromGeographic(new MapPoint(task.Location.Longtitude, task.Location.Latitude, new SpatialReference(4326))); //mapPoint = new MapPoint(extent.Extent.XMax, extent.Extent.YMax, new SpatialReference(102100)); this.Geometry = extent; simpleMarkerSymbol = new SimpleMarkerSymbol(); simpleMarkerSymbol.Color = ShapeColor; simpleMarkerSymbol.Size = ShapeSize; simpleMarkerSymbol.Style = ShapeStyle; this.Symbol = simpleMarkerSymbol; this.Attributes.Add("MapPointContent", MapPointContent); this.MapPointContent = new MapPointContent(extent.Extent.XMax, extent.Extent.YMax); this.MapPointContent.Address = task.Location.Address; this.MapPointContent.Id = task.DatabaseId; this.MapPointContent.Latitude = task.Location.Latitude; this.MapPointContent.Longtitude = task.Location.Longtitude; this.MapPointContent.Name = task.Name; this.MapPointContent.UserName = task.UserEmail; this.MapPointContent.PublishedDate = task.LastTimeModified; this.MapPointContent.Info = task.Info; this.MapPointContent.Info = task.Info; this.MapPointContent.Label = task.Label; if (string.IsNullOrWhiteSpace(MapPointContent.Address)) { ReverseGeocode(); } }
} // public static GraphicsLayer createRLLayer(Map map, string layerID, string layerName) void Map_MouseMove(object sender, MouseEventArgs e) { // print coordinates try { //log(string.Format("VRedlineImpl.Map_MouseMove")); var c = MapApplication.Current; var ScreenCoordsTextBlock = c.FindObjectInLayout("ScreenCoordsTextBlock") as TextBlock; var MapCoordsTextBlock = c.FindObjectInLayout("MapCoordsTextBlock") as TextBlock; if (c.Map.Extent != null) { System.Windows.Point screenPoint = e.GetPosition(c.Map); ScreenCoordsTextBlock.Text = string.Format("Screen Coords: X = {0}, Y = {1}", screenPoint.X, screenPoint.Y); ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = c.Map.ScreenToMap(screenPoint); if (c.Map.WrapAroundIsActive) { mapPoint = ESRI.ArcGIS.Client.Geometry.Geometry.NormalizeCentralMeridian(mapPoint) as ESRI.ArcGIS.Client.Geometry.MapPoint; } MapCoordsTextBlock.Text = string.Format("X = {0}, Y = {1}", Math.Round(mapPoint.X, 4), Math.Round(mapPoint.Y, 4)); var wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); mapPoint = wm.ToGeographic(mapPoint) as ESRI.ArcGIS.Client.Geometry.MapPoint; ScreenCoordsTextBlock.Text = string.Format("Lon = {0}, Lat = {1}", Math.Round(mapPoint.X, 7), Math.Round(mapPoint.Y, 7)); } } catch (Exception ex) { log(string.Format("VRedlineImpl.Map_MouseMove, error: {0}", ex.Message)); } } // void Map_MouseMove(object sender, MouseEventArgs e) {
// *********************************************************************************** // * ...Find the nearest Weather Station // *********************************************************************************** private void btnLookupWindDirection_Click(object sender, RoutedEventArgs e) { try { if (_spillLocationGraphicsLayer.Graphics.Count > 0) { List <GPParameter> parameters = new List <GPParameter>(); client.Projection.WebMercator wm = new client.Projection.WebMercator(); ESRI.ArcGIS.Client.Geometry.Geometry geoPoint = wm.ToGeographic(_spillLocationGraphicsLayer.Graphics[0].Geometry); parameters.Add(new GPFeatureRecordSetLayer("Feature_Set", geoPoint)); Geoprocessor findNearestWSGPTask = new Geoprocessor(_findNearestWSURL); findNearestWSGPTask.OutputSpatialReference = _mapWidget.Map.SpatialReference; findNearestWSGPTask.ExecuteCompleted += findNearestWSGPTask_ExecuteCompleted; findNearestWSGPTask.Failed += GeoprocessorTask_Failed; findNearestWSGPTask.ExecuteAsync(parameters); } else { MessageBox.Show("Please add the incident location on the map first!", "Warning"); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); MessageBox.Show("Could not get wind direction!", "Error"); return; } }
Envelope ConvertPointToEnvelop(MapPoint point) { ESRI.ArcGIS.Client.Projection.WebMercator wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); //return wm.FromGeographic(new ESRI.ArcGIS.Client.Geometry.Envelope(point, point) { SpatialReference = new SpatialReference(org_wkid) }).Extent; return wm.FromGeographic(point).Extent; }
public static void ConvertPoints() { MapPoint mp = new MapPoint(); mp.Y = -28.487006; mp.X = 139.537485; mp.SpatialReference = new SpatialReference(4326); MapPoint mp2 = new MapPoint(); mp2.Y = -28.314113; mp2.X = 139.437479; mp2.SpatialReference = new SpatialReference(4326); ESRI.ArcGIS.Client.Projection.WebMercator converter = new ESRI.ArcGIS.Client.Projection.WebMercator(); ESRI.ArcGIS.Client.Geometry.Geometry convertedMapEndPoint = converter.FromGeographic(mp); ESRI.ArcGIS.Client.Geometry.Geometry convertedMapStartPoint = converter.FromGeographic(mp2); Console.WriteLine("Start Point:" + convertedMapStartPoint); Console.WriteLine("End Point" + convertedMapEndPoint); }
public GraphicMapPoint(double X, double Y, SpatialReference spatialReference) { var merc = new ESRI.ArcGIS.Client.Projection.WebMercator(); var longLat = merc.ToGeographic(new MapPoint(X, Y)); mapPoint = new MapPoint(X, Y, spatialReference); this.Geometry = mapPoint; simpleMarkerSymbol = new SimpleMarkerSymbol(); simpleMarkerSymbol.Color = ShapeColor; simpleMarkerSymbol.Size = ShapeSize; simpleMarkerSymbol.Style = ShapeStyle; this.Symbol = simpleMarkerSymbol; this.MapPointContent = new MapPointContent(longLat.Extent.XMax, longLat.Extent.YMax); this.Attributes.Add("MapPointContent", MapPointContent); if (MapPointContent.Address == null) { ReverseGeocode(); } }
private string _baseURL = "Image"; //百度影像 public override void Initialize() { ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator(); this.FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892) { SpatialReference = new SpatialReference(102100) }; //this.FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(9001735.65795624, 2919532.04645186, 19020489.8293508, 8346937.81802098) //{ // SpatialReference = new SpatialReference(102100) //}; //图层的空间坐标系 this.SpatialReference = new SpatialReference(102100); // 建立切片信息,每个切片大小256*256px,共16级. this.TileInfo = new TileInfo() { Height = 256, Width = 256, Origin = new MapPoint(-cornerCoordinate, cornerCoordinate) { SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102100) }, Lods = new Lod[32] }; //为每级建立方案,每一级是前一级别的一半. double resolution = cornerCoordinate * 2 / 256; for (int i = 0; i < TileInfo.Lods.Length; i++) { TileInfo.Lods[i] = new Lod() { Resolution = resolution }; resolution /= 2; } // 调用初始化函数 base.Initialize(); }
MapPoint ConvertMapPointTo102100(MapPoint mp) { ESRI.ArcGIS.Client.Projection.WebMercator wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); return wm.FromGeographic(mp) as MapPoint; }
public void ZoomToLevel(int level, double x, double y) { MapPoint point = new ESRI.ArcGIS.Client.Projection.WebMercator().FromGeographic(new MapPoint(x,y)) as MapPoint; bool zoomentry = false; double resolution; if (level == -1) resolution = Map.Resolution; else resolution = (this.Map.Layers["base"] as TiledLayer).TileInfo.Lods[level].Resolution; if (Math.Abs(this.Map.Resolution - resolution) < 0.05) { this.Map.PanTo(point); return; } zoomentry = false; this.Map.ZoomToResolution(resolution); Map.ExtentChanged += (s, a) => { if (!zoomentry) this.Map.PanTo(point); zoomentry = true; // SwitchLayerVisibility(); }; }
void projectGraphicsAsync(string geometryServiceUrl, IList<Graphic> graphics, SpatialReference outputSpatialReference, ProjectCompleteDelegate onProjectGeometryComplete, object userState) { if (graphics == null) throw new ArgumentNullException("graphics"); if (graphics.Count < 1) { OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = graphics }); return; } if (outputSpatialReference.WKID == 4326 && graphics.All(g => g.Geometry != null && g.Geometry.SpatialReference != null && isWebMercator(g.Geometry.SpatialReference))) { // Project from web mercator to GCS client-side var wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); List<Graphic> outGraphics = new List<Graphic>(); foreach (var g in graphics) { var outGraphic = cloneGraphic(g); outGraphic.Geometry = wm.ToGeographic(g.Geometry); outGraphics.Add(outGraphic); } OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = outGraphics }); } else if (isWebMercator(outputSpatialReference) && graphics.All(g => g.Geometry != null && g.Geometry.SpatialReference != null && g.Geometry.SpatialReference.WKID == 4326)) { // Project from GCS to web mercator client-side var wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); List<Graphic> outGraphics = new List<Graphic>(); foreach (var g in graphics) { var outGraphic = cloneGraphic(g); outGraphic.Geometry = wm.FromGeographic(g.Geometry); outGraphics.Add(outGraphic); } OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = outGraphics }); } else { GeometryService geomService = new GeometryService(geometryServiceUrl) { ProxyURL = this.ProxyUrl }; geomService.ProjectCompleted += (o, e) => { int len1 = graphics.Count; int len2 = e.Results.Count; System.Diagnostics.Debug.Assert(len1 == len2, Resources.Strings.ExceptionNumberofGraphicsBeforeAndAfterProjectionAreNotEqual); for (int i = 0; i < len1 && i < len2; i++) { var targetGraphic = cloneGraphic(graphics[i]); targetGraphic.Geometry = e.Results[i].Geometry; e.Results[i] = targetGraphic; } onProjectGeometryComplete(o, e); }; geomService.Failed += (o, e) => { if ((e.Error is ESRI.ArcGIS.Client.Tasks.ServiceException || e.Error is System.Net.WebException) && geometryServiceUrl != FallbackGeometryServer) { projectGraphicsAsync(FallbackGeometryServer, graphics, outputSpatialReference, onProjectGeometryComplete, e.UserState); } else { OnGeometryServiceOperationFailed(new ExceptionEventArgs(new Exception(e.Error == null ? e.Error.Message : ""), e.UserState)); } }; geomService.ProjectAsync(graphics, outputSpatialReference, userState); } }
private void buttonSearchCoord_Click(object sender, RoutedEventArgs e) { if (this.map1.Layers.Contains(this.map1.Layers["SearchLyr"])) { this.map1.Layers.Remove(this.map1.Layers["SearchLyr"]); } ESRI.ArcGIS.Client.Geometry.Geometry mp= GetLocationCoord(this.textBoxAdd.Text); if (mp==null) { MessageBox.Show("Can not get the Coordinate"); return; } ESRI.ArcGIS.Client.Geometry.Polyline pl = CreateGeoForZoom(mp); ESRI.ArcGIS.Client.GraphicsLayer gl = CreateSearchLyr(mp); //this.map1.ZoomToResolution(this.map1.Resolution/510,mp as ESRI.ArcGIS.Client.Geometry.MapPoint); ESRI.ArcGIS.Client.Projection.WebMercator wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); ESRI.ArcGIS.Client.Geometry.MapPoint mpLonLat= (ESRI.ArcGIS.Client.Geometry.MapPoint)wm.ToGeographic(mp); this.textBoxResult.Text = this.textBoxAdd.Text + ":" + mpLonLat.X +","+ mpLonLat.Y; this.map1.ZoomTo(pl as ESRI.ArcGIS.Client.Geometry.Geometry); this.map1.Layers.Add(gl as ESRI.ArcGIS.Client.Layer); }
private void buttonSearchAddress_Click(object sender, RoutedEventArgs e) { string[] coords = this.textBoxCoord.Text.Trim().Replace(',', ',').Split(','); if (coords==null||coords.Length<2) { MessageBox.Show("Wrong Coords Format,Check it out"); return; } double lon = double.Parse(coords[0]); double lat = double.Parse(coords[1]); if (lat>90.0||lat<-90.0||lon>180.0||lon<-180.0) { MessageBox.Show("Wrong Coords Format,Check it out"); return; } string result= GetLocationAddress(this.textBoxCoord.Text); if (this.map1.Layers.Contains(this.map1.Layers["SearchLyr"])) { this.map1.Layers.Remove(this.map1.Layers["SearchLyr"]); } ESRI.ArcGIS.Client.Geometry.MapPoint mp = new ESRI.ArcGIS.Client.Geometry.MapPoint() { X=lon, Y=lat, SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326) }; ESRI.ArcGIS.Client.Projection.WebMercator wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); mp= wm.FromGeographic(mp) as ESRI.ArcGIS.Client.Geometry.MapPoint; ESRI.ArcGIS.Client.Geometry.Polyline pl = CreateGeoForZoom(mp); ESRI.ArcGIS.Client.GraphicsLayer gl = CreateSearchLyr(mp); this.textBoxResult.Text = this.textBoxCoord.Text + ":" +result; this.map1.ZoomTo(pl as ESRI.ArcGIS.Client.Geometry.Geometry); this.map1.Layers.Add(gl as ESRI.ArcGIS.Client.Layer); }
public static ESRI.ArcGIS.Client.Geometry.Geometry GetLocationCoord(string address) { ESRI.ArcGIS.Client.Geometry.MapPoint _mp = null; string url=string.Format("http://maps.google.com/maps/api/geocode/json?address={0}ka&sensor=false",address); HttpWebRequest hwr = WebRequest.Create(url) as HttpWebRequest; hwr.Method = "GET"; HttpWebResponse httpResponse; StringBuilder stringBuffer = new StringBuilder(); try { httpResponse = hwr.GetResponse() as HttpWebResponse; if (httpResponse.GetResponseStream().CanRead) { StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8); string s = sr.ReadToEnd(); JObject jObject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(s); string lon= ((((jObject["results"] as JArray)[0] as JObject)["geometry"] as JObject)["location"] as JObject)["lng"].ToString(); string lat = ((((jObject["results"] as JArray)[0] as JObject)["geometry"] as JObject)["location"] as JObject)["lat"].ToString(); ESRI.ArcGIS.Client.Geometry.MapPoint mp = new ESRI.ArcGIS.Client.Geometry.MapPoint() { X=double.Parse(lon), Y=double.Parse(lat), SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326) }; ESRI.ArcGIS.Client.Projection.WebMercator w = new ESRI.ArcGIS.Client.Projection.WebMercator(); _mp = w.FromGeographic(mp) as ESRI.ArcGIS.Client.Geometry.MapPoint; } } catch (Exception e) { } return _mp; }
void projectGraphicsAsync(string geometryServiceUrl, IList <Graphic> graphics, SpatialReference outputSpatialReference, ProjectCompleteDelegate onProjectGeometryComplete, object userState) { if (graphics == null) { throw new ArgumentNullException("graphics"); } if (graphics.Count < 1) { OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = graphics }); return; } if (outputSpatialReference.WKID == 4326 && graphics.All(g => g.Geometry != null && g.Geometry.SpatialReference != null && isWebMercator(g.Geometry.SpatialReference))) { // Project from web mercator to GCS client-side var wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); List <Graphic> outGraphics = new List <Graphic>(); foreach (var g in graphics) { var outGraphic = cloneGraphic(g); outGraphic.Geometry = wm.ToGeographic(g.Geometry); outGraphics.Add(outGraphic); } OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = outGraphics }); } else if (isWebMercator(outputSpatialReference) && graphics.All(g => g.Geometry != null && g.Geometry.SpatialReference != null && g.Geometry.SpatialReference.WKID == 4326)) { // Project from GCS to web mercator client-side var wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); List <Graphic> outGraphics = new List <Graphic>(); foreach (var g in graphics) { var outGraphic = cloneGraphic(g); outGraphic.Geometry = wm.FromGeographic(g.Geometry); outGraphics.Add(outGraphic); } OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = outGraphics }); } else { GeometryService geomService = new GeometryService(geometryServiceUrl) { ProxyURL = this.ProxyUrl }; geomService.ProjectCompleted += (o, e) => { int len1 = graphics.Count; int len2 = e.Results.Count; System.Diagnostics.Debug.Assert(len1 == len2, Resources.Strings.ExceptionNumberofGraphicsBeforeAndAfterProjectionAreNotEqual); for (int i = 0; i < len1 && i < len2; i++) { var targetGraphic = cloneGraphic(graphics[i]); targetGraphic.Geometry = e.Results[i].Geometry; e.Results[i] = targetGraphic; } onProjectGeometryComplete(o, e); }; geomService.Failed += (o, e) => { if ((e.Error is ESRI.ArcGIS.Client.Tasks.ServiceException || e.Error is System.Net.WebException) && geometryServiceUrl != FallbackGeometryServer) { projectGraphicsAsync(FallbackGeometryServer, graphics, outputSpatialReference, onProjectGeometryComplete, e.UserState); } else { OnGeometryServiceOperationFailed(new ExceptionEventArgs(new Exception(e.Error == null ? e.Error.Message : ""), e.UserState)); } }; geomService.ProjectAsync(graphics, outputSpatialReference, userState); } }
// *********************************************************************************** // * ...Find the nearest Weather Station // *********************************************************************************** private void btnLookupWindDirection_Click(object sender, RoutedEventArgs e) { try { if (_spillLocationGraphicsLayer.Graphics.Count > 0) { List<GPParameter> parameters = new List<GPParameter>(); client.Projection.WebMercator wm = new client.Projection.WebMercator(); ESRI.ArcGIS.Client.Geometry.Geometry geoPoint = wm.ToGeographic(_spillLocationGraphicsLayer.Graphics[0].Geometry); parameters.Add(new GPFeatureRecordSetLayer("Feature_Set", geoPoint)); Geoprocessor findNearestWSGPTask = new Geoprocessor(_findNearestWSURL); findNearestWSGPTask.OutputSpatialReference = _mapWidget.Map.SpatialReference; findNearestWSGPTask.ExecuteCompleted += findNearestWSGPTask_ExecuteCompleted; findNearestWSGPTask.Failed += GeoprocessorTask_Failed; findNearestWSGPTask.ExecuteAsync(parameters); } else { MessageBox.Show("Please add the incident location on the map first!", "Warning"); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); MessageBox.Show("Could not get wind direction!", "Error"); return; } }
} // public void userGiveCSVLayerParams(string url, string lyrname, string proxy) /// <summary> /// Call from form, add to map graphicslayer from json /// </summary> /// <param name="url"></param> /// <param name="lyrname"></param> /// <param name="proxy"></param> public void userGiveJSONLayerParams(string url, string lyrname, string proxy) { log(string.Format("userGiveJSONLayerParams, name '{2}', url '{0}', proxy '{1}'", url, proxy, lyrname)); MapApplication.Current.HideWindow(jsonParamsForm); var requrl = string.IsNullOrEmpty(proxy) ? url : string.Format("{0}?{1}", proxy, url); // get json text WebClient wc = new WebClient(); Uri uri = new Uri(requrl, UriKind.RelativeOrAbsolute); wc.OpenReadCompleted += (sender, args) => { if (args.Error != null) { log(String.Format("userGiveJSONLayerParams wc_OpenReadCompleted, error in reading answer, msg [{0}], trace [{1}]", args.Error.Message, args.Error.StackTrace)); } else { try { StreamReader reader = new StreamReader(args.Result); string text = reader.ReadToEnd(); log(string.Format("userGiveJSONLayerParams wc_OpenReadCompleted, resp '{0}'", text)); // got layer content, make layer var featureSet = FeatureSet.FromJson(text); var graphicsLayer = new GraphicsLayer() { Graphics = new GraphicCollection(featureSet) }; // set layer params graphicsLayer.Opacity = 1; graphicsLayer.ID = VExtClass.computeSHA1Hash(string.Format("{0}", text)); graphicsLayer.Initialized += (osender, eargs) => { log(string.Format("userGiveJSONLayerParams.Initialized, {0}-{1}", lyrname, graphicsLayer.ID)); }; // projection var MyMap = MapApplication.Current.Map; var mercator = new ESRI.ArcGIS.Client.Projection.WebMercator(); if (!featureSet.SpatialReference.Equals(MyMap.SpatialReference)) { if (MyMap.SpatialReference.Equals(new SpatialReference(102100)) && featureSet.SpatialReference.Equals(new SpatialReference(4326))) { foreach (Graphic g in graphicsLayer.Graphics) { g.Geometry = mercator.FromGeographic(g.Geometry); } } else if (MyMap.SpatialReference.Equals(new SpatialReference(4326)) && featureSet.SpatialReference.Equals(new SpatialReference(102100))) { foreach (Graphic g in graphicsLayer.Graphics) { g.Geometry = mercator.ToGeographic(g.Geometry); } } else { var geometryService = new GeometryService( "http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.ProjectCompleted += (s, a) => { for (int i = 0; i < a.Results.Count; i++) { graphicsLayer.Graphics[i].Geometry = a.Results[i].Geometry; } }; geometryService.Failed += (s, a) => { MessageBox.Show("Ошибка проецирования: " + a.Error.Message); }; geometryService.ProjectAsync(graphicsLayer.Graphics, MyMap.SpatialReference); } } // if map.SR != featureset.SR // add layer to map graphicsLayer.Initialize(); MapApplication.SetLayerName(graphicsLayer, lyrname); ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsVisibleInMapContents(graphicsLayer, true); MapApplication.Current.Map.Layers.Add(graphicsLayer); } // got json text catch (Exception ex) { log(String.Format("userGiveJSONLayerParams wc_OpenReadCompleted, make layer failed {0}, {1}", ex.Message, ex.StackTrace)); } } }; // wc.OpenReadCompleted wc.OpenReadAsync(uri); log(string.Format("userGiveJSONLayerParams, done for name '{2}', url '{0}', proxy '{1}'", url, proxy, lyrname)); } // public void userGiveJSONLayerParams(string url, string lyrname, string proxy)