Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit da3e386

Browse files
committed
Polygon/polyline renderer samples.
1 parent 14b1c3f commit da3e386

File tree

130 files changed

+26409
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+26409
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with your package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Android.Content;
2+
using Android.Gms.Maps.Model;
3+
using MapOverlay;
4+
using MapOverlay.Droid;
5+
using Xamarin.Forms;
6+
using Xamarin.Forms.Maps;
7+
using Xamarin.Forms.Maps.Android;
8+
using System.Collections.Generic;
9+
10+
[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
11+
namespace MapOverlay.Droid
12+
{
13+
public class CustomMapRenderer : MapRenderer
14+
{
15+
List<Position> shapeCoordinates;
16+
17+
public CustomMapRenderer(Context context) : base(context)
18+
{
19+
}
20+
21+
protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Map> e)
22+
{
23+
base.OnElementChanged(e);
24+
25+
if (e.OldElement != null)
26+
{
27+
// Unsubscribe
28+
}
29+
30+
if (e.NewElement != null)
31+
{
32+
var formsMap = (CustomMap)e.NewElement;
33+
shapeCoordinates = formsMap.ShapeCoordinates;
34+
Control.GetMapAsync(this);
35+
}
36+
}
37+
38+
protected override void OnMapReady(Android.Gms.Maps.GoogleMap map)
39+
{
40+
base.OnMapReady(map);
41+
42+
var polygonOptions = new PolygonOptions();
43+
polygonOptions.InvokeFillColor(0x66FF0000);
44+
polygonOptions.InvokeStrokeColor(0x660000FF);
45+
polygonOptions.InvokeStrokeWidth(30.0f);
46+
47+
foreach (var position in shapeCoordinates)
48+
{
49+
polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
50+
}
51+
NativeMap.AddPolygon(polygonOptions);
52+
}
53+
}
54+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using Android.App;
3+
using Android.Content.PM;
4+
using Android.OS;
5+
6+
namespace MapOverlay.Droid
7+
{
8+
[Activity (Label = "MapOverlay.Droid", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
9+
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
10+
{
11+
protected override void OnCreate (Bundle bundle)
12+
{
13+
base.OnCreate (bundle);
14+
15+
global::Xamarin.Forms.Forms.Init (this, bundle);
16+
Xamarin.FormsMaps.Init (this, bundle);
17+
18+
var width = Resources.DisplayMetrics.WidthPixels;
19+
var height = Resources.DisplayMetrics.HeightPixels;
20+
var density = Resources.DisplayMetrics.Density;
21+
22+
App.ScreenWidth = (width - 0.5f) / density;
23+
App.ScreenHeight = (height - 0.5f) / density;
24+
25+
LoadApplication (new App ());
26+
}
27+
}
28+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
7+
<ProjectGuid>{31F4760E-4880-455F-8FD7-05C52D56E816}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<RootNamespace>MapOverlay.Droid</RootNamespace>
10+
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
11+
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
12+
<AndroidResgenClass>Resource</AndroidResgenClass>
13+
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
14+
<AndroidApplication>True</AndroidApplication>
15+
<AssemblyName>MapOverlay.Droid</AssemblyName>
16+
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
17+
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
18+
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
19+
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
20+
<NuGetPackageImportStamp />
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
23+
<DebugSymbols>true</DebugSymbols>
24+
<DebugType>portable</DebugType>
25+
<Optimize>false</Optimize>
26+
<OutputPath>bin\Debug</OutputPath>
27+
<DefineConstants>DEBUG;</DefineConstants>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
<AndroidLinkMode>None</AndroidLinkMode>
31+
<ConsolePause>false</ConsolePause>
32+
<AndroidEnableMultiDex>true</AndroidEnableMultiDex>
33+
</PropertyGroup>
34+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
35+
<DebugType>portable</DebugType>
36+
<Optimize>true</Optimize>
37+
<OutputPath>bin\Release</OutputPath>
38+
<ErrorReport>prompt</ErrorReport>
39+
<WarningLevel>4</WarningLevel>
40+
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
41+
<ConsolePause>false</ConsolePause>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<PackageReference Include="Xamarin.Forms" Version="4.3.0.908675" />
45+
<PackageReference Include="Xamarin.Forms.Maps" Version="4.3.0.908675" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Reference Include="System" />
49+
<Reference Include="System.Xml" />
50+
<Reference Include="System.Core" />
51+
<Reference Include="Mono.Android" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<ProjectReference Include="..\MapOverlay\MapOverlay.csproj">
55+
<Project>{6A579B08-685B-4DDD-81EA-D15B22CFE5B6}</Project>
56+
<Name>MapOverlay</Name>
57+
</ProjectReference>
58+
</ItemGroup>
59+
<ItemGroup>
60+
<Compile Include="MainActivity.cs" />
61+
<Compile Include="Resources\Resource.designer.cs" />
62+
<Compile Include="Properties\AssemblyInfo.cs" />
63+
<Compile Include="CustomMapRenderer.cs" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<None Include="Resources\AboutResources.txt" />
67+
<None Include="Properties\AndroidManifest.xml" />
68+
<None Include="Assets\AboutAssets.txt" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<Folder Include="Resources\layout\" />
72+
<Folder Include="Resources\values\" />
73+
</ItemGroup>
74+
<ItemGroup>
75+
<AndroidResource Include="Resources\drawable\icon.png" />
76+
<AndroidResource Include="Resources\drawable-hdpi\icon.png" />
77+
<AndroidResource Include="Resources\drawable-xhdpi\icon.png" />
78+
<AndroidResource Include="Resources\drawable-xxhdpi\icon.png" />
79+
</ItemGroup>
80+
<ItemGroup>
81+
<AndroidResource Include="Resources\layout\Tabbar.axml" />
82+
<AndroidResource Include="Resources\layout\Toolbar.axml" />
83+
<AndroidResource Include="Resources\values\styles.xml" />
84+
<AndroidResource Include="Resources\values\colors.xml" />
85+
</ItemGroup>
86+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
87+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.mapoverlay">
3+
<uses-sdk android:minSdkVersion="19" />
4+
<application android:label="MapOverlay">
5+
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="INSERT_MAP_API_KEY_HERE" />
6+
<!-- Necessary for apps that target Android 9.0 or higher -->
7+
<uses-library android:name="org.apache.http.legacy" android:required="false" />
8+
</application>
9+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
10+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
11+
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
12+
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
13+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
14+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
15+
<uses-permission android:name="android.permission.INTERNET" />
16+
</manifest>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using Android.App;
4+
5+
// Information about this assembly is defined by the following attributes.
6+
// Change them to the values specific to your project.
7+
8+
[assembly: AssemblyTitle ("MapOverlay.Droid")]
9+
[assembly: AssemblyDescription ("")]
10+
[assembly: AssemblyConfiguration ("")]
11+
[assembly: AssemblyCompany ("")]
12+
[assembly: AssemblyProduct ("")]
13+
[assembly: AssemblyCopyright ("davidbritch")]
14+
[assembly: AssemblyTrademark ("")]
15+
[assembly: AssemblyCulture ("")]
16+
17+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
18+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
19+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
20+
21+
[assembly: AssemblyVersion ("1.0.0")]
22+
23+
// The following attributes are used to specify the signing key for the assembly,
24+
// if desired. See the Mono documentation for more information about signing.
25+
26+
//[assembly: AssemblyDelaySign(false)]
27+
//[assembly: AssemblyKeyFile("")]
28+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Images, layout descriptions, binary blobs and string dictionaries can be included
2+
in your application as resource files. Various Android APIs are designed to
3+
operate on the resource IDs instead of dealing with images, strings or binary blobs
4+
directly.
5+
6+
For example, a sample Android app that contains a user interface layout (main.axml),
7+
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8+
would keep its resources in the "Resources" directory of the application:
9+
10+
Resources/
11+
drawable/
12+
icon.png
13+
14+
layout/
15+
main.axml
16+
17+
values/
18+
strings.xml
19+
20+
In order to get the build system to recognize Android resources, set the build action to
21+
"AndroidResource". The native Android APIs do not operate directly with filenames, but
22+
instead operate on resource IDs. When you compile an Android application that uses resources,
23+
the build system will package the resources for distribution and generate a class called "R"
24+
(this is an Android convention) that contains the tokens for each one of the resources
25+
included. For example, for the above Resources layout, this is what the R class would expose:
26+
27+
public class R {
28+
public class drawable {
29+
public const int icon = 0x123;
30+
}
31+
32+
public class layout {
33+
public const int main = 0x456;
34+
}
35+
36+
public class strings {
37+
public const int first_string = 0xabc;
38+
public const int second_string = 0xbcd;
39+
}
40+
}
41+
42+
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
43+
to reference the layout/main.axml file, or R.strings.first_string to reference the first
44+
string in the dictionary file values/strings.xml.

0 commit comments

Comments
 (0)