0

I'm implementing a Universal Windows Platform (UWP) app, and I m using the Carto Map Mobile SDK (UWP). However, I don't know how to add a .png image as a Map Marker programmatically. Here is my code:

        /// 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);

The Carto Map official technical document didn't help at all, and here is the screenshot Carto Mobile SDK document. However, when I installed the official SDK.UWP via the Nuget, there aren't any relevant functions that mentioned in the document in the library.

Can anyone help me solve this problem?

Otherwise, it is meaningless for me to create this UWP app further.

1 Answer 1

0

Fortunately this is somewhat easier, you do not need to convert BinaryData to byte arrays or anything. Simply do the following:

builder.Bitmap = Carto.Graphics.Bitmap.CreateFromCompressed(iconBytes);
1
  • Thank you, it works. Just a friendly suggestion, would you please update the Technical documentation on GitHub (it might mislead new people who want to implement carto map on UWP app) or create a more helpful demo file for UWP, including add customised markers, click vector object/element to display the popup infobox(balloon) etc.? Lots of people just changed from Google map to Carto map, we are not quite familiar with it, and the .net UWP demo file is not as handy as that for android or ios. Cheers.
    – Jack Lau
    Commented Sep 10, 2018 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.