2016-10-27 1 views
0

Mapbox Android SDK 버전 4.2.0.beta4를 사용하여 폴리곤 외부에서 1px 스트로크의 폭을 늘리려고합니다.Mapbox Android SDK를 사용하여 폴리곤 획의 크기를 변경하는 방법

먼저 PolygonOptions를 사용했지만 사용 가능한 옵션이 없습니다.

public Polygon addPolygon(MapboxMap mapboxMap) { 
    PolygonOptions polygonOptions = new PolygonOptions() 
        .addAll(latLngs) 
        .alpha(ALPHA_UNSELECTED) 
        .fillColor(FILL_COLOR) 
        .strokeColor(BORDER_COLOR); 

    // no option for stroke width 

    return mapboxMap.addPolygon(polygonOptions); 
} 
https://www.mapbox.com/mapbox-gl-style-spec/

public void changeStrokeWidth(MapboxMap mapboxMap) { 
     Layer styleLayer = mapboxMap.getLayer("background"); 

     styleLayer.setProperties(PropertyFactory.lineWidth(10f)); 
} 

사람은 알고 있나요 내가 그 스타일 사양에 정의되어 있지만 적절한 레이어 ID를 찾을 수 없습니다로 사용하여 새 런타임 스타일 API를 사용하여 시도

, 나는 "배경"을 시도 이 작업을 수행하는 방법 또는 동작을 에뮬레이트하기 위해 폴리곤의 맨 위에 자체 폴리 라인 세트를 만들어야합니까?

답변

0

여기에 몇 가지 옵션이 있습니다. 현재 우리는 다각형 스트로크 폭을 증가시킬 수있는 방법을 제공하지 않습니다하지만 당신은 할 수 있습니다

  1. 다각형을 구성하는 같은 latlng의를 사용하여 폴리 라인을 추가합니다. 이것은 훨씬 쉬운 방법이지만 폴리 라인이 맵 상단에 추가되는 것을 고려해야합니다 (때때로 레이블을 덮음).

  2. 두 번째 옵션은 다각형과 동일한 지오메트리를 사용하여지도에 선형 레이어를 추가하는 것입니다. 여기에 an example이 포인트를 가져 와서 이러한 레이어를 만드는 방법을 보여줍니다.

추가 질문 사항이 있으면 알려주십시오.

+0

많은 정보를 제공해 주셔서 감사합니다. 참고 사항 새로운 런타임 스타일로 덮여 있었다는 느낌을주는 github에서 닫힌 두 장의 티켓이 있습니다. https://github.com/mapbox/mapbox-gl-native/issues/1737 https://github.com/mapbox/mapbox-gl-native/issues/324 –

+0

다소 오래된 티켓;) 실제로 런타임 스타일을 구현하기 전에 이것은 방법이었습니다. 우리는 여전히 SDK를 개선하기 위해 노력 중이며 다음 릴리스에서 주석 (폴리곤 포함) 개선을 고려했습니다. – cammace

0
//Hi, Guys. Below is the simple example to change the properties of polygon border. Hope it will help you.// 

{ 

List<LatLng> plotPolygon = new ArrayList<>(); 

List<com.mapbox.services.commons.models.Position> coordinates = new ArrayList<>(); 

        plotPolygon.add(new LatLng(18.9965099,75.7316343)); 
        plotPolygon.add(new LatLng(20.8858018,74.7288414)); 
        plotPolygon.add(new LatLng(21.1612315,79.0024702)); 
        plotPolygon.add(new LatLng(18.7918749,78.899195)); 
        plotPolygon.add(new LatLng(18.9965099,75.7316343)); 

        Polygon polygon1 = mapboxMap.addPolygon(new PolygonOptions() 
          .addAll(plotPolygon) 
        );   
        polygon1.setFillColor(Color.parseColor("#3bb2d0")); 

다음은 다각형 테두리 좌표 목록을 작성하는 것입니다.

    coordinates.add(com.mapbox.services.commons.models.Position.fromCoordinates(75.7316343 , 18.9965099)); 
        coordinates.add(com.mapbox.services.commons.models.Position.fromCoordinates(74.7288414 , 20.8858018)); 
        coordinates.add(com.mapbox.services.commons.models.Position.fromCoordinates(79.0024702 , 21.1612315)); 
        coordinates.add(com.mapbox.services.commons.models.Position.fromCoordinates(78.899195 , 18.7918749)); 
        coordinates.add(com.mapbox.services.commons.models.Position.fromCoordinates(75.7316343 , 18.9965099)); 

changeStrokeProperties(mapboxMap , coordinates); 

} 

public void changeStrokeProperties(MapboxMap mapboxMap , List<com.mapbox.services.commons.models.Position> coordinates) { 

// Create the LineString from the list of coordinates and then make a GeoJSON// 
// FeatureCollection so we can add the line to our map as a layer.// 

    final Feature lineFeature =  Feature.fromGeometry(LineString.fromCoordinates(coordinates)); 

     final GeoJsonSource source = new GeoJsonSource(
       "route", FeatureCollection.fromFeatures(new Feature[] { lineFeature })); 


      mapboxMap.addSource(source); 


      LineLayer lineLayer = new LineLayer("linelayer", "route"); 

      lineLayer.setProperties(
        PropertyFactory.lineDasharray(new Float[]{0.01f, 2f}), 
        PropertyFactory.lineCap(Property.LINE_CAP_ROUND), 
        PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND), 
        PropertyFactory.lineWidth(5f), 
        PropertyFactory.lineColor(Color.parseColor("#e55e5e")) 

      ); 
      mapboxMap.addLayer(lineLayer); 

    } 
관련 문제