Giter VIP home page Giter VIP logo

mapbox-ios-binding's Introduction

Mapbox for Xamarin.iOS

Mapbox for Xamarin.iOS

A Xamarin.iOS binding library for Mapbox library.

About

This project is maintained by Naxam Co.,Ltd.
We specialize in developing mobile applications using Xamarin and native technology stack.

Looking for developers for your project?


Installation

Install-Package Naxam.Mapbox.iOS

Usage

Getting started with the package. Please don't forget to follow the official guide here.

License

Mapbox binding library for iOS is released under the MIT license. See LICENSE for details.

Get our showcases on AppStore/PlayStore

Try our showcases to know more about our capabilities.

Contact us if interested.



Follow us for the latest updates
Twitter URL Twitter Follow

mapbox-ios-binding's People

Contributors

dependabot[bot] avatar fleuverouge avatar nghiahaminh25101995 avatar tuyen-vuduc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapbox-ios-binding's Issues

iOS designer crashes with VS 8.0 (build 3001)

It is quite mysterious, but with the latest VS for Mac, iOS designer crashes if you open a xib or storyboard if the project uses this binding library. If I remove the library, xibs open correctly.

The issue applies to the example project here, so it is very easy to reproduce:

  1. Open this example project with VS for Mac 8.0
  2. Attempt to open iOS designer with e.g.: LaunchScreen.storyboard
    Crashlog attached.
    crash.txt

Polylines that are part of a style layer are not drawn on the map

The following should be possible, but does not work in the latest bindings:

  1. Add empty MGLShapeSource to the map
  2. Create MGLLineStyleLayer and associate it with the MGLShapeSource
  3. Add the MGLLineStyleLayer to the map
  4. Create new PolyLineFeature
  5. Set MGLShapeSource.Shape = polyline
  6. Polyline should appear on the map with the styles set in the MGLStyleLayer

The above sequence results in no new polyline on the map.

Point features added to the map in this way work correctly. Polygons appear to be broken as well.

The code below demonstrates this issue. The temple icon appears on the map, but the red line does not.

[Export("mapView:didFinishLoadingStyle:")]
public void MapViewDidFinishLoadingStyle(MGLMapView mapView, MGLStyle style)
{
    var coordinates = new CLLocationCoordinate2D[] {
        new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude + 0.03, longitude: mapView.CenterCoordinate.Longitude - 0.02),
        new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude + 0.02, longitude: mapView.CenterCoordinate.Longitude - 0.03),
        new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude, longitude: mapView.CenterCoordinate.Longitude - 0.02),
        new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude -0.01, longitude: mapView.CenterCoordinate.Longitude),
        new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude -0.04, longitude: mapView.CenterCoordinate.Longitude + 0.01),
        new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude -0.04, longitude: mapView.CenterCoordinate.Longitude + 0.04)
    };

    var polyline = new MGLPolylineFeature();
    polyline.AppendCoordinates(ref coordinates[0], (nuint)coordinates.Length);
    var temple = new MGLPointFeature();
    temple.Coordinate = new CLLocationCoordinate2D(21.0276, 105.8355);
    var shapes = new MGLShape[] { polyline, temple };

    var source = new MGLShapeSource("test", new MGLShape[0], null);
    style.AddSource(source);

    var lineStyleLayer = new MGLLineStyleLayer("test-line", source);
    lineStyleLayer.LineColor = NSExpression.FromConstant(UIColor.Red);
    lineStyleLayer.LineWidth = NSExpression.FromConstant(NSNumber.FromDouble(5.0));
    style.AddLayer(lineStyleLayer);

    var templeImage = UIImage.FromBundle("temple");
    templeImage = templeImage.ImageWithAlignmentRectInsets(new UIEdgeInsets(0, 0, templeImage.Size.Height / 2, 0));
    style.SetImage(templeImage, "temple");
    var symbolStyleLayer = new MGLSymbolStyleLayer("test-symbol", source);
    symbolStyleLayer.IconImageName = NSExpression.FromConstant(new NSString("temple"));
    symbolStyleLayer.IconOpacity = NSExpression.FromConstant(NSNumber.FromDouble(0.7));
    style.AddLayer(symbolStyleLayer);

    var shapeCollectionFeature = MGLShapeCollectionFeature.ShapeCollectionWithShapes(shapes);
    source.Shape = shapeCollectionFeature;
}

The same exact code reproduced in Swift works as expected:

func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
    
    var coordinates: [CLLocationCoordinate2D] = [
        CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude + 0.03, longitude: mapView.centerCoordinate.longitude - 0.02),
        CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude + 0.02, longitude: mapView.centerCoordinate.longitude - 0.03),
        CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude, longitude: mapView.centerCoordinate.longitude - 0.02),
        CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude - 0.01, longitude: mapView.centerCoordinate.longitude),
        CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude - 0.04, longitude: mapView.centerCoordinate.longitude + 0.01),
        CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude - 0.04, longitude: mapView.centerCoordinate.longitude + 0.04)
    ]

    let polyline = MGLPolylineFeature(coordinates: &coordinates, count: UInt(coordinates.count))
    let temple = MGLPointFeature()
    temple.coordinate = CLLocationCoordinate2D(latitude: 21.0276, longitude: 105.8355)
    let shapes: [MGLShape] = [ polyline, temple ]

    let source = MGLShapeSource(identifier: "test", shapes: [MGLShape](), options: nil)
    style.addSource(source)

    let lineStyleLayer = MGLLineStyleLayer(identifier: "test-line", source: source)
    lineStyleLayer.lineColor = NSExpression.init(forConstantValue: UIColor.red)
    lineStyleLayer.lineWidth = NSExpression.init(forConstantValue: 5.0)
    style.addLayer(lineStyleLayer)
    
    var templeImage = UIImage.init(named: "temple")
    templeImage = templeImage?.withAlignmentRectInsets(UIEdgeInsets(top: 0, left: 0, bottom: templeImage?.size.height ?? 0 / 2, right: 0))
    style.setImage(templeImage ?? UIImage(), forName: "temple")
    let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "test-symbol", source: source)
    symbolStyleLayer.iconImageName = NSExpression.init(forConstantValue: "temple")
    symbolStyleLayer.iconOpacity = NSExpression.init(forConstantValue: 0.7)
    style.addLayer(symbolStyleLayer);
    
    let shapeCollectionFeature = MGLShapeCollectionFeature.init(shapes: shapes)
    source.shape = shapeCollectionFeature;
}

Sample project reproducing the issue: https://drive.google.com/file/d/1dI8Ai5lIZxKWA-NOFx8eBUx-gtLVJsom/view?usp=sharing

Sample working Swift project: https://drive.google.com/file/d/1m1p2FqjZh_c0akMIi2flsSbimuseDYdo/view?usp=sharing

Binding issue MGLPolyline, MGLPolygon

Maybe I am wrong but shouldn't these interfaces be compiled with IntPtr instead of ref CLLocationCoordinate2D coords ?
Could not make it work with ref , maybe I am missing something ?
Thanks

This works anyway.

CLLocationCoordinate2D[] coords = coordsc2d.ToArray();

nuint count = (nuint)coords.Count();
var pinnedArray = GCHandle.Alloc(coords, GCHandleType.Pinned);
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
IMGLOverlay mp = null;
mp = new MGLPolyline();
mp .SetCoordinates(pointer, count);
pinnedArray.Free();
interface MGLPolygon : MGLOverlay
	{
		// @property (readonly, nonatomic) NSArray<MGLPolygon *> * _Nullable interiorPolygons;
		[NullAllowed, Export("interiorPolygons")]
		MGLPolygon[] InteriorPolygons { get; }

		// +(instancetype _Nonnull)polygonWithCoordinates:(const CLLocationCoordinate2D * _Nonnull)coords count:(NSUInteger)count;
		[Static]
		[Export("polygonWithCoordinates:count:")]
        unsafe MGLPolygon PolygonWithCoordinates(IntPtr coords, nuint count);

		// +(instancetype _Nonnull)polygonWithCoordinates:(const CLLocationCoordinate2D * _Nonnull)coords count:(NSUInteger)count interiorPolygons:(NSArray<MGLPolygon *> * _Nullable)interiorPolygons;
		[Static]
		[Export("polygonWithCoordinates:count:interiorPolygons:")]
        unsafe MGLPolygon PolygonWithCoordinates(IntPtr coords, nuint count, [NullAllowed] MGLPolygon[] interiorPolygons);
	}

interface MGLPolyline : MGLOverlay
	{
		// +(instancetype _Nonnull)polylineWithCoordinates:(const CLLocationCoordinate2D * _Nonnull)coords count:(NSUInteger)count;
		[Static]
		[Export("polylineWithCoordinates:count:")]
		
		unsafe MGLPolyline PolylineWithCoordinates(IntPtr coords, nuint count);
	}

Cannot set annotation tap

I try to make annotation visible by tap, but when I tap marker annotation doesn't appears.

Here is my code from ViewController

`public partial class MapController : UIViewController
{
MGLMapView map;

    public MapController(IntPtr handle) : base(handle)
    {
    }
    public override async void ViewDidLoad()
    {
        //Getting list of tours
        List<Experience> experiences = await ExperienceMethods.GetExperiencesAsync();
        //Getting centrer location, for us it's 1 element in List
        double lat_center = Convert.ToDouble(experiences[0].lat, CultureInfo.InvariantCulture);
        double lng_center = Convert.ToDouble(experiences[0].lng, CultureInfo.InvariantCulture);

        //Rendering map
        MGLAccountManager.AccessToken = "************";
        map = new MGLMapView(
            View.Bounds,
            new NSUrl("mapbox://styles/mapbox/streets-v10")
            );
        map.SetCenterCoordinate(new CLLocationCoordinate2D(lat_center, lng_center), 11, false);
        View.AddSubview(map);
        //Here is delegate for tap
        map.WeakDelegate = this;

        //Getting all pointers via forloop
        for (int i =0; i < experiences.Count; i++)
        {

            double lat = Convert.ToDouble(experiences[i].lat, CultureInfo.InvariantCulture);
            double lng = Convert.ToDouble(experiences[i].lng, CultureInfo.InvariantCulture);
            var point = new MGLPointAnnotation()
            {
                Title = experiences[i].title,
                Coordinate = new CLLocationCoordinate2D(Convert.ToDouble(experiences[i].lat, CultureInfo.InvariantCulture), Convert.ToDouble(experiences[i].lng, CultureInfo.InvariantCulture))
            };
            map.AddAnnotation(point);

        }

    }
    [Export("map:annotationCanShowCallout:")]
    public bool MapView_AnnotationCanShowCallout(MGLMapView map, IMGLAnnotation annotation)
    {
        return true;
    }`

How I can fix this?

Apply a MGLCircleStyleLayer to a cluster not work

Hi,
I read this example in the mapbox official page
https://www.mapbox.com/ios-sdk/examples/clustering
I translated it in c#. It works except for association between the MGLSymbolStyleLayer, MGLCircleStyleLayer and the "cluster" component draw on the map. So, in the map the point are clustered, but not rendered with the correct style.

I do not know if this is a bug in the porting or another problem.
I guess the problem is the definition of NSPredicate. In the example is declared as

"circlesLayer.predicate = NSPredicate(format: "%K == YES", "cluster")"

in c#

"Predicate = NSPredicate.FromFormat("%K == YES", new NSString("cluster"))"

Can you check this problem?

Map crashes in simulator while scrolling

I've just upgraded the MapBox binding to 4.0.2 from 3.6.1, and now I'm seeing crashes while scrolling/zooming through the map:

libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: unordered_map::at: key not found
2018-06-19 09:25:38.443 Launchpad[43988:1200641] critical: Stacktrace:

2018-06-19 09:25:38.443 Launchpad[43988:1200641] critical:   at <unknown> <0xffffffff>
2018-06-19 09:25:38.444 Launchpad[43988:1200641] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) [0x0005c] in <0b60c1467e7449608ac42f9c7bbfdd05>:0
2018-06-19 09:25:38.444 Launchpad[43988:1200641] critical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:79
2018-06-19 09:25:38.444 Launchpad[43988:1200641] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:63
2018-06-19 09:25:38.444 Launchpad[43988:1200641] critical:   at Unifly.Launchpad.iOS.Application.Main (string[]) [0x00001] in /Users/christoph/vsworkspace/unifly-launchpad/src/Shared/iOS/Main.cs:12
2018-06-19 09:25:38.444 Launchpad[43988:1200641] critical:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00051] in <19475de33a3c4bfdb9df32cb528871bb>:0
2018-06-19 09:25:38.444 Launchpad[43988:1200641] critical: 
Native stacktrace:

2018-06-19 09:25:38.452 Launchpad[43988:1200641] critical: 	0   Launchpad                           0x0000000103709674 mono_handle_native_crash + 244
2018-06-19 09:25:38.452 Launchpad[43988:1200641] critical: 	1   libsystem_platform.dylib            0x000000011528ff5a _sigtramp + 26
2018-06-19 09:25:38.452 Launchpad[43988:1200641] critical: 	2   ???                                 0x000000000000ffff 0x0 + 65535
2018-06-19 09:25:38.452 Launchpad[43988:1200641] critical: 	3   libsystem_c.dylib                   0x0000000114ec5c97 abort + 127
2018-06-19 09:25:38.452 Launchpad[43988:1200641] critical: 	4   libc++abi.dylib                     0x0000000113e02e6f __cxa_bad_cast + 0
2018-06-19 09:25:38.452 Launchpad[43988:1200641] critical: 	5   libc++abi.dylib                     0x0000000113e02ff3 _ZL25default_terminate_handlerv + 241
2018-06-19 09:25:38.452 Launchpad[43988:1200641] critical: 	6   libobjc.A.dylib                     0x0000000113e3d2b6 _ZL15_objc_terminatev + 105
2018-06-19 09:25:38.452 Launchpad[43988:1200641] critical: 	7   libc++abi.dylib                     0x0000000113e200ae _ZSt11__terminatePFvvE + 8
2018-06-19 09:25:38.453 Launchpad[43988:1200641] critical: 	8   libc++abi.dylib                     0x0000000113e1fd56 __cxa_rethrow + 99
2018-06-19 09:25:38.453 Launchpad[43988:1200641] critical: 	9   libobjc.A.dylib                     0x0000000113e3d1cc objc_exception_rethrow + 40
2018-06-19 09:25:38.453 Launchpad[43988:1200641] critical: 	10  CoreFoundation                      0x0000000112d64399 CFRunLoopRunSpecific + 777
2018-06-19 09:25:38.453 Launchpad[43988:1200641] critical: 	11  GraphicsServices                    0x00000001173a9a73 GSEventRunModal + 62
2018-06-19 09:25:38.453 Launchpad[43988:1200641] critical: 	12  UIKit                               0x000000010c875057 UIApplicationMain + 159
2018-06-19 09:25:38.453 Launchpad[43988:1200641] critical: 	13  ???                                 0x0000000133ba9ee7 0x0 + 5162835687
2018-06-19 09:25:38.453 Launchpad[43988:1200641] critical: 	14  ???                                 0x0000000133ba9c43 0x0 + 5162835011
2018-06-19 09:25:38.453 Launchpad[43988:1200641] critical: 
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================


This happens regardless of the '--registrar:static' argument, and doesn't happen when deploying to my iPhone 6s. Any ideas as to what could be causing this or how to fix it?

Adding MGLMapView as a subview breaks layout

When I add the mapbox mapview (MGLMapView) as a subview, my layout breaks somehow.

MGLMapView routeMapView = new MGLMapView(RouteView.Frame); RouteView.AddSubview(routeMapView);

Without mapview in the bottom-left corner:
img_4356

With mapview put in the frame of the bottom-left corner:
img_4355

Can somebody please explain this to me? I have two other views, where the mapview is working pretty well. But there the mapview is starting in the superview of the view controller at point 0,0.

I almost tried everything to get it running. Also added it with the XIB editor with the same result.

Thanks for any help or advice.

Try to use your lib instead of Default Maps

I trying to use your lib with Xamarin.iOS Native like this

public partial class MapController : UIViewController { MGLMapView map; public MapController(IntPtr handle) : base(handle) { } public override void ViewDidLoad() { MGLAccountManager.AccessToken = "**************"; map = new MGLMapView( UIScreen.MainScreen.Bounds, new NSUrl("mapbox://styles/naxamtest/cj5kin5x21li42soxdx3mb1yt") ); map.SetCenterCoordinate(new CLLocationCoordinate2D(21.028511, 105.804817), 11, false); } }

But I still see a default map.

I have ViewController with MapView added on it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.