2017-12-18 23 views
0

Geojson 레이어를 가져 와서 색상을 적용하고 싶습니다. 아래 코드를 사용하면이 영역의 맨 위에 검정색 선이 있습니다. 그 부분은 정확합니다, 그냥 영역에 색과 음영을 추가해야합니다. 그러나 나는 geojson이 작업을 수행 할 수있는 간단한 방법을보고 있지 않다 또는Google지도 geojson 개체/geolayer의 색상 및 음영 영역 설정 sdk android

enter image description here

private void drawNeighborhood(int neighborhoodIndex) { 
    try { 
     mMap.clear(); 
     if (mViewModel.validateNeighborboodsState()) { 
     return; 
     } 

     Features[] featuresArray = mViewModel.getFeature(); 
     final LatLngBounds.Builder builder = LatLngBounds.builder(); 
     if (featuresArray.length > neighborhoodIndex) { 
     Features currentFeature = featuresArray[neighborhoodIndex]; 
     GeoJsonLayer geoJsonLayer = getGeoJsonLayer(currentFeature); 
     createViewArea(builder, currentFeature); 
     final CameraUpdate cameraUpdate = 
      CameraUpdateFactory.newLatLngBounds(builder.build(), 200); 
     mMap.animateCamera(cameraUpdate); 
     geoJsonLayer.addLayerToMap(); 
     } 

    } catch (JSONException e) { 
     Timber.e("GeoJSON file could not be converted to a JSONObject"); 
    } 

    } 




private GeoJsonLayer getGeoJsonLayer(Features features) throws JSONException { 
    Gson gson = new Gson(); 
    String raw = gson.toJson(features); 
    JSONObject json = new JSONObject(raw); 
    return new GeoJsonLayer(mMap, json); 
    } 

기능 모델 지역의 기반이되는 무슨 그런

public class Features { 
    private Properties properties; 

    private String type; 

    private Geometry geometry; 

    public Properties getProperties() { 
    return properties; 
    } 

    public void setProperties(Properties properties) { 
    this.properties = properties; 
    } 

    public String getType() { 
    return type; 
    } 

    public void setType(String type) { 
    this.type = type; 
    } 

    public Geometry getGeometry() { 
    return geometry; 
    } 

    public void setGeometry(Geometry geometry) { 
    this.geometry = geometry; 
    } 

    @Override 
    public String toString() { 
    return "ClassPojo [properties = " + properties + ", type = " + type + ", geometry = " + geometry + "]"; 
    } 
} 

에게 객체 geolayer. (항상 선이 아닌 다각형입니다.) 해야 바닐라 geojson 사양

public class Geometry { 
    private String type; 

    private String[][][] coordinates; 

    public String getType() { 
    return type; 
    } 

    public void setType(String type) { 
    this.type = type; 
    } 

    public String[][][] getCoordinates() { 
    return coordinates; 
    } 

    public void setCoordinates(String[][][] coordinates) { 
    this.coordinates = coordinates; 
    } 

    @Override 
    public String toString() { 
    return "ClassPojo [type = " + type + ", coordinates = " + coordinates + "]"; 
    } 
} 

답변

1

나는 Google 워드 프로세서를 잘못 생각했다. 해결책은 다음과 같습니다.

Features[] featuresArray = mViewModel.getFeature(); 
    final LatLngBounds.Builder builder = LatLngBounds.builder(); 
    if (featuresArray.length > neighborhoodIndex) { 
    Features currentFeature = featuresArray[neighborhoodIndex]; 
    GeoJsonLayer geoJsonLayer = getGeoJsonLayer(currentFeature); 


    GeoJsonPolygonStyle geoJsonPolygonStyle = geoJsonLayer.getDefaultPolygonStyle(); 


    int color = Color.parseColor(currentFeature.getProperties().getColor()); 
    int colorTransparent = ColorUtils.setAlphaComponent(color, 100); 
    geoJsonPolygonStyle.setStrokeColor(color); 
    geoJsonPolygonStyle.setFillColor(colorTransparent); 
    createViewArea(builder, currentFeature); 
    final CameraUpdate cameraUpdate = 
     CameraUpdateFactory.newLatLngBounds(builder.build(), 200); 
    mMap.animateCamera(cameraUpdate); 
    geoJsonLayer.addLayerToMap(); 
    }