protected override void WriteElementContents(Client.Layer layer) { base.WriteElementContents(layer); HeatMapLayer heatMapLayer = layer as HeatMapLayer; if (heatMapLayer != null) { #region Gradient if (heatMapLayer.Gradient != null) { writer.WriteStartElement(Constants.esriPrefix, "HeatMapLayer.Gradient", Constants.esriNamespace); writer.WriteStartElement("GradientStopCollection"); foreach (GradientStop gradient in heatMapLayer.Gradient) { writer.WriteStartElement("GradientStop"); if (gradient.Color != null) { writer.WriteAttributeString("Color", gradient.Color.ToString(CultureInfo.InvariantCulture)); } if (gradient.Offset != 0) { writer.WriteAttributeString("Offset", gradient.Offset.ToString(CultureInfo.InvariantCulture)); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); } #endregion #region Heat Map Points if (heatMapLayer.HeatMapPoints != null) { writer.WriteStartElement(Constants.esriPrefix, "HeatMapLayer.HeatMapPoints", Constants.esriNamespace); writer.WriteStartElement(Constants.esriPrefix, "PointCollection", Constants.esriNamespace); foreach (MapPoint heatMapPoint in heatMapLayer.HeatMapPoints) { writer.WriteStartElement(Constants.esriPrefix, "MapPoint", Constants.esriNamespace); writer.WriteAttributeString("X", heatMapPoint.X.ToString(CultureInfo.InvariantCulture)); writer.WriteAttributeString("Y", heatMapPoint.Y.ToString(CultureInfo.InvariantCulture)); if (heatMapPoint.SpatialReference != null) { writer.WriteStartElement(Constants.esriPrefix, "MapPoint.SpatialReference", Constants.esriNamespace); writeSpatialReference(writer, heatMapPoint.SpatialReference); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); } #endregion } }
protected override void WriteAttributes(Client.Layer layer) { base.WriteAttributes(layer); HeatMapLayer heatMapLayer = layer as HeatMapLayer; if (heatMapLayer != null) { if (heatMapLayer.Intensity != 10.0) { writer.WriteAttributeString("Intensity", heatMapLayer.Intensity.ToString(CultureInfo.InvariantCulture)); } } }
void Layers_LayersInitialized(object sender, EventArgs args) { //Add 1000 random points to the heat map layer //Replace this with "real" data points that you want to display //in the heat map. HeatMapLayer layer = MyMap.Layers["RandomHeatMapLayer"] as HeatMapLayer; Random rand = new Random(); for (int i = 0; i < 1000; i++) { double x = rand.NextDouble() * MyMap.Extent.Width - MyMap.Extent.Width / 2; double y = rand.NextDouble() * MyMap.Extent.Height - MyMap.Extent.Height / 2; layer.HeatMapPoints.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(x, y)); } }
protected override void CreateHeatMapIfNeeded() { if (_heatMapLayer == null) { _heatMapLayer = new HeatMapLayer(Xamarin.Forms.Forms.Context, FormsMap) { ParentMap = _googleMap, Radius = FormsMap.Radius, Intensity = FormsMap.Intensity, Locations = FormsMap.Locations?.Select(CoordinateConverter.ConvertToNative) }; FormsMap.PropertyChanged -= FormsMapPropertyChanged; FormsMap.PropertyChanged += FormsMapPropertyChanged; _nativeMap.AddView(_heatMapLayer); } }
public MainPage() { this.InitializeComponent(); this.Loaded += (s, e) => { testData = new LocationCollection(); layer = new HeatMapLayer() { ParentMap = MyMap, Locations = GetTestData(500), Radius = 250000 }; MyMap.Children.Add(layer); }; }
protected override void CreateHeatMapIfNeeded() { if (_heatMapLayer == null) { _heatMapLayer = new HeatMapLayer(FormsMap) { ParentMap = _nativeMap, Radius = FormsMap.Radius, Intensity = FormsMap.Intensity, Locations = FormsMap.Locations?.Select(CoordinateConverter.ConvertToNative) }; FormsMap.PropertyChanged -= FormsMapPropertyChanged; FormsMap.PropertyChanged += FormsMapPropertyChanged; _heatMapLayer.Frame = new CoreGraphics.CGRect(0, 0, _nativeMap.Frame.Width, _nativeMap.Frame.Height); _nativeMap.AddSubview(_heatMapLayer); } }
protected override void CreateHeatMapIfNeeded() { if (_heatMapLayer == null) { IEnumerable <BasicGeoposition> positions = FormsMap.Locations?.Select(pos => new BasicGeoposition { Latitude = pos.Latitude, Longitude = pos.Longitude }); Geopath polygonPath = new Geopath(positions); _heatMapLayer = new HeatMapLayer(FormsMap) { ParentMap = _nativeMap, Locations = polygonPath, Radius = FormsMap.Radius, Intensity = FormsMap.Intensity, Visibility = Visibility.Collapsed }; _nativeMap.Children.Add(_heatMapLayer); } }
/// <summary> /// Handles click event on search button and handles search functionality /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Search_Click(object sender, RoutedEventArgs e) { if (EndDatePicker.SelectedDate != null && StartDatePicker.SelectedDate != null) { //Clear prior search myMap.Visibility = Visibility.Hidden; myMapLabel.Visibility = Visibility.Collapsed; myMap.Children.Clear(); SearchResults.Visibility = Visibility.Collapsed; AddressList.Children.Clear(); ErrorMessage.Visibility = Visibility.Collapsed; LoadingLabel.Visibility = Visibility.Visible; LocationData locationData = locationApi.getLocationData(LocationBox.Text); myMap.Center = locationData.CentrePoint; ComboBoxItem crimetype = (ComboBoxItem)CrimeType.SelectedItem; string crimeTag = (String)crimetype.Tag; DateTime startDate = (DateTime)StartDatePicker.SelectedDate; DateTime endDate = (DateTime)EndDatePicker.SelectedDate; List <Location> locations = new List <Location>(); try { locations = await policeApi.getCrimeLocations(locationData, startDate, endDate, crimeTag); LocationCollection locationCollection = new LocationCollection(); // create List of locations to add to heat map layer foreach (Location location in locations) { locationCollection.Add(location); } // Create new HeatMapLayer setting view properties layer = new HeatMapLayer() { ParentMap = myMap, Locations = locationCollection, Radius = 500, Opacity = 0.5 }; // Add to map view as child component layer myMap.Children.Add(layer); LocationRect box = new LocationRect(locations); myMap.SetView(box); } catch (Exception ex) { MessageBox.Show("--Error retrieving data from server--\n" + "Please try one or more of the following: \n" + "* Ensuring your are entering a valid geolocation in England and Wales (e.g avoid any special characters)\n" + "* Narrowing the search area (e.g South London/Chelsea instead of London \n" + "* Reducing the date range \n" + "* Searching for less common crimes (e.g bicycle crime instead of public order offences)\n\n" , "Error", MessageBoxButton.OK); Debug.WriteLine(ex.StackTrace); InitializeComponent(); } LoadingLabel.Visibility = Visibility.Hidden; myMap.Visibility = Visibility.Visible; myMap.Focus(); //allows '+' and '-' to zoom the map } else { MessageBox.Show("Please enter a start and end date", "Enter date", MessageBoxButton.OK); } }