Codenizer.Avalonia.Map 0.3.0

dotnet add package Codenizer.Avalonia.Map --version 0.3.0
NuGet\Install-Package Codenizer.Avalonia.Map -Version 0.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Codenizer.Avalonia.Map" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Codenizer.Avalonia.Map --version 0.3.0
#r "nuget: Codenizer.Avalonia.Map, 0.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Codenizer.Avalonia.Map as a Cake Addin
#addin nuget:?package=Codenizer.Avalonia.Map&version=0.3.0

// Install Codenizer.Avalonia.Map as a Cake Tool
#tool nuget:?package=Codenizer.Avalonia.Map&version=0.3.0

Codenizer.Avalonia.Map

An Avalonia UI control to build zoomable and pannable maps.

Usage

Reference the Codenizer.Avalonia.Map NuGet package in your project.

Add the necessary namespace to the AXAML file you want to include the control on:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:map="clr-namespace:Codenizer.Avalonia.Map;assembly=Codenizer.Avalonia.Map" 

Add the control:

<map:Map
            VerticalAlignment="Stretch"
            HorizontalAlignment="Stretch"
            Name="TestMap"
            MapObjectSelected="Map_OnMapObjectSelected"/>

Then from code add objects to the map in order for them to be rendered:

TestMap.MapObjects.Add(new Square("redSquare", 0, 0, 1000, 1000, "#FF0000"));
TestMap.MapObjects.Add(new Square("greenSquare", 100, 100, 800, 800, "#00FF00"));
TestMap.MapObjects.Add(new Square("blueSquare", 400, 400, 200, 200, "#0000FF"));
TestMap.MapObjects.Add(new Square("yellowSquare", 700, 200, 100, 100, "#FFCC00"));

TestMap.MapObjects.Add(new Point("point1", 100, 100, 2, "#000000"));
TestMap.MapObjects.Add(new Point("point2", 400, 400, 2, "#000000"));
TestMap.MapObjects.Add(new Point("point3", 700, 200, 2, "#000000"));
TestMap.MapObjects.Add(new Point("point4", 750, 250, 2, "#000000"));

And observe the result: Screenshot of a rendered map

For more details have a look at the MapTest sample application.

Features

The control supports zooming and panning. These are controlled mainly through methods on the control itself, for example:

  • ZoomAll which ensures all objects added to the control will be visible
  • ZoomExtent which fits the provided object into the viewport (with some padding for extra niceness)
  • Zoom which supports zooming to an arbitrary level and center position

Additionally, mouse-wheel zoom is supported directly by the control. Panning is handled through a drag action on the control.

The control provides a MapObjectSelected event which will fire after clicking on a selectable (see below) object. It will only fire if an object was under the cursor.

Adding objects to the control

The control supports these object types out of the box:

  • Square
  • Path
  • Point
  • Image

Custom objects can be created by inheriting from MapObject that provides the following properties and methods:

  • Name this is the identifier used by ZoomExtent
  • Bounds the outer bounds of the object
  • IsSelectable, a flag that indicates whether this object can be selected through clicking on it
  • IsVisible, a flag that indicates whether this object should be rendered
  • Contains(position), returns true when the given position is within the bounds of this object. Useful if you have a complex shape.
  • TightContains(position), allows for a more specific hit test on the position. Useful if you have a complex shape.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.0 588 8/27/2023
0.2.0 850 11/6/2022
0.1.0 422 11/6/2022