You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在.NET MAUI应用的ArcGIS地图中创建信号强度热力图层?

.NET MAUI中基于ArcGIS创建RSSI热力图的问题

需求背景

我开发了一个.NET MAUI桌面应用,可从模拟LoRa网络扫描器的SD卡读取历史数据。目前地图已能展示扫描过程及不同扫描中扫描器相对于模拟LoRa发射器的不同位置,现在希望基于信号强度(RSSI)值创建热力图层,预期效果为渐变色彩的强度分布(比如从绿色到红色的过渡)。

我尝试过参考ArcGIS的热点分析示例,但难以适配自身需求,不确定是否选对了方案。

代码更新后问题

参考相关文章编写代码后,点击"Update renderer"按钮时,原地图点消失,但未生成预期的热力图。

代码实现

HeatMapRenderer.cs

using Newtonsoft.Json;
namespace HeatMapRendererJson
{
    public partial class HeatMapRenderer
    {
        public string ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        public void AddColorStop(double ratio, Color color)
        {
            if (ratio > 1.0 || ratio < 0.0) { throw new Exception("Argument 'ratio' must be a value between 0 and 1."); };

            ColorStop stop = new ColorStop(ratio, color);
            ColorStops.Add(stop);
        }
      
        public void ClearColorStops()
        {
            ColorStops.Clear();
        }

        [JsonProperty("type")]
        public string Type { get; set; } = "heatmap";


        [JsonProperty("blurRadius")]
        public long BlurRadius { get; set; }

        [JsonProperty("colorStops")]
        public List<ColorStop> ColorStops { get; set; } = new List<ColorStop>();

        [JsonProperty("field")]
        public string Field { get; set; }

        [JsonProperty("maxPixelIntensity")]
        public double MaxPixelIntensity { get; set; }

        [JsonProperty("minPixelIntensity")]
        public double MinPixelIntensity { get; set; }
    }

    public partial class ColorStop
    {

        [JsonProperty("ratio")]
        public double Ratio { get; set; }

        [JsonProperty("color")]
        public int[] Color { get; set; }

        public ColorStop(double ratio, Color color)
        {
            Ratio = ratio;
            Color = new int[] { (int)color.Red, (int)color.Green, (int)color.Blue, (int)color.Alpha };
        }
    }
}

MainWindow.xaml.cs

public partial class MainWindow : ContentPage
{
    // 地震点样本图层URL
    private string _earthquakesUrl ="https://sampleserver6.arcgisonline.com/arcgis/rest/services/Earthquakes_Since1970/FeatureServer/0";

    // 存储地震图层及其默认渲染器的引用
    private FeatureLayer _quakesLayer;
    private Renderer _defaultRenderer;

    private List<Field> numericFields = new List<Field>();

    public MainWindow()
    {
        InitializeComponent();
        Init();
        Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "myKey";
    }
    private async void Init()
    {
        // 创建OpenStreetMap底图
        Basemap osmBasemap = new Basemap(BasemapStyle.OSMStandard);

        // 创建带OpenStreetMap底图的地图
        Map map = new Map(osmBasemap);

        // 创建地震图层、加载并获取其默认渲染器
        _quakesLayer = new FeatureLayer(new Uri(_earthquakesUrl));
        await _quakesLayer.LoadAsync();
        _defaultRenderer = _quakesLayer.Renderer;

        // 将地震图层添加到地图,再把地图添加到地图视图
        map.OperationalLayers.Add(_quakesLayer);
        MyMapView.Map = map;
       
        int x =1;
        foreach (var fld in _quakesLayer.FeatureTable.Fields)
        {
            if (fld.FieldType.HasFlag(FieldType.Float32 | FieldType.Float64 | FieldType.Int16 | FieldType.Int32))
            {
                numericFields.Add(fld);
            }
            Debug.WriteLine(x + "-fields: " + fld);
            x++;
        }
        Debug.WriteLine("numericFields: " + numericFields[11]);
    }

    private void UpdateRendererButton_Clicked(object sender, EventArgs e)
    {
        // 解析部分用户输入
        double.TryParse(MinIntensityTextBox.Text, out double minIntensity);
        double.TryParse(MaxIntensityTextBox.Text, out double maxIntensity);
        //int.TryParse(BlurRadiusComboBox.SelectedItem.ToString(), out int blurRadius);

        // 根据用户输入创建新的热力图渲染器信息
        HeatMapRenderer heatMapRendererInfo = new HeatMapRenderer
        {
            BlurRadius = 6,
            MaxPixelIntensity = 1000.0,
            MinPixelIntensity = 0.0
        };

         heatMapRendererInfo.Field = numericFields[11].Name;
         heatMapRendererInfo.AddColorStop(0.0, Colors.Transparent);
        heatMapRendererInfo.AddColorStop(0.10, new Color(1, 0, 0, (float)0.6));    // 位置0为红色
        //heatMapRendererInfo.AddColorStop(0.5, new Color(1, 1, 0, (float)0.6));  // 位置0.5为黄色
        heatMapRendererInfo.AddColorStop(1.0, new Color(0, 1, 0, (float)0.6));    // 位置1为绿色
             // 获取渲染器类的JSON表示
        string heatMapJson = heatMapRendererInfo.ToJson();

        // 使用静态方法Renderer.FromJson从JSON字符串创建新渲染器
        var heatMapRenderer = Renderer.FromJson(heatMapJson);

        // 将渲染器应用到地图中的点图层
        _quakesLayer.Renderer = heatMapRenderer;
    }

    private void ResetRenderer_Clicked(object sender, EventArgs e)
    {
        // 重新应用图层的默认渲染器
        _quakesLayer.Renderer = _defaultRenderer;
    }
}

MainWindow.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Scanner_MAUI.Pages.MainWindow"
             Title="MainWindow"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="300"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="35"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="35"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
 <Button Grid.Row="7" Grid.ColumnSpan="2"
                    Text="Update renderer"
                    Width="120" Height="25"
                    Clicked="UpdateRendererButton_Clicked"/>
        <Button Grid.Row="8" Grid.ColumnSpan="2"
                    Text="Reset"
                    Width="120" Height="25"
                    Clicked="ResetRenderer_Clicked"/>
    </Grid>
    <esri:MapView x:Name="MyMapView"
                      Grid.Column="1"/>
    </Grid>
</ContentPage>

求助需求

我是C#和.NET MAUI新手,希望得到解决该问题的具体建议,让热力图能正常生成。


内容的提问来源于stack exchange,提问作者BaselE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 10:27:09