Implementation of setProperties method on LineLayer in MapBox encounters resolution issues

I am currently utilizing the Android Mapbox SDK to integrate a VectorSource into a MapboxMap and then I am trying to incorporate a LineLayer onto the map as well.

My version is 5.1.3

This code will be written in TypeScript due to its compatibility with the NativeScript framework, which enables the utilization of native libraries and direct access to native android/iOS APIs.

// These variables serve as easy references to classes in the mapbox package

const PropertyFactory = com.mapbox.mapboxsdk.style.layers.PropertyFactory;
const Property = com.mapbox.mapboxsdk.style.layers.Property;
const LineLayer = com.mapbox.mapboxsdk.style.layers.LineLayer;
const VectorSource = com.mapbox.mapboxsdk.style.sources.VectorSource;
const lineCap = com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap;
const lineColor = com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor;
const lineJoin = com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin;
const lineWidth = com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;
const LatLngBounds = com.mapbox.mapboxsdk.geometry.LatLngBounds;
const FillLayer = com.mapbox.mapboxsdk.style.layers.FillLayer;
const SymbolLayer = com.mapbox.mapboxsdk.style.layers.SymbolLayer;
const CircleLayer = com.mapbox.mapboxsdk.style.layers.CircleLayer;


 // Set the vector source (GLSource) for the mapbox map
    const vectorSource = new VectorSource(
      layer.ID.toString(),
      `http://themaptiles.cloudapp.net/data/${layer.GLSource}.json`
    );
    this._mapboxMap.addSource(vectorSource);

  let newLayer;
    if (layer.Type == "line") {
      console.log(`*** Creating new LineLayer ***`);
      newLayer = new LineLayer("line-layer", layer.ID.toString());

      // Obtain the line color for this style
      const lColor = style["line"]["line-color"];
      const androidColor = new Color(lColor).android; // Ends up valid and similar to -1293839 for android use

      newLayer.setSourceLayer(layer.ID.toString());

      // This will encounter an error with 'Failed resolving method setProperties on class com.mapbox.mapboxsdk.style.layers.Layer'
      newLayer.setProperties(
        PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
        PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
        PropertyFactory.lineColor(androidColor),
        PropertyFactory.lineWidth(new java.lang.Float(2))
      );
    }


this._mapboxMap.addLayer(newLayer);

If I avoid using the setProperties method, the code runs without issues but no visible line appears on the map after adding the layer.

Answer №1

One issue that arises in the interaction between Java and JavaScript is the challenge of handling variadic functions in NativeScript.

When examining mapbox's official API documentation, the Layer.setProperties method is found to require a list of arguments:

Unfortunately, extracting these arguments for the JNI -> Java call to Layer.setProperties is not straightforward when calling the function from JavaScript. A workaround involves wrapping the arguments in an array instead.

  newLayer.setProperties([
    PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
    PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
    PropertyFactory.lineColor(androidColor),
    PropertyFactory.lineWidth(new java.lang.Float(2))
  ]);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React fails to acknowledge union types

I have the following types defined: export enum LayersItemOptionsEnum { OPERATOR, HEADER, } type sharedTypes = { children: string | ReactElement; }; type LayersItemStatic = sharedTypes & { label: string; option: LayersItemOptionsEnum; }; t ...

Bring in typings from a package with an alternate title

I have a project that I am currently converting to typescript. In this project, I am using the package ng-idle. Additionally, there is a corresponding @types package named angular-idle, which contains the file @types/angular-idle/index.d.ts with the follow ...

Navigating TS errors when dealing with child components in Vue and Typescript

Recently, I encountered an issue where I created a custom class-based Vue component and wanted to access its methods and computed properties from a parent component. I found an example in the Vue Docs that seemed to address my problem (https://v2.vuejs.org ...

Why am I encountering issues accessing a child property in TypeScript?

Here is some TypeScript code that I am working with: export interface SelectQuery_thing { __typename: "ThingQueryPayload"; content: (SelectQuery_thing_content | null)[]; pageInfo: SelectQuery_thing_pageInfo; } export interface SelectQuery_thing_con ...

What is the process for removing a document with the 'where' function in Angular Fire?

var doc = this.afs.collection('/documents', ref => ref.where('docID', '==', docID)); After successfully retrieving the document requested by the user with the code above, I am unsure of how to proceed with deleting that do ...

Ways to transfer information among Angular's services and components?

Exploring the Real-Time Binding of Data Between Services and Components. Consider the scenario where isAuthenticated is a public variable within an Authentication service affecting a component's view. How can one subscribe to the changes in the isAut ...

Discovering the way in Android using Google Maps while providing latitude and longitude coordinates

I am trying to send the origin and destination points to Google for directions. I have noticed that when I use names for the origin and destination, it works correctly and returns accurate JSON information. However, when I provide latitude and longitude c ...

Challenges encountered while using TypeScript to implement the CSS breakpoint mixin

I attempted to replicate the breakpoint mixin functionality described at using TypeScript, but I am having trouble correctly typing the function. import { css } from 'styled-components'; import { breakpoints } from './_variables'; exp ...

Exploring Typescript: Enhancing the functionality of `export = Joi.Root`

I've noticed that the types for @hapi/joi appear to be outdated - some configuration parameters mentioned in the official documentation are missing from the types. To address this, I am attempting to enhance the existing types. node_modules/@types/ha ...

The module "@clerk/nextjs/server" does not contain a member with the name "clerkMiddleware" available for export

Currently, I am working on Nextjs 14 with typescript and implementing authentication and authorization using Clerk. Following the instructions in the Clerk documentation, I included the code snippet below in my middleware.ts file: import { authMiddleware } ...

Transforming Javascript into Typescript with node modules in Visual Studio 2015

After developing a JavaScript web app using npm and webpack, I successfully converted all the .js files to .ts using the PowerShell command found here. Now, I am looking to transition to a VS2015 TypeScript project but struggling to find guidance on how ...

What does `(keyof FormValues & string) | string` serve as a purpose for?

Hey there! I'm new to TypeScript and I'm a bit confused about the purpose of (keyof FormValues & string) | string. Can someone please explain it to me? export type FieldValues = Record<string, any>; export type FieldName<FormValues ...

What is the best way to save a Map for future use in different components?

Let's say I define an enum like this: export enum SomeEnum { SomeLongName = 1, AnotherName = 2 } Within my display components, I'm utilizing an enum map to translate the enum values into strings for presentation on the web app: enumMap = new Map ...

What are some techniques for breaking down or streamlining typescript code structures?

Within my TypeScript class, I have a skip function. In the interface, I've specified that the data is coming from the backend. Now, on the frontend, I want to be able to rename the backend variables as demonstrated below. There are multiple variables ...

The application experiences crashes when the tablet is rotated, happening while in the development stage

For my web-based Android application project, I am utilizing PhoneGap and Eclipse IDE on a Windows platform. My focus is specifically on Tablet development, more precisely on the Samsung Galaxy Tab 10.1. To develop, I use Eclipse and test the app on the ...

Generating Typescript definition files from JavaScript files with module.exports assignment

I'm currently working on creating a custom TypeScript definition file for format-duration: module.exports = (ms) => { let { days, hours, minutes, seconds } = parseMs(ms) seconds = addZero(seconds) if (days) return `${days}:${addZero(hours)}: ...

Is today within the current week? Utilizing Moment JS for time tracking

There is a problem that I am facing. Can you assist me in determining whether the day falls within the current week? I am currently developing a weather forecast service and need to validate if a given day is within the current week. The only clue I have ...

Is it possible that React.createElement does not accept objects as valid react children?

I am working on a simple text component: import * as React from 'react' interface IProps { level: 't1' | 't2' | 't3', size: 's' | 'm' | 'l' | 'xl' | 'xxl', sub ...

Leveraging default values in generic implementations

Imagine a scenario where the following code is present: type QueryResult<ResultType = string, ErrorType = string> = { result: ResultType, } | { errors: ErrorType, } So, if I want to initialize my result, I can proceed like this: const myResult: ...

Unable to locate the name 'JSON' in the typescript file

I have been working on an angular application where I have implemented JSON conversion functionalities such as JSON.stringify and JSON.parse. However, I encountered an error stating 'Cannot find name 'JSON''. Furthermore, there is anoth ...