0

Final Edit

I've found the correct documentation, and can inspect the MapView instance and mapboxMap to see available functions.

However I'm still not clear on how to actually use the SDK from within JavaScript, for example using mapboxMap.addLayer(layer: Layer). How do I make a new Layer?

So any tips on how to use a native SDK from within my angular/nativescript app would be lovely.

Original Question

I need a bit more control over my Mapbox plugin in my NativeScript project (I need to implement clustering, custom popups, custom (moveable) markers etc) and nativescript-mapbox doesn't provide convenience methods for this.

According to the documentation, the onMapReady event is meant to return a reference to the native MapView object under args.ios || args.android however when I inspect this object via logging, it appears to just be a string.

com.mapbox.mapboxsdk.maps.MapView{14ffde6 VFED..CL. ........ 0,0-1080,1584}

I've tried referencing parameters that I feel should be present on it (by reading the Mapbox SDK documentation) and yet nothing appears to be defined.

So my question is this, how exactly do I go about accessing the native MapView instance within my code, so that I can take full advantage of the SDK to have greater control over the plugin?

Some examples on how I might perform a simple action, such as create a MapMarker would be extremely helpful!

Edit

Based on the comments, I investigated the instance com.mapbox.mapboxsdk.maps.MapView with console.dir() and was given a long list of available functions. However these aren't lining up with what is available in the docs over here.

I'm clearly not understanding something, but feel like I'm close. Can anyone help me with my missing link here?

Some questions I'm trying to answer; why are the docs I've found different from the methods available on this instance. How can I go about doing some (seemingly) simple things like adding or modifying a marker or symbol layer?

Edit 2

I think I just figured it out, I was inspecting a MapView instance, which has a property called mapboxMap, I was looking at the documentation for mapboxMap and wondering why it wasn't lining up with the MapView instance.

So just use console.dir(nativeMapView.mapboxMap) and you'll see it has the methods required to manipulate the map!

Rohan
  • 456
  • 3
  • 16
  • `com.mapbox.mapboxsdk.maps.MapView{14ffde6 VFED..CL. ........ 0,0-1080,1584}` that is an instance, not sure on the logging as a 'string' but you could try `const x = args.android// the instance you are getting; console.dir(x) and see what logs, you should see methods, members, etc. – Brad Martin May 15 '18 at 02:03
  • @BradMartin I am unfamiliar with the syntax, how did you know it was an instance? My console logger wasn't giving a type, I just assumed because of how strange it looked. I will try your suggestion and update my question with the result. – Rohan May 15 '18 at 03:25
  • For one, I've contributed to the plugin and used it in previous projects :) as for the type when it's logged, it's giving you the type but it's on the namespace of the full class, so `com.mapbox...MapView` is your type for the instance you are logging. You can do the same with other layouts/views in NativeScript. Add a console.log(something) where something is a ref to a layout or view (button, label) and you'll see the same. So on that instance you'll have access to whatever the SDK provides. Hope that helps. – Brad Martin May 15 '18 at 05:11
  • @BradMartin using console.dir(x) has given me the insight I need. The functions listed though don't appear in the documentation I've got here. I will keep digging. Would you mind creating an answer with a link to the docs and a bit of an explanation so that I can accept it? – Rohan May 16 '18 at 01:28

1 Answers1

1

com.mapbox.mapboxsdk.maps.MapView{14ffde6 VFED..CL. ........ 0,0-1080,1584} that is an instance, not sure on the logging as a 'string' but you could try `const x = args.android// the instance you are getting; console.dir(x) and see what logs, you should see methods, members, etc.

As for the type when it's logged, it's giving you the type but it's on the namespace of the full class, so com.mapbox...MapView is your type for the instance you are logging. You can do the same with other layouts/views in NativeScript. Add a console.log(something) where something is a ref to a layout or view (button, label) and you'll see the same. So on that instance you'll have access to whatever the SDK provides. Hope that helps.

Brad Martin
  • 5,637
  • 4
  • 28
  • 44
  • Thank you so much brad, this was the hint I needed to get it figured out. Do you have any further insight into how to make use of the SDK when it requires instances of other objects like a Layer? (see my question again for edits) – Rohan May 17 '18 at 00:45