Skip to content

Commit

Permalink
Merge pull request #22 from amay077/develop
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
amay077 authored Jul 3, 2016
2 parents 0e3bfc9 + d4bea06 commit 858afb3
Show file tree
Hide file tree
Showing 28 changed files with 3,367 additions and 2,760 deletions.
5,539 changes: 2,795 additions & 2,744 deletions XFGoogleMapSample/Droid/Resources/Resource.designer.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion XFGoogleMapSample/Droid/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="MonoAndroid60" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="MonoAndroid60" />
<package id="Xamarin.Forms" version="2.3.0.49" targetFramework="MonoAndroid60" />
<package id="Xamarin.Forms.GoogleMaps" version="1.2.0" targetFramework="monoandroid60" />
<package id="Xamarin.Forms.GoogleMaps" version="1.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.GooglePlayServices.Base" version="29.0.0.1" targetFramework="MonoAndroid60" />
<package id="Xamarin.GooglePlayServices.Basement" version="29.0.0.1" targetFramework="MonoAndroid60" />
<package id="Xamarin.GooglePlayServices.Maps" version="29.0.0.1" targetFramework="MonoAndroid60" />
Expand Down
2 changes: 1 addition & 1 deletion XFGoogleMapSample/UWP/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
"Xamarin.Forms": "2.3.0.49",
"Xamarin.Forms.GoogleMaps": "1.2.0"
"Xamarin.Forms.GoogleMaps": "1.3.0"
},
"frameworks": {
"uap10.0": {}
Expand Down
2 changes: 2 additions & 0 deletions XFGoogleMapSample/XFGoogleMapSample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
Text="Pins" />
<Button x:Name="buttonShapes"
Text="Shapes" />
<Button x:Name="buttonTiles"
Text="Tiles" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
1 change: 1 addition & 0 deletions XFGoogleMapSample/XFGoogleMapSample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public MainPage()
buttonBasicMap.Clicked += (sender, e) => Navigation.PushAsync(new BasicMapPage());
buttonPins.Clicked += (sender, e) => Navigation.PushAsync(new PinsPage());
buttonShapes.Clicked += (sender, e) => Navigation.PushAsync(new ShapesPage());
buttonTiles.Clicked += (sender, e) => Navigation.PushAsync(new TilesPage());
}

protected override void OnAppearing()
Expand Down
54 changes: 54 additions & 0 deletions XFGoogleMapSample/XFGoogleMapSample/TilesPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:maps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
x:Class="XFGoogleMapSample.TilesPage"
Title="Tiles">
<ContentPage.Content>
<StackLayout
VerticalOptions="Fill"
Orientation="Vertical">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Button x:Name="buttonORMTile"
Text="OpenRailwayMap (512px)"
Grid.Row="1"
Grid.Column="1"/>
<Button x:Name="buttonJGSITile"
Text="Japan GSI"
Grid.Row="1"
Grid.Column="2"/>

<Button x:Name="buttonSyncImage"
Text="Image (Sync)"
Grid.Row="2"
Grid.Column="1"/>
<Button x:Name="buttonAsyncImage"
Text="Image (Async)"
Grid.Row="2"
Grid.Column="2"/>

<Button x:Name="buttonRemove"
Text="Remove Tile"
Grid.Row="3"
Grid.Column="1"
Grid.ColumnSpan="2"/>
</Grid>

<maps:Map x:Name="map"
VerticalOptions="FillAndExpand"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
126 changes: 126 additions & 0 deletions XFGoogleMapSample/XFGoogleMapSample/TilesPage.xaml.cs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions XFGoogleMapSample/XFGoogleMapSample/XFGoogleMapSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<EmbeddedResource Include="ShapesPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="TilesPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
Expand All @@ -59,6 +62,9 @@
<Compile Include="ShapesPage.xaml.cs">
<DependentUpon>ShapesPage.xaml</DependentUpon>
</Compile>
<Compile Include="TilesPage.xaml.cs">
<DependentUpon>TilesPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="Xamarin.Forms.Core">
Expand Down
2 changes: 1 addition & 1 deletion XFGoogleMapSample/XFGoogleMapSample/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Xamarin.Forms" version="2.3.0.49" targetFramework="portable-net45+win+wp80+MonoTouch10+MonoAndroid10+xamarinmac20+xamarintvos10+xamarinwatchos10+xamarinios10" />
<package id="Xamarin.Forms.GoogleMaps" version="1.2.0" targetFramework="portable45-net45+win8+wp8" />
<package id="Xamarin.Forms.GoogleMaps" version="1.3.0" targetFramework="portable45-net45+win8+wp8" />
</packages>
5 changes: 5 additions & 0 deletions XFGoogleMapSample/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
<string>Can we use your location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We are using your location</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion XFGoogleMapSample/iOS/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<packages>
<package id="Xamarin.Build.Download" version="0.2.1" targetFramework="xamarinios10" />
<package id="Xamarin.Forms" version="2.3.0.49" targetFramework="xamarinios10" />
<package id="Xamarin.Forms.GoogleMaps" version="1.2.0" targetFramework="xamarinios10" />
<package id="Xamarin.Forms.GoogleMaps" version="1.3.0" targetFramework="xamarinios10" />
<package id="Xamarin.Google.iOS.Maps" version="1.13.1.0" targetFramework="xamarinios10" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using APolyline = Android.Gms.Maps.Model.Polyline;
using APolygon = Android.Gms.Maps.Model.Polygon;
using ACircle = Android.Gms.Maps.Model.Circle;
using ATileOverlay = Android.Gms.Maps.Model.TileOverlay;
using Android.Util;
using Android.App;
using Xamarin.Forms.GoogleMaps.Internals;
Expand All @@ -36,6 +37,7 @@ public MapRenderer()
List<APolyline> _polylines;
List<APolygon> _polygons;
List<ACircle> _circles;
List<ATileOverlay> _tileLayers;
float _scaledDensity = 1;

const string MoveMessageName = "MapMoveToRegion";
Expand Down Expand Up @@ -83,6 +85,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<View> e)
((ObservableCollection<Polyline>)oldMapModel.Polylines).CollectionChanged -= OnPolylineCollectionChanged;
((ObservableCollection<Polygon>)oldMapModel.Polygons).CollectionChanged -= OnPolygonCollectionChanged;
((ObservableCollection<Circle>)oldMapModel.Circles).CollectionChanged -= OnCircleCollectionChanged;
((ObservableCollection<TileLayer>)oldMapModel.TileLayers).CollectionChanged -= OnTileLayerCollectionChanged;

MessagingCenter.Unsubscribe<Map, MoveToRegionMessage>(this, MoveMessageName);

Expand Down Expand Up @@ -141,6 +144,10 @@ protected override void OnElementChanged(ElementChangedEventArgs<View> e)
var inccCircle = Map.Circles as INotifyCollectionChanged;
if (inccCircle != null)
inccCircle.CollectionChanged += OnCircleCollectionChanged;

var inccTileLayer = Map.TileLayers as INotifyCollectionChanged;
if (inccTileLayer != null)
inccTileLayer.CollectionChanged += OnTileLayerCollectionChanged;
}

void OnPinCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
Expand Down Expand Up @@ -243,6 +250,31 @@ void OnCircleCollectionChanged(object sender, NotifyCollectionChangedEventArgs n
}
}

void OnTileLayerCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
{
switch (notifyCollectionChangedEventArgs.Action)
{
case NotifyCollectionChangedAction.Add:
AddTileLayers(notifyCollectionChangedEventArgs.NewItems);
break;
case NotifyCollectionChangedAction.Remove:
RemoveTileLayers(notifyCollectionChangedEventArgs.OldItems);
break;
case NotifyCollectionChangedAction.Replace:
RemoveTileLayers(notifyCollectionChangedEventArgs.OldItems);
AddTileLayers(notifyCollectionChangedEventArgs.NewItems);
break;
case NotifyCollectionChangedAction.Reset:
_tileLayers?.ForEach(tileLayer => tileLayer.Remove());
_tileLayers = null;
AddTileLayers((IList)(Element as Map).TileLayers);
break;
case NotifyCollectionChangedAction.Move:
//do nothing
break;
}
}

void OnMoveToRegionMessage(Map s, MoveToRegionMessage m)
{
MoveToRegion(m.Span, m.Animate);
Expand Down Expand Up @@ -285,6 +317,7 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b)
OnPolylineCollectionChanged (((Map)Element).Polylines, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset));
OnPolygonCollectionChanged(((Map)Element).Polygons, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
OnCircleCollectionChanged(((Map)Element).Circles, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
OnTileLayerCollectionChanged(((Map)Element).TileLayers, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
_init = false;
}
else if (changed)
Expand Down Expand Up @@ -718,6 +751,59 @@ void RemoveCircles(IList circles)
}
}

void AddTileLayers(IList tileLayers)
{
var map = NativeMap;
if (map == null)
return;

if (_tileLayers == null)
_tileLayers = new List<ATileOverlay>();

_tileLayers.AddRange(tileLayers.Cast<TileLayer>().Select(tileLayer =>
{
var opts = new TileOverlayOptions();

ITileProvider nativeTileProvider;

if (tileLayer.MakeTileUri != null)
{
nativeTileProvider = new NUrlTileLayer(tileLayer.MakeTileUri, tileLayer.TileSize);
}
else if (tileLayer.TileImageSync != null)
{
nativeTileProvider = new NSyncTileLayer(tileLayer.TileImageSync, tileLayer.TileSize);
}
else
{
nativeTileProvider = new NAsyncTileLayer(tileLayer.TileImageAsync, tileLayer.TileSize);
}
var nativeTileOverlay = map.AddTileOverlay(opts.InvokeTileProvider(nativeTileProvider));

// associate pin with marker for later lookup in event handlers
tileLayer.Id = nativeTileOverlay;
return nativeTileOverlay;
}));
}

void RemoveTileLayers(IList tileLayers)
{
var map = NativeMap;
if (map == null)
return;
if (_tileLayers == null)
return;

foreach (TileLayer tileLayer in tileLayers)
{
var atileLayer = _tileLayers.FirstOrDefault(m => ((ATileOverlay)tileLayer.Id).Id == m.Id);
if (atileLayer == null)
continue;
atileLayer.Remove();
_tileLayers.Remove(atileLayer);
}
}

bool _disposed;
protected override void Dispose(bool disposing)
{
Expand All @@ -733,6 +819,7 @@ protected override void Dispose(bool disposing)
((ObservableCollection<Polyline>)mapModel.Polylines).CollectionChanged -= OnPolylineCollectionChanged;
((ObservableCollection<Polygon>)mapModel.Polygons).CollectionChanged -= OnPolygonCollectionChanged;
((ObservableCollection<Circle>)mapModel.Circles).CollectionChanged -= OnCircleCollectionChanged;
((ObservableCollection<TileLayer>)mapModel.TileLayers).CollectionChanged -= OnTileLayerCollectionChanged;
}

var gmap = NativeMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Threading.Tasks;
using Android.Gms.Maps.Model;
using IATileProvider = Android.Gms.Maps.Model.ITileProvider;

namespace Xamarin.Forms.GoogleMaps.Android
{
internal class NAsyncTileLayer : Java.Lang.Object, IATileProvider
{
private Func<int, int, int, Task<byte[]>> _tileImageAsync;
private int _tileSize;

public NAsyncTileLayer(Func<int, int, int, Task<byte[]>> tileImageAsync, int tileSize = 256) : base()
{
_tileImageAsync = tileImageAsync;
_tileSize = tileSize;
}

public Tile GetTile(int x, int y, int zoom)
{
var imgByte = _tileImageAsync(x, y, zoom).Result;
return new Tile(_tileSize, _tileSize, imgByte);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Android.Gms.Maps.Model;
using IATileProvider = Android.Gms.Maps.Model.ITileProvider;

namespace Xamarin.Forms.GoogleMaps.Android
{
internal class NSyncTileLayer : Java.Lang.Object, IATileProvider
{
private Func<int, int, int, byte[]> _tileImageSync;
private int _tileSize;

public NSyncTileLayer(Func<int, int, int, byte[]> tileImageSync, int tileSize = 256) : base()
{
_tileImageSync = tileImageSync;
_tileSize = tileSize;
}

public Tile GetTile(int x, int y, int zoom)
{
var imgByte = _tileImageSync(x, y, zoom);
return new Tile(_tileSize, _tileSize, imgByte);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Android.Gms.Maps.Model;

namespace Xamarin.Forms.GoogleMaps.Android
{
internal class NUrlTileLayer : UrlTileProvider
{
private Func<int, int, int, Uri> _makeTileUri;

public NUrlTileLayer(Func<int, int, int, Uri> makeTileUri, int tileSize = 256) : base(tileSize, tileSize)
{
_makeTileUri = makeTileUri;
}

public override Java.Net.URL GetTileUrl(int x, int y, int zoom)
{
var uri = _makeTileUri(x,y,zoom);
return new Java.Net.URL(uri.AbsoluteUri);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
[assembly: AssemblyProduct("Xamarin.Forms.GoogleMaps")]
[assembly: AssemblyCopyright("Copyright © amay077. 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
<Compile Include="FormsGoogleMaps.cs" />
<Compile Include="GeocoderBackend.cs" />
<Compile Include="MapRenderer.cs" />
<Compile Include="NUrlTileLayer.cs" />
<Compile Include="NSyncTileLayer.cs" />
<Compile Include="NAsyncTileLayer.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: ComVisible(false)]
[assembly: ExportRenderer(typeof(Map), typeof(MapRenderer))]
Loading

0 comments on commit 858afb3

Please sign in to comment.