【问题标题】:How can I add a customised Carto Map Marker via Carto Map Moblie SDK.UWP?如何通过 Carto Map Moblie SDK.UWP 添加自定义的 Carto Map Marker?
【发布时间】:2018-09-11 06:51:42
【问题描述】:

我正在实现通用 Windows 平台 (UWP) 应用,并且正在使用 Carto Map Mobile SDK (UWP)。但是,我不知道如何以编程方式将 .png 图像添加为地图标记。这是我的代码:

                /// Preparation - create layer and datasource

            // projection will be needed later
            Projection projection = map.Options.BaseProjection;

            // Initialize an local data source - a bucket for your objects created in code
            LocalVectorDataSource datasource = new LocalVectorDataSource(projection);

            // Initialize a vector layer with the previous data source
            VectorLayer layer = new VectorLayer(datasource);

            // Add layer to map
            map.Layers.Add(layer);



            /// Now we real adding objects

            // Create marker style
            MarkerStyleBuilder builder = new MarkerStyleBuilder();
            builder.Size = 20;
            BinaryData iconBytes = AssetUtils.LoadAsset("Z:/FolderName/ProjectName/Assets/markers_mdpi/mapmarker.png");

            byte[] bytearray = iconBytes.GetData();
            int size = Marshal.SizeOf(bytearray[0]) * bytearray.Length;

            IntPtr pnt = Marshal.AllocHGlobal(size);

            builder.Bitmap = new Bitmap(pnt, true);


            MarkerStyle style = null;


            style = builder.BuildStyle();

            // Create a marker with the style we defined previously and add it to the source
            Marker marker = new Marker(position, style);
            datasource.Add(marker);

Carto Map 官方技术文档一点帮助都没有,这里是截图Carto Mobile SDK document。但是,当我通过 Nuget 安装官方 SDK.UWP 时,库中并没有文档中提到的任何相关功能。

谁能帮我解决这个问题?否则我进一步创建这个 UWP 应用程序是没有意义的。非常感谢。

【问题讨论】:

    标签: c# uwp carto-mobile


    【解决方案1】:

    好的,我刚刚解决了这个问题,Carto Map Support 团队也回复了我。官方技术文档更新不及时,误导了初次接触carto map(尤其是UWP的)的新人。

    解决办法是:

                /// Preparation - create layer and datasource
    
                // projection will be needed later
                Projection projection = map.Options.BaseProjection;
    
                // Initialize an local data source - a bucket for your objects created in code
                LocalVectorDataSource datasource = new LocalVectorDataSource(projection);
    
                // Initialize a vector layer with the previous data source
                VectorLayer layer = new VectorLayer(datasource);
    
                // Add layer to map
                map.Layers.Add(layer);                
    
                /// Now we real adding objects
    
                // Create marker style
                MarkerStyleBuilder builder = new MarkerStyleBuilder();
                builder.Size = 30;
                //here we generate a filePath string then pass it into AssetUtils.LoadAsset 
                string filePath = System.IO.Path.Combine("SubfolderName", "imagefileName.png"); 
    
                var data = AssetUtils.LoadAsset("SubfolderName\\imagefileName.png");
                var bitmap = Bitmap.CreateFromCompressed(data);
    
                if (bitmap != null)
                {
                    builder.Bitmap = bitmap;
                    bitmap.Dispose();
                }
    
                MarkerStyle style = builder.BuildStyle();
    
                // Create a marker with the style we defined previously and add it to the source
                Marker marker = new Marker(position, style);
                datasource.Add(marker);
    

    请确保所有文件/来源都来自 Assets 文件夹。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-15
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      • 2021-06-27
      • 1970-01-01
      相关资源
      最近更新 更多