Advertisement
Guest User

Nutiteq JNI

a guest
Nov 24th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.56 KB | None | 0 0
  1. I tried with a Ogr Layer and with a Ogr Vector Datasource, this last one is what I show you.
  2. ...
  3. import com.nutiteq.datasources.vector.OGRVectorDataSource;
  4. import com.nutiteq.layers.vector.OgrLayer;
  5. ...
  6.  
  7.     private void doRestrictedZones() {
  8.         // TODO Auto-generated method stub
  9.         mDrawerLayout.closeDrawers();
  10.  
  11.             Class<?> activityToRun = (Class<?>) WmsMapActivity.class;
  12.             FilePicker activityInstance = null;
  13.             try {
  14.                 activityInstance = (FilePicker) activityToRun.newInstance();
  15.         } catch (InstantiationException e) {
  16.             // TODO Auto-generated catch block
  17.             e.printStackTrace();
  18.         } catch (IllegalAccessException e) {
  19.             // TODO Auto-generated catch block
  20.             e.printStackTrace();
  21.         }
  22.  
  23.             FilePickerActivity.setFileSelectMessage(activityInstance.getFileSelectMessage());
  24.             FilePickerActivity.setFileDisplayFilter(activityInstance.getFileFilter());             
  25.                
  26.         Intent intent = new Intent(WmsMapActivity.this, FilePickerActivity.class);
  27.         Bundle bundle = new Bundle();
  28.         bundle.putString("class", "WmsMapActivity");
  29.                
  30.         intent.putExtras(bundle);
  31.         startActivityForResult(intent, PICK_FILE );            
  32.     }
  33.  
  34.     @Override
  35.     protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  36.         switch(requestCode){
  37.  
  38.             case PICK_FILE:
  39.                 if (resultCode == RESULT_OK ) {
  40.                     // read filename from extras
  41.                     //Bundle b    = intent.getExtras();;//getIntent().getExtras();
  42.                     String file = intent.getStringExtra("selectedFile");
  43.    
  44.                     createStyleSets();
  45.                     if (file.endsWith(".db") || file.endsWith(".sqlite") || file.endsWith(".spatialite")) {
  46.                         Log.i("TAG", "WmsMapActivity::onActivityResult:: NOT Vector File");
  47.                     } else {
  48.                         addOgrVectorDataSourceLayer(mapLayer.getProjection(), file, null, Color.BLUE);
  49.                     }              
  50.                 }
  51.             break;
  52.         }
  53.     }
  54.    
  55.     // JNI Java Part
  56.     private void addOgrVectorDataSourceLayer(Projection proj, String dbPath, String table, int color) {
  57.         OGRVectorDataSource dataSource;
  58.         try {
  59.             dataSource = new OGRVectorDataSource(proj, dbPath, table) {
  60.                 @Override
  61.                 protected Label createLabel(Map<String, String> userData) {
  62.                     return WmsMapActivity.this.createLabel(userData);
  63.                 }
  64.  
  65.                 @Override
  66.                 protected StyleSet<PointStyle> createPointStyleSet(Map<String, String> userData, int zoom) {
  67.                     return pointStyleSet;
  68.                 }
  69.  
  70.                 @Override
  71.                 protected StyleSet<LineStyle> createLineStyleSet(Map<String, String> userData, int zoom) {
  72.                     return lineStyleSet;
  73.                 }
  74.  
  75.                 @Override
  76.                 protected StyleSet<PolygonStyle> createPolygonStyleSet(Map<String, String> userData, int zoom) {
  77.                     return polygonStyleSet;
  78.                 }
  79.  
  80.             };
  81.         } catch (IOException e) {
  82.             Log.e("TAG",e.getLocalizedMessage());
  83.             //Toast.makeText(this, "ERROR "+e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
  84.             return;
  85.         }
  86.  
  87.         dataSource.setMaxElements(MAX_ELEMENTS);
  88.  
  89.         GeometryLayer ogrLayer = new GeometryLayer(dataSource);
  90.         mapView.getLayers().addLayer(ogrLayer);
  91.  
  92.         Envelope extent = ogrLayer.getDataExtent();
  93.         mapView.setBoundingBox(new Bounds(extent.minX, extent.maxY, extent.maxX, extent.minY), false);
  94.     }  
  95. //*******************************************************************************************************//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement