com.nextgis.maplib.map.VectorLayer Java Examples

The following examples show how to use com.nextgis.maplib.map.VectorLayer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RuleFeatureRendererUI.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Fragment getSettingsScreen(VectorLayer vectorLayer) {
    mSettings = super.getSettingsScreen(vectorLayer);

    if (mSettings == null) {
        RuleStyleFragment fragment = new RuleStyleFragment();
        fragment.mRenderer = (RuleFeatureRenderer) mRenderer;
        fragment.mStyleRule = (FieldStyleRule) fragment.mRenderer.getStyleRule();

        if (fragment.mStyleRule == null) {
            fragment.mStyleRule = new FieldStyleRule(mLayer);
            fragment.mRenderer.setStyleRule(fragment.mStyleRule);
        }

        mSettings = fragment;
    }

    return mSettings;
}
 
Example #2
Source File: CreateVectorLayerActivity.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
private boolean createNewLayer() {
    MainApplication app = (MainApplication) getApplication();
    int geomType = getResources().getIntArray(R.array.geom_types)[mSpLayerType.getSelectedItemPosition()];
    List<Field> fields = mFieldAdapter.getFields();
    if (fields.size() == 0)
        fields.add(new Field(GeoConstants.FTString, "description", getString(R.string.default_field_name)));
    else
        for (int i = 0; i < fields.size(); i++)
            fields.get(i).setName("field_" + (i + 1));

    VectorLayer layer = app.createEmptyVectorLayer(mEtLayerName.getText().toString().trim(), null, geomType, fields);

    SimpleFeatureRenderer sfr = (SimpleFeatureRenderer) layer.getRenderer();
    if (null != sfr) {
        Style style = sfr.getStyle();
        if (null != style) {
            Random rnd = new Random(System.currentTimeMillis());
            style.setColor(Color.rgb(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255)));
        }
    }

    MapBase map = app.getMap();
    map.addLayer(layer);
    return map.save();
}
 
Example #3
Source File: AttributesFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
public void setSelectedFeature(
        VectorLayer selectedLayer,
        long selectedItemId)
{
    mItemId = selectedItemId;
    mLayer = selectedLayer;

    if (mLayer == null)
        return;

    mFeatureIDs = mLayer.query(null); // get all feature IDs

    for (int i = 0; i < mFeatureIDs.size(); i++) {
        if (mFeatureIDs.get(i) == mItemId) {
            mItemPosition = i;
            break;
        }
    }

    setAttributes();
}
 
Example #4
Source File: LayerContentProvider.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public int update(
        Uri uri,
        ContentValues contentValues,
        String s,
        String[] strings)
{
    Layer layer = getLayerByUri(uri);
    if (null == layer) {
        return 0;
    }

    if (layer instanceof VectorLayer) {
        return ((VectorLayer) layer).update(uri, contentValues, s, strings);
    }

    if (layer instanceof TrackLayer) {
        return ((TrackLayer) layer).update(uri, contentValues, s, strings);
    }

    return 0;
}
 
Example #5
Source File: LayerContentProvider.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public int delete(
        Uri uri,
        String s,
        String[] strings)
{
    Layer layer = getLayerByUri(uri);
    if (null == layer) {
        return 0;
    }

    if (layer instanceof VectorLayer) {
        return ((VectorLayer) layer).delete(uri, s, strings);
    }

    if (layer instanceof TrackLayer) {
        return ((TrackLayer) layer).delete(uri, s, strings);
    }

    return 0;
}
 
Example #6
Source File: LayerContentProvider.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Uri insert(
        Uri uri,
        ContentValues contentValues)
{
    Layer layer = getLayerByUri(uri);
    if (null == layer) {
        return null;
    }

    if (layer instanceof VectorLayer) {
        return ((VectorLayer) layer).insert(uri, contentValues);
    }

    if (layer instanceof TrackLayer) {
        return ((TrackLayer) layer).insert(uri, contentValues);
    }

    return null;
}
 
Example #7
Source File: LayerContentProvider.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public String getType(Uri uri)
{
    Layer layer = getLayerByUri(uri);
    if (null == layer) {
        return null;
    }

    if (layer instanceof VectorLayer) {
        return ((VectorLayer) layer).getType(uri);
    }

    if (layer instanceof TrackLayer) {
        return ((TrackLayer) layer).getType(uri);
    }

    return null;
}
 
Example #8
Source File: SimpleFeatureRenderer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Style applyField(Style style, long featureId) {
    if (style instanceof ITextStyle) {
        String fieldValue = ((ITextStyle) style).getField();

        if (fieldValue != null) {
            Feature feature = ((VectorLayer) getLayer()).getFeature(featureId);
            if (fieldValue.equals(FIELD_ID))
                fieldValue = feature.getId() + "";
            else
                fieldValue = feature.getFieldValueAsString(fieldValue);

            ((ITextStyle) style).setText(fieldValue);
        }
    }

    return style;
}
 
Example #9
Source File: VectorLayerSettingsActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (mLayer == null)
        return;

    if (mLayer.getType() == Constants.LAYERTYPE_LOCAL_VECTOR
            || mLayer.getType() == Constants.LAYERTYPE_NGW_VECTOR
            || mLayer.getType() == Constants.LAYERTYPE_NGW_WEBMAP) {
        mVectorLayer = (VectorLayer) mLayer;
        mLayerMinZoom = mVectorLayer.getMinZoom();
        mLayerMaxZoom = mVectorLayer.getMaxZoom();
        mRenderer = mVectorLayer.getRenderer();
        mToolbar = findViewById(R.id.main_toolbar);
        setSubtitle();
    }
}
 
Example #10
Source File: ModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void createView(final IGISApplication app, Bundle savedState)
{
    //create and fill controls
    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        int layerId = extras.getInt(KEY_LAYER_ID);
        MapBase map = app.getMap();
        mLayer = (VectorLayer) map.getLayerById(layerId);

        if (null != mLayer) {
            mSharedPreferences = mLayer.getPreferences();

            mFields = new HashMap<>();
            mFeatureId = extras.getLong(KEY_FEATURE_ID);
            mIsViewOnly = extras.getBoolean(KEY_VIEW_ONLY, false);
            mIsGeometryChanged = extras.getBoolean(KEY_GEOMETRY_CHANGED, true);
            mGeometry = (GeoGeometry) extras.getSerializable(KEY_GEOMETRY);
            LinearLayout layout = findViewById(R.id.controls_list);
            fillControls(layout, savedState);
        } else {
            Toast.makeText(this, R.string.error_layer_not_inited, Toast.LENGTH_SHORT).show();
            finish();
        }
    }
}
 
Example #11
Source File: AttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Constants.NOTIFY_DELETE);
    intentFilter.addAction(Constants.NOTIFY_DELETE_ALL);
    registerReceiver(mReceiver, intentFilter);

    IGISApplication application = (IGISApplication) getApplication();
    MapBase map = application.getMap();

    if (null != map) {
        ILayer layer = map.getLayerById(mLayerId);
        if (null != layer && layer instanceof VectorLayer) {
            mLayer = (VectorLayer) layer;
            mTable.setAdapter(getAdapter());
            Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
            toolbar.setSubtitle(mLayer.getName());
        } else
            Toast.makeText(this, R.string.error_layer_not_inited, Toast.LENGTH_SHORT).show();
    }
}
 
Example #12
Source File: FormBuilderModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void appendData(VectorLayer layer, SharedPreferences preferences, Map<String, List<String>> table, int row,
                              IFormControl control, JSONObject element) throws JSONException {
    if (layer instanceof NGWVectorLayer)
        element.put(SyncStateContract.Columns.ACCOUNT_NAME, ((NGWVectorLayer) layer).getAccountName());

    if (preferences != null) {
        element.put(PREF_FIRST_NAME, preferences.getString(PREF_FIRST_NAME, ""));
        element.put(PREF_LAST_NAME, preferences.getString(PREF_LAST_NAME, ""));
        element.put(PREF_USERNAME, preferences.getString(PREF_USERNAME, ""));
    }

    if (control instanceof Counter && table != null && row != -1) {
        JSONObject attrs = element.getJSONObject(JSON_ATTRIBUTES_KEY);
        if (!attrs.isNull(Counter.PREFIX_LIST)) {
            String prefix = attrs.getString(Counter.PREFIX_LIST);
            prefix = table.get(prefix).get(row);
            attrs.put(Counter.PREFIX, prefix);
        }

        if (!attrs.isNull(Counter.SUFFIX_LIST)) {
            String suffix = attrs.getString(Counter.SUFFIX_LIST);
            suffix = table.get(suffix).get(row);
            attrs.put(Counter.SUFFIX, suffix);
        }
    }
}
 
Example #13
Source File: LayerFillService.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(IProgressor progressor) {
    try {
        VectorLayer vectorLayer = (VectorLayer) mLayer;
        if(null == vectorLayer)
            return false;

        vectorLayer.createFromGeoJson(mUri, progressor);
    } catch (IOException | JSONException | SQLiteException | NGException | ClassCastException e) {
        e.printStackTrace();
        setError(e, progressor);
        notifyError(mProgressMessage);
        return false;
    }

    return true;
}
 
Example #14
Source File: DrawItem.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void deleteSelectedPoint(VectorLayer layer) {
    float[] points = getSelectedRing();
    if (null == points || mSelectedPoint < 0)
        return;

    if (points.length <= getMinPointCount(layer.getGeometryType()) * 2) {
        mDrawItemsVertex.remove(mSelectedRing);
        mSelectedRing = mDrawItemsVertex.size() > 0 ? 0 : Constants.NOT_FOUND;
        mSelectedPoint = Constants.NOT_FOUND;
        return;
    }

    float[] newPoints = new float[points.length - 2];
    int counter = 0;
    for (int i = 0; i < points.length; i++) {
        if (i == mSelectedPoint || i == mSelectedPoint + 1)
            continue;

        newPoints[counter++] = points[i];
    }

    if (mSelectedPoint >= newPoints.length)
        mSelectedPoint = 0;

    setRing(mSelectedRing, newPoints);
}
 
Example #15
Source File: PhotoGallery.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void getAttaches(IGISApplication app, VectorLayer layer, long featureId, Map<String, Integer> map, boolean excludeSign, String comment) {
    Uri uri = Uri.parse("content://" + app.getAuthority() + "/" +
            layer.getPath().getName() + "/" + featureId + "/" + Constants.URI_ATTACH);
    MatrixCursor attachCursor = (MatrixCursor) layer.query(uri,
            new String[]{VectorLayer.ATTACH_DATA, VectorLayer.ATTACH_ID, VectorLayer.ATTACH_DESCRIPTION},
            FIELD_ID + " = " + featureId, null, null, null);

    if (attachCursor.moveToFirst()) {
        do {
            if (excludeSign && attachCursor.getInt(1) == Integer.MAX_VALUE)
                continue;

            if (comment != null && !attachCursor.getString(2).equals(comment))
                continue;
            map.put(attachCursor.getString(0), attachCursor.getInt(1));
        } while (attachCursor.moveToNext());
    }

    attachCursor.close();
}
 
Example #16
Source File: RebuildCacheService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void startNextTask() {
    if (mQueue.isEmpty()) {
        stopService();
        return;
    }

    mIsCanceled = false;
    final IProgressor progressor = this;
    new Thread(new Runnable() {
        @Override
        public void run() {
            mLayer = (VectorLayer) MapBase.getInstance().getLayerById(mQueue.remove(0));
            mIsRunning = true;
            mCurrentTasks++;
            String notifyTitle = getString(R.string.rebuild_cache);
            notifyTitle += ": " + mCurrentTasks + "/" + mQueue.size() + 1;

            mBuilder.setWhen(System.currentTimeMillis())
                    .setContentTitle(notifyTitle)
                    .setTicker(notifyTitle);
            mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());

            Process.setThreadPriority(Constants.DEFAULT_DOWNLOAD_THREAD_PRIORITY);
            if (mLayer != null)
                mLayer.rebuildCache(progressor);

            mIsRunning = mRemoveCurrent = false;
            startNextTask();
        }
    }).start();
}
 
Example #17
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
void testAttachUpdate()
{
    IGISApplication application = (IGISApplication) getApplication();
    /*MapBase map = application.getMap();
    NGWVectorLayer ngwVectorLayer = null;
    for(int i = 0; i < map.getLayerCount(); i++){
        ILayer layer = map.getLayer(i);
        if(layer instanceof NGWVectorLayer)
        {
            ngwVectorLayer = (NGWVectorLayer)layer;
        }
    }
    if(null != ngwVectorLayer) {
        Uri updateUri = Uri.parse("content://" + SettingsConstants.AUTHORITY + "/" +
                                  ngwVectorLayer.getPath().getName() + "/36/attach/1000");
    */
    Uri updateUri = Uri.parse(
            "content://" + AppSettingsConstants.AUTHORITY +
            "/layer_20150210140455993/36/attach/2");

    ContentValues values = new ContentValues();
    values.put(VectorLayer.ATTACH_DISPLAY_NAME, "no_image.jpg");
    values.put(VectorLayer.ATTACH_DESCRIPTION, "simple update description");
    //    values.put(VectorLayer.ATTACH_ID, 999);
    int result = getContentResolver().update(updateUri, values, null, null);
    if(Constants.DEBUG_MODE){
        if (result == 0) {
            Log.d(TAG, "update failed");
        } else {
            Log.d(TAG, "" + result);
        }
    }
    //}
}
 
Example #18
Source File: MainApplication.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
public VectorLayer createEmptyVectorLayer(
        String layerName,
        String layerPath,
        int layerType,
        List<Field> fields)
{
    VectorLayerUI vectorLayer = new VectorLayerUI(this, mMap.createLayerStorage(layerPath));
    vectorLayer.setName(layerName);
    vectorLayer.setVisible(true);
    vectorLayer.setMinZoom(GeoConstants.DEFAULT_MIN_ZOOM);
    vectorLayer.setMaxZoom(GeoConstants.DEFAULT_MAX_ZOOM);

    vectorLayer.create(layerType, fields);
    return vectorLayer;
}
 
Example #19
Source File: SimpleFeatureRendererUI.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Fragment getSettingsScreen(VectorLayer vectorLayer) {
    mSettings = super.getSettingsScreen(vectorLayer);
    if (mSettings == null) {
        mSettings = new StyleFragment();
        ((StyleFragment) mSettings).setStyle(mStyle);
        ((StyleFragment) mSettings).setLayer(vectorLayer);
    }

    return mSettings;
}
 
Example #20
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
public void onFinishChooseLayerDialog(
        int code,
        ILayer layer)
{
    VectorLayer vectorLayer = (VectorLayer) layer;
    if (layer == null)
        return; // TODO toast?

    if (mSelectedLayer != null)
        mSelectedLayer.setLocked(false);

    mSelectedLayer = vectorLayer;
    mEditLayerOverlay.setSelectedLayer(vectorLayer);

    if (code == ADD_CURRENT_LOC) {
        if (layer instanceof ILayerUI) {
            IVectorLayerUI layerUI = (IVectorLayerUI) layer;
            layerUI.showEditForm(mActivity, Constants.NOT_FOUND, null);
        }
    } else if (code == EDIT_LAYER) {
        setMode(MODE_SELECT_ACTION);
    } else if (code == ADD_GEOMETRY_BY_WALK) {
        mEditLayerOverlay.newGeometryByWalk();
        setMode(MODE_EDIT_BY_WALK);
    } else if (code == ADD_POINT_BY_TAP) {
        createPointFromOverlay();
    }
}
 
Example #21
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected void addGeometryByWalk()
{
    //show select layer dialog if several layers, else start default or custom form
    List<ILayer> layers = mMap.getVectorLayersByType(GeoConstants.GTLineStringCheck | GeoConstants.GTPolygonCheck
            | GeoConstants.GTMultiLineStringCheck | GeoConstants.GTMultiPolygonCheck);
    layers = removeHideLayers(layers);

    if (layers.isEmpty()) {
        Toast.makeText(mActivity, getString(R.string.warning_no_edit_layers), Toast.LENGTH_LONG).show();
    } else if (layers.size() == 1) {
        //open form
        VectorLayer layer = (VectorLayer) layers.get(0);
        mSelectedLayer = layer;
        mEditLayerOverlay.setSelectedLayer(layer);
        mEditLayerOverlay.newGeometryByWalk();
        setMode(MODE_EDIT_BY_WALK);

        Toast.makeText(mActivity, String.format(getString(R.string.edit_layer), layer.getName()), Toast.LENGTH_SHORT).show();
    } else {
        if (isDialogShown())
            return;
        //open choose edit layer dialog
        mChooseLayerDialog = new ChooseLayerDialog();
        mChooseLayerDialog.setLayerList(layers)
                .setCode(ADD_GEOMETRY_BY_WALK)
                .setTitle(getString(R.string.choose_layers))
                .setTheme(mActivity.getThemeId())
                .show(mActivity.getSupportFragmentManager(), "choose_layer");
    }
}
 
Example #22
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected void addCurrentLocation()
{
    //show select layer dialog if several layers, else start default or custom form
    List<ILayer> layers = mMap.getVectorLayersByType(
            GeoConstants.GTMultiPointCheck | GeoConstants.GTPointCheck);
    layers = removeHideLayers(layers);
    if (layers.isEmpty()) {
        Toast.makeText(
                mActivity, getString(R.string.warning_no_edit_layers), Toast.LENGTH_LONG)
                .show();
    } else if (layers.size() == 1) {
        //open form
        ILayer vectorLayer = layers.get(0);
        if (vectorLayer instanceof ILayerUI) {
            mSelectedLayer = (VectorLayer) vectorLayer;
            mEditLayerOverlay.setSelectedLayer(mSelectedLayer);
            IVectorLayerUI vectorLayerUI = (IVectorLayerUI) vectorLayer;
            vectorLayerUI.showEditForm(mActivity, Constants.NOT_FOUND, null);

            Toast.makeText(
                    mActivity,
                    String.format(getString(R.string.edit_layer), vectorLayer.getName()),
                    Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(
                    mActivity, getString(R.string.warning_no_edit_layers),
                    Toast.LENGTH_LONG).show();
        }
    } else {
        if (isDialogShown())
            return;
        //open choose dialog
        mChooseLayerDialog = new ChooseLayerDialog();
        mChooseLayerDialog.setLayerList(layers)
                .setCode(ADD_CURRENT_LOC)
                .setTitle(getString(R.string.choose_layers))
                .setTheme(mActivity.getThemeId())
                .show(mActivity.getSupportFragmentManager(), "choose_layer");
    }
}
 
Example #23
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected void addPointByTap()
{
    if (mSelectedLayer != null)
        mSelectedLayer.setLocked(false);

    //show select layer dialog if several layers, else start default or custom form
    List<ILayer> layers = mMap.getVectorLayersByType(GeoConstants.GTPointCheck | GeoConstants.GTMultiPointCheck);
    layers = removeHideLayers(layers);
    if (layers.isEmpty()) {
        Toast.makeText(
                mActivity, getString(R.string.warning_no_edit_layers), Toast.LENGTH_LONG)
                .show();
    } else if (layers.size() == 1) {
        //open form
        VectorLayer layer = (VectorLayer) layers.get(0);

        mSelectedLayer = layer;
        mEditLayerOverlay.setSelectedLayer(layer);
        createPointFromOverlay();

        Toast.makeText(
                mActivity,
                String.format(getString(R.string.edit_layer), layer.getName()),
                Toast.LENGTH_SHORT).show();
    } else {
        if (isDialogShown())
            return;
        //open choose edit layer dialog
        mChooseLayerDialog = new ChooseLayerDialog();
        mChooseLayerDialog.setLayerList(layers)
                .setCode(ADD_POINT_BY_TAP)
                .setTitle(getString(R.string.choose_layers))
                .setTheme(mActivity.getThemeId())
                .show(mActivity.getSupportFragmentManager(), "choose_layer");
    }
}
 
Example #24
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected void addNewGeometry()
{
    mApp.sendEvent(GA_LAYER, GA_EDIT, GA_FAB);

    //show select layer dialog if several layers, else start default or custom form
    List<ILayer> layers = mMap.getVectorLayersByType(
            GeoConstants.GTPointCheck | GeoConstants.GTMultiPointCheck |
            GeoConstants.GTLineStringCheck | GeoConstants.GTMultiLineStringCheck |
            GeoConstants.GTPolygonCheck | GeoConstants.GTMultiPolygonCheck);
    layers = removeHideLayers(layers);
    if (layers.isEmpty()) {
        Toast.makeText(mActivity, getString(R.string.warning_no_edit_layers), Toast.LENGTH_LONG).show();
    } else if (layers.size() == 1) {
        //open form
        VectorLayer layer = (VectorLayer) layers.get(0);

        mSelectedLayer = layer;
        mEditLayerOverlay.setSelectedLayer(layer);
        setMode(MODE_SELECT_ACTION);

        Toast.makeText(mActivity, String.format(getString(R.string.edit_layer), layer.getName()), Toast.LENGTH_SHORT).show();
    } else {
        if (isDialogShown())
            return;
        //open choose edit layer dialog
        mChooseLayerDialog = new ChooseLayerDialog();
        mChooseLayerDialog.setLayerList(layers)
                .setCode(EDIT_LAYER)
                .setTitle(getString(R.string.choose_layers))
                .setTheme(mActivity.getThemeId())
                .show(mActivity.getSupportFragmentManager(), "choose_layer");
    }
}
 
Example #25
Source File: AttachItem.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ContentValues getContentValues(boolean withAttachId) {
    ContentValues returnValues = new ContentValues();
    returnValues.put(VectorLayer.ATTACH_DISPLAY_NAME, mDisplayName);
    returnValues.put(VectorLayer.ATTACH_MIME_TYPE, mMimetype);
    returnValues.put(VectorLayer.ATTACH_DESCRIPTION, mDescription);
    returnValues.put(VectorLayer.ATTACH_SIZE, mSize);

    if (withAttachId) {
        returnValues.put(VectorLayer.ATTACH_ID, mAttachId);
    }

    return returnValues;
}
 
Example #26
Source File: DatabaseContext.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static SQLiteDatabase getDbForLayer(final VectorLayer layer){
    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(false);
    // speedup writing
    db.rawQuery("PRAGMA synchronous=OFF", null);
    //db.rawQuery("PRAGMA locking_mode=EXCLUSIVE", null);
    db.rawQuery("PRAGMA journal_mode=OFF", null);
    db.rawQuery("PRAGMA count_changes=OFF", null);
    db.rawQuery("PRAGMA cache_size=15000", null);

    return db;
}
 
Example #27
Source File: Tabs.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void init(VectorLayer layer, long featureId, GeoGeometry geometry, Map<String, List<String>> table, int row,
                 SharedPreferences sharedPreferences, SharedPreferences preferences,
                 FragmentManager supportFragmentManager, boolean isViewOnly) {
    mLayer = layer;
    mFeatureId = featureId;
    mIsViewOnly = isViewOnly;
    mGeometry = geometry;
    mTable = table;
    mRow = row;
    mSharedPreferences = sharedPreferences;
    mPreferences = preferences;
    mFragmentManager = supportFragmentManager;
    mTag = ViewCompat.generateViewId();
    findViewById(R.id.tab).setId(mTag);
}
 
Example #28
Source File: LayerContentProvider.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ParcelFileDescriptor openFile(
        Uri uri,
        String mode)
        throws FileNotFoundException
{
    Layer layer = getLayerByUri(uri);
    if (null == layer) {
        return null;
    }
    return ((VectorLayer) layer).openFile(uri, mode);
}
 
Example #29
Source File: LayerContentProvider.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Query may be with LIMIT. See http://stackoverflow.com/a/24055457
 * <p/>
 * Example:
 * <pre>{@code
 * Uri uri = Uri.parse(...);
 * uri = uri.buildUpon().appendQueryParameter(URI_PARAMETER_LIMIT, "2").build();
 * context.getContentResolver().query(uri, ...);}</pre>
 */
@Override
public Cursor query(
        Uri uri,
        String[] projection,
        String selection,
        String[] selectionArgs,
        String sortOrder)
{
    Layer layer = getLayerByUri(uri);
    if (null == layer) {
        return null;
    }

    // http://stackoverflow.com/a/24055457
    String limit = uri.getQueryParameter(URI_PARAMETER_LIMIT);

    if (layer instanceof VectorLayer) {
        return ((VectorLayer) layer).query(
                uri, projection, selection, selectionArgs, sortOrder, limit);
    }

    if (layer instanceof TrackLayer) {
        try {
            return ((TrackLayer) layer).query(
                    uri, projection, selection, selectionArgs, sortOrder, limit);
        } catch (SQLException e) {
            return null;
        }
    }

    return null;
}
 
Example #30
Source File: LayerFillService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(IProgressor progressor) {
    try {
        VectorLayer vectorLayer = (VectorLayer) mLayer;
        if (null == vectorLayer)
            return false;
        File meta = new File(mPath.getParentFile(), NGFP_META);

        if (meta.exists()) {
            String jsonText = FileUtil.readFromFile(meta);
            JSONObject metaJson = new JSONObject(jsonText);
            //read fields
            List<Field> fields = NGWUtil.getFieldsFromJson(metaJson.getJSONArray(NGWUtil.NGWKEY_FIELDS));
            //read geometry type
            String geomTypeString = metaJson.getString("geometry_type");
            int geomType = GeoGeometryFactory.typeFromString(geomTypeString);
            vectorLayer.create(geomType, fields);

            if (GeoJSONUtil.isGeoJsonHasFeatures(mPath)) {
                //read SRS -- not need as we will be fill layer with 3857
                JSONObject srs = metaJson.getJSONObject(NGWUtil.NGWKEY_SRS);
                int nSRS = srs.getInt(NGWUtil.NGWKEY_ID);
                vectorLayer.fillFromGeoJson(mPath, nSRS, progressor);
            }
        } else
            vectorLayer.createFromGeoJson(mPath, progressor); // should never get there
    } catch (IOException | JSONException | SQLiteException | NGException | ClassCastException e) {
        e.printStackTrace();
        setError(e, progressor);
        notifyError(mProgressMessage);
        return false;
    }

    if (mDeletePath)
        FileUtil.deleteRecursive(mPath);

    return true;
}