2017-11-09 1 views
2

MapboxMap에 VectorSource를 추가하기 위해 Android Mapbox SDK를 사용하고 있는데,지도에 LineLayer도 추가하려고합니다. LineLayer의 MapBox setProperties가 해결되지 않습니다.

현재는 네이티브 라이브러리 및 네이티브 안드로이드/아이폰 OS API에 직접 액세스의 소비를 수있는 NativeScript 프레임 워크를 사용하고 있기 때문에이 코드는 타이프에 될 것입니다 버전 5.1.3

를 사용하여.

// these constants are just simple ways to reference a class 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 map GLSource (vector) to 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()); 

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

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

     // will throw here 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); 

내가 setProperties 방법 다음 코드가 잘 실행하지만 레이어가 추가 된 후지도에 보이는 라인이 존재하지를 사용하지 않는 경우

.

+0

안녕하세요 @ 브래드 마틴, 당신은 속성의 배열을'setProperties' 가변 방식으로 전달할 수 있습니까? – pkanev

+0

감사합니다 @ pkanev - 배열로 설정을 전달하면 실제로 예외가 발생하지 않습니다. –

답변

3

많은 자바 중 하나 < -> NativeScript에서 JavaScript 비 호환성 및 문제점 - 가변 기능. > Layer.setProperties 자바 호출이 쉽게 자바 스크립트 함수 호출에서 추출 할 수 없습니다 - https://www.mapbox.com/android-docs/api/map-sdk/5.2.0-beta.3/com/mapbox/mapboxsdk/style/layers/Layer.html#setProperties-com.mapbox.mapboxsdk.style.layers.PropertyValue...- 그러나

의 JNI에 대한 의미 인수 : mapbox의 공식 API를 보면

Layer.setProperties 방법은 인수 목록을 소요 심판 대신 배열에 인수를 래핑해야합니다.

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