protected override void GetSource( Envelope extent, int width, int height, DynamicLayer.OnImageComplete onComplete ) { _currentWidth = width; _currentHeight = height; MapPoints = new List<MapPoint>(); //Make up some dummy data int count = 0; while( count < 1000 ) { MapPoints.Add( new MapPoint( extent.XMin + ( extent.Width * ( _random.Next( 100 ) / 100.00 ) ), extent.YMin + ( extent.Height * ( _random.Next( 100 ) / 100.00 ) ), extent.SpatialReference ) ); count++; } //Make up some dummy data _pngRenderer = new PixelPngRenderer( _currentWidth, _currentHeight, MapPoints ); ParameterizedThreadStart starter = new ParameterizedThreadStart( ( pngRenderer ) => { Stream imageStream = InitalizeImage( pngRenderer as PixelPngRenderer ); Dispatcher.BeginInvoke( () => { _image = new BitmapImage(); _image.SetSource( imageStream ); onComplete( _image, width, height, extent ); } ); } ); new Thread( starter ).Start( _pngRenderer ); }
/// <summary> /// Gets the source image to display in the dynamic layer. Override this to generate /// or modify images. /// </summary> /// <param name="properties">The image export properties.</param> /// <param name="onComplete">The method to call when the image is ready.</param> /// <seealso cref="ESRI.ArcGIS.Client.DynamicLayer.OnProgress"/> protected override void GetSource(DynamicLayer.ImageParameters properties, DynamicLayer.OnImageComplete onComplete) { if (!IsInitialized) { onComplete(null, null); return; } Envelope extent = properties.Extent; var ex121 = AppStateSettings.Instance.ViewDef.MapControl.Extent; var vp = new MgrsViewport(Map); /* Calculate visisble UTM boxes */ LastMetersPerPixel = vp.MetersPerPixel; if (!Cfg.IsEnabled) { onComplete(null, null); return; } var draw = new DrawMgrsRaster(Cfg, vp); int width = properties.Width; int height = properties.Height; var img1 = GenerateImage1(width, height, 96, dc => draw.Render(dc)); onComplete(Convert(img1), new ImageResult(extent)); }
/// <summary> /// Sets the value of the DynamicLayerFullExtent attached property to a specified DynamicLayer. /// </summary> /// <param name="element">The DynamicLayer to which the attached property is written.</param> /// <param name="value">The needed DynamicLayerFullExtent value.</param> public static void SetDynamicLayerFullExtent(DynamicLayer element, Envelope value) { if (element == null) { throw new ArgumentNullException("element"); } element.SetValue(DynamicLayerFullExtentProperty, value); }
/// <summary> /// Gets the value of the DynamicLayerFullExtent attached property for a specified DynamicLayer. /// </summary> /// <param name="element">The DynamicLayer from which the property value is read.</param> /// <returns>The DynamicLayerFullExtent property value for the DynamicLayer.</returns> public static Envelope GetDynamicLayerFullExtent(DynamicLayer element) { if (element == null) { throw new ArgumentNullException("element"); } return(element.GetValue(DynamicLayerFullExtentProperty) as Envelope); }
public static void InitRefreshTimer(this DynamicLayer lyr, TimeSpan interval) { DynamicLayerTimer tmr = new DynamicLayerTimer { BoundLayer = lyr, Interval = interval }; lyr.SetValue(RefreshTimerProperty, tmr); tmr.Tick += new EventHandler(tmr_Tick); }
protected override void GetSource( Envelope extent, int width, int height, DynamicLayer.OnImageComplete onComplete ) { //List<MapPoint> mapPoints = new List<MapPoint>(); //List<Point> points = new List<Point>(); //int count = 0; //while( count < 1000 ) //{ // mapPoints.Add(new MapPoint(extent.XMin + (extent.Width * (_random.Next(100)/100.00)), // extent.YMin + (extent.Height * (_random.Next(100)/100.00)), // extent.SpatialReference)); // count++; //} //foreach( MapPoint entry in mapPoints ) //{ // double M11 = ( double ) width / 360.00; // double M22 = -( double ) height / 180.00; // double M12 = 0.00; // double M21 = 0.00; // double offsetX = 180.00 * ( ( double ) width / 360.00 ); // double offsetY = 90.00 * ( ( double ) height / 180.0 ); // Matrix transform = new Matrix( M11, M12, M21, M22, offsetX, offsetY ); // points.Add( transform.Transform( new Point( entry.X, entry.Y ) ) ); //} if( _timer != null ) _timer.Dispose(); _currentWidth = width; _currentHeight = height; _pngRenderer = new RainDropPngRenderer( _currentWidth, _currentHeight ); ParameterizedThreadStart starter = new ParameterizedThreadStart( ( pngRenderer ) => { Stream imageStream = InitalizeImage( pngRenderer as RainDropPngRenderer ); Dispatcher.BeginInvoke( () => { _image = new BitmapImage(); _image.SetSource( imageStream ); onComplete( _image, width, height, extent ); _timer = new Timer( timer_Tick, _pngRenderer, new TimeSpan( 0, 0, 0 ), TimeSpan.FromMilliseconds( RippleIntervalMilliSeconds ) ); } ); } ); new Thread( starter ).Start( _pngRenderer ); }
public void UpdateDynamic() { Bitmap TmpLayer; if (StaticLayer != null) { TmpLayer = (Bitmap)StaticLayer.Clone(); } else { TmpLayer = new Bitmap(Width, Height); } if (DynamicLayer != null) { DynamicLayer.Dispose(); } Shapes.DrawTmp(Graphics.FromImage(TmpLayer)); DynamicLayer = TmpLayer; }
public static void StopRefreshTimer(this DynamicLayer lyr) { DynamicLayerTimer tmr = (DynamicLayerTimer)lyr.GetValue(RefreshTimerProperty); tmr.Stop(); }
/// <summary> /// Gets the URL. Override from DynamicMapServiceLayer /// </summary> /// <param name="properties">The image export properties.</param> /// <param name="onComplete">OnUrlComplete delegate.</param> /// <remarks> /// The Map has a private method loadLayerInView which calls Layer.Draw. /// The DynamicMapServiceLayer abstract class overrides the Draw method and calls /// DynamicMapServiceLayer.GetUrl which must be implemented in a subclass. /// The last parameter is the OnUrlComplete delegate, which is used to pass the appropriate values /// (url, width, height, envelope) to the private DynamicMapServiceLayer.getUrlComplete method. /// </remarks> public override void GetUrl(DynamicLayer.ImageParameters properties, DynamicMapServiceLayer.OnUrlComplete onComplete) { Envelope extent = properties.Extent; int width = properties.Width; int height = properties.Height; int extentWKID = (extent.SpatialReference != null) ? extent.SpatialReference.WKID : 0; string baseUrl = MapUrl ?? Url; if (baseUrl == null) { onComplete(null, null); return; } StringBuilder mapURL = new StringBuilder(baseUrl); if (!baseUrl.Contains("?")) mapURL.Append("?"); else if (!baseUrl.EndsWith("&")) mapURL.Append("&"); mapURL.Append("SERVICE=WMS&REQUEST=GetMap"); mapURL.AppendFormat("&WIDTH={0}", width); mapURL.AppendFormat("&HEIGHT={0}", height); mapURL.AppendFormat("&FORMAT={0}", ImageFormat); mapURL.AppendFormat("&LAYERS={0}", Layers == null ? "" : String.Join(",", Layers)); mapURL.Append("&STYLES="); mapURL.AppendFormat("&BGCOLOR={0}", "0xFFFFFF"); mapURL.AppendFormat("&TRANSPARENT={0}", "TRUE"); mapURL.AppendFormat("&VERSION={0}", GetValidVersionNumber()); //If one of the WebMercator codes, change to a WKID supported by the service if (SupportedSpatialReferenceIDs != null && (extentWKID == 102100 || extentWKID == 102113 || extentWKID == 3857 || extentWKID == 900913)) { if (!SupportedSpatialReferenceIDs.Contains(extentWKID)) { if (SupportedSpatialReferenceIDs.Contains(3857)) extentWKID = 3857; else if (SupportedSpatialReferenceIDs.Contains(102100)) extentWKID = 102100; else if (SupportedSpatialReferenceIDs.Contains(102113)) extentWKID = 102113; else if (SupportedSpatialReferenceIDs.Contains(900913)) extentWKID = 900913; } } bool useCrsFormat = _useCrsFormat != null && _useCrsFormat.Contains(extentWKID); // Need to use CRS:xx format ==> x,y order if (LowerThan13Version()) { mapURL.AppendFormat("&SRS={0}", useCrsFormat ? CrsFromSR(extentWKID) : string.Format("EPSG:{0}", extentWKID)); mapURL.AppendFormat(CultureInfo.InvariantCulture, "&bbox={0},{1},{2},{3}", extent.XMin, extent.YMin, extent.XMax, extent.YMax); } else { mapURL.AppendFormat("&CRS={0}", useCrsFormat ? CrsFromSR(extentWKID) : string.Format("EPSG:{0}", extentWKID)); if (!useCrsFormat && !LowerThan13Version() && UseLatLon(extentWKID)) mapURL.AppendFormat(CultureInfo.InvariantCulture, "&BBOX={0},{1},{2},{3}", extent.YMin, extent.XMin, extent.YMax, extent.XMax); else mapURL.AppendFormat(CultureInfo.InvariantCulture, "&BBOX={0},{1},{2},{3}", extent.XMin, extent.YMin, extent.XMax, extent.YMax); } onComplete(Utilities.PrefixProxy(ProxyUrl, mapURL.ToString()).AbsoluteUri, new ImageResult(new ESRI.ArcGIS.Client.Geometry.Envelope() { XMin = extent.XMin, YMin = extent.YMin, XMax = extent.XMax, YMax = extent.YMax })); }
public void AddToList(DynamicLayer dl) { objectList.Add(dl); }
public void AddEsriLayer(DynamicLayer pLayer) { map.glOverlay.ChildLayers.Add(pLayer); }
void ISupportsDynamicImageByteRequests.GetImageData(DynamicLayer.ImageParameters properties, OnImageDataReceived onImageDataReceived) { OnImageComplete onImageComplete = (image, props) => { BitmapSource bitmapSource = image as BitmapSource; MemoryStream stream = new MemoryStream(); if (bitmapSource != null) { PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Interlace = PngInterlaceOption.Off; encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); encoder.Save(stream); stream.Seek(0, SeekOrigin.Begin); } onImageDataReceived(stream, props); }; GetSource(properties, onImageComplete); }
/// <summary> /// Gets the source image to display in the dynamic layer. Override this to generate /// or modify images. /// </summary> /// <param name="properties">The image export properties.</param> /// <param name="onComplete">The method to call when the image is ready.</param> /// <seealso cref="ESRI.ArcGIS.Client.DynamicLayer.OnProgress"/> protected override void GetSource(DynamicLayer.ImageParameters properties, DynamicLayer.OnImageComplete onComplete) { if (!IsInitialized || HeatMapPoints == null || HeatMapPoints.Count == 0) { onComplete(null, null); return; } Envelope extent = properties.Extent; int width = properties.Width; int height = properties.Height; if (renderThread != null && renderThread.IsBusy) { renderThread.CancelAsync(); //render already running. Cancel current process, and queue up new enqueueExport = new ImageParameters(extent, width, height); enqueueOnComplete = onComplete; return; } //Accessing a GradientStop collection from a non-UI thread is not allowed, //so we used a private class gradient collection List<ThreadSafeGradientStop> stops = new List<ThreadSafeGradientStop>(Gradient.Count); foreach (GradientStop stop in Gradient) { stops.Add(new ThreadSafeGradientStop() { Color = stop.Color, Offset = stop.Offset }); } //Gradients must be sorted by offset stops.Sort((ThreadSafeGradientStop g1, ThreadSafeGradientStop g2) => { return g1.Offset.CompareTo(g2.Offset); }); List<HeatPoint> points = new List<HeatPoint>(); double res = extent.Width / width; //adjust extent to include points slightly outside the view so pan won't affect the outcome Envelope extent2 = new Envelope(extent.XMin - Intensity * res, extent.YMin - Intensity * res, extent.XMax + Intensity * res, extent.YMax + Intensity * res); //get points within the extent and transform them to pixel space foreach (MapPoint p in HeatMapPoints) { if (Map != null && Map.WrapAroundIsActive) { // Note : this should work even if WrapAround is not active but it's probably less performant if (p.Y >= extent2.YMin && p.Y <= extent2.YMax) { Point screenPoint = Map.MapToScreen(p, true); if (!double.IsNaN(width) && Map.FlowDirection == FlowDirection.RightToLeft) screenPoint.X = width - screenPoint.X; if (screenPoint.X >= -Intensity && screenPoint.X <= width + Intensity) { points.Add(new HeatPoint() { X = (int)Math.Round(screenPoint.X), Y = (int)Math.Round(screenPoint.Y) }); } } } else { if (p.X >= extent2.XMin && p.Y >= extent2.YMin && p.X <= extent2.XMax && p.Y <= extent2.YMax) { points.Add(new HeatPoint() { X = (int)Math.Round((p.X - extent.XMin) / res), Y = (int)Math.Round((extent.YMax - p.Y) / res) }); } } } //Start the render thread renderThread.RunWorkerAsync( new object[] { extent, width, height, (int)Math.Round(this.Intensity), stops, points, onComplete }); }
/// <summary> /// Gets the source image to display in the dynamic layer. Override this to generate /// or modify images. /// </summary> /// <param name="extent">The extent of the image being request.</param> /// <param name="width">The width of the image being request.</param> /// <param name="height">The height of the image being request.</param> /// <param name="onComplete">The method to call when the image is ready.</param> /// <seealso cref="OnProgress"/> protected override void GetSource(Envelope extent, int width, int height, DynamicLayer.OnImageComplete onComplete) { if (!IsInitialized) { onComplete(null, -1, -1, null); return; } if (renderThread != null && renderThread.IsBusy) { renderThread.CancelAsync(); //render already running. Cancel current process. while (renderThread.IsBusy) //wait for thread to cancel { #if SILVERLIGHT Thread.Sleep(10); #else System.Windows.Forms.Application.DoEvents(); #endif } } //Accessing a GradientStop collection from a non-UI thread is not allowed, //so we used a private class gradient collection List<ThreadSafeGradientStop> stops = new List<ThreadSafeGradientStop>(Gradient.Count); foreach (GradientStop stop in Gradient) { stops.Add(new ThreadSafeGradientStop() { Color = stop.Color, Offset = stop.Offset }); } //Gradients must be sorted by offset stops.Sort((ThreadSafeGradientStop g1, ThreadSafeGradientStop g2) => { return g1.Offset.CompareTo(g2.Offset); }); List<HeatPoint> points = new List<HeatPoint>(); double res = (extent.Width / width) / Resolution; //adjust extent to include points slightly outside the view so pan won't affect the outcome Envelope extent2 = new Envelope(extent.XMin - Intensity * res, extent.YMin - Intensity * res, extent.XMax + Intensity * res, extent.YMax + Intensity * res); //get points within the extent and transform them to pixel space foreach (MapPoint p in HeatMapPoints) { if (p.X >= extent2.XMin && p.Y >= extent2.YMin && p.X <= extent2.XMax && p.Y <= extent2.YMax) { points.Add(new HeatPoint() { X = (int)Math.Round((p.X - extent.XMin) / res), Y = (int)Math.Round((extent.YMax - p.Y) / res) }); } } //Start the render thread renderThread.RunWorkerAsync( new object[] { extent, width, height, this.Intensity, this.Resolution, stops, points, onComplete }); }
public override void Execute(object parameter) { if (Layer == null) { return; } bool isServerLayer = false; Envelope targetExtent = null; TiledLayer tiledLayer = Layer as TiledLayer; if (tiledLayer != null) { isServerLayer = true; targetExtent = LayerExtentExtensions.GetTiledLayerFullExtent(tiledLayer); // get the cached value (if any) which will likely be in the map's spRef already if (targetExtent == null) // value not known, use value on service metadata (will likely be in the services' spatial ref and not neccesarily in map's spRef) { targetExtent = tiledLayer.FullExtent; } if (tiledLayer is ESRI.ArcGIS.Client.Bing.TileLayer) { if (targetExtent.SpatialReference == null) { targetExtent.SpatialReference = new SpatialReference(102100); } } } DynamicLayer dynamicLayer = Layer as DynamicLayer; if (dynamicLayer != null) { isServerLayer = true; targetExtent = LayerExtentExtensions.GetDynamicLayerFullExtent(dynamicLayer); // get the cached value (if any) which will likely be in the map's spRef already if (targetExtent == null) // value not known, use value on service metadata (will likely be in the services' spatial ref and not neccesarily in map's spRef) { targetExtent = dynamicLayer.FullExtent; } } if (isServerLayer) { if (targetExtent == null || Map == null || Map.SpatialReference == null) { return; } if (Map.SpatialReference.Equals(targetExtent.SpatialReference)) { // spatial reference matches. can directly zoom Map.ZoomTo(targetExtent); } else { if (string.IsNullOrEmpty(GeometryServiceUrl)) { throw new Exception(Resources.Strings.ExceptionNoGeometryServiceUrlSpecifiedLayerZoomedIsDifferentSpatialReference); } GeometryServiceOperationHelper helper = new GeometryServiceOperationHelper(GeometryServiceUrl); helper.ProjectExtentCompleted += (o, e) => { // Cache (save) the projected extent values if (tiledLayer != null) { LayerExtentExtensions.SetTiledLayerFullExtent(tiledLayer, e.Extent); } else if (dynamicLayer != null) { LayerExtentExtensions.SetDynamicLayerFullExtent(dynamicLayer, e.Extent); } Map.ZoomTo(e.Extent); }; helper.ProjectExtent(targetExtent, Map.SpatialReference); } return; } // Non server rendererd layers follow GraphicsLayer graphicsLayer = Layer as GraphicsLayer; if (graphicsLayer == null) { return; } if (Map != null) { Envelope newMapExtent = null; if (graphicsLayer.Graphics.Count < 1) { FeatureLayer featureLayer = graphicsLayer as FeatureLayer; if (featureLayer != null && featureLayer.LayerInfo != null && featureLayer.LayerInfo.Extent != null) { Envelope env = featureLayer.LayerInfo.Extent; SpatialReference sr = env.SpatialReference; if (sr == null) { sr = featureLayer.LayerInfo.DefaultSpatialReference; } if (Map.SpatialReference.Equals(sr)) { Map.PanTo(env); } else if (sr != null) { GeometryServiceOperationHelper geomHelper = new GeometryServiceOperationHelper( new ConfigurationStoreHelper().GetGeometryServiceUrl(View.Instance.ConfigurationStore)); geomHelper.GeometryServiceOperationFailed += (o, args) => { Logger.Instance.LogError(args.Exception); throw args.Exception; }; geomHelper.ProjectExtentCompleted += (o, args) => { MapZoomOrPan(args.Extent); }; geomHelper.ProjectExtent(env, Map.SpatialReference); } } } else { foreach (Graphic graphic in graphicsLayer.Graphics) { if (graphic.Geometry != null && graphic.Geometry.Extent != null) { newMapExtent = graphic.Geometry.Extent.Union(newMapExtent); } } newMapExtent = MapZoomOrPan(newMapExtent); } } }
/// <summary> /// Gets the value of the DynamicLayerFullExtent attached property for a specified DynamicLayer. /// </summary> /// <param name="element">The DynamicLayer from which the property value is read.</param> /// <returns>The DynamicLayerFullExtent property value for the DynamicLayer.</returns> public static Envelope GetDynamicLayerFullExtent(DynamicLayer element) { if (element == null) { throw new ArgumentNullException("element"); } return element.GetValue(DynamicLayerFullExtentProperty) as Envelope; }