Skip to content
nutiteq edited this page Mar 22, 2013 · 9 revisions

CartoDB provides nice geodata server as a service, with data storage, rich API, a lot of nice web-based client solutions and content management. You can keep your data in CartoDB and use Nutiteq SDK as Android native client solution. CartoDB provides several APIs, and we support following:

  • SQL API enables to use SQL (with PostGIS extension) to request vector data. As with every vector data you need to define styles for it also. We define here styles for all possible geometry types, so the layer would work for Points, Polygons and Lines. If you need Markers or Texts instead of Points, then you need to modify CartoDbVectorLayer.java data parser accordingly.
        // 1. Define styles for all possible geometry types
        int minZoom = 5;	 // minimal zoom to show the vector data
        int color = Color.BLUE;
		
        StyleSet<PointStyle> pointStyleSet = new StyleSet<PointStyle>();
        Bitmap pointMarker = UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.point);
        PointStyle pointStyle = PointStyle.builder().setBitmap(pointMarker).setSize(0.05f).setColor(color).setPickingSize(0.2f).build();
        pointStyleSet.setZoomStyle(minZoom, pointStyle);

        StyleSet<LineStyle> lineStyleSet = new StyleSet<LineStyle>();
        LineStyle lineStyle = LineStyle.builder().setWidth(0.05f).setColor(color).build();
        lineStyleSet.setZoomStyle(minZoom, lineStyle);

        PolygonStyle polygonStyle = PolygonStyle.builder().setColor(color & 0x80FFFFFF).setLineStyle(lineStyle).build();
        StyleSet<PolygonStyle> polygonStyleSet = new StyleSet<PolygonStyle>(null);
        polygonStyleSet.setZoomStyle(minZoom, polygonStyle);

        // 2. Define CartoDB.com layer and add it to the map
        String account = "nutiteq";
        // Estonian historical regions
        String table = "kihelkonnad_1897"; // Estonian historical regions
        // Define fields to be loaded NB! always include the_geom_webmercator for geometry 
        String columns = "kihelkond, the_geom_webmercator"; 
        int limit = 3000; // max number of objects. Over ~5000 may be problem for memory on some devices
        String sql = "SELECT "+columns+" FROM "+table+" WHERE "+CartoDbVectorLayer.TAG_WEBMERCATOR +" && ST_SetSRID('BOX3D(!bbox!)'::box3d, 3857) LIMIT "+limit;
        
        CartoDbVectorLayer cartoLayer = new CartoDbVectorLayer(mapView.getLayers().getBaseLayer().getProjection(), account, sql, pointStyleSet, lineStyleSet, polygonStyleSet);
        mapView.getLayers().addLayer(cartoLayer);

Source for CartoDbVectorLayer.java is in AdvancedMap3D application.

  • Map Tiles - you can use standard TMSMapLayer() for this. CartoDB tile URL format is http://{account}.cartodb.com/tiles/{table_name}/{z}/{x}/{y}.png, therefore adding Estonian historical regions as overlay layer in Nutiteq SDK would be:
      TMSMapLayer cartoDbTileLayer = new TMSMapLayer(this.proj, 1, 19,  15,
           "http://nutiteq.cartodb.com/tiles/kihelkonnad_1897/", "/", ".png");
      mapView.getLayers().addLayer(cartoDbTileLayer);

Screenshot with demo data

Clone this wiki locally