Java Code Examples for com.nextgis.maplib.datasource.Feature#getId()

The following examples show how to use com.nextgis.maplib.datasource.Feature#getId() . 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: 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 2
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public AttachItem getNewTempAttach(Feature feature)
{
    long featureId = feature.getId();
    AttachItem attachItem = new AttachItem("" + NOT_FOUND, "", "", "");
    Uri uri = insertTempAttach(featureId, attachItem);

    if (uri == null) {
        return null;
    }

    String attachId = uri.getLastPathSegment();
    attachItem = getAttach("" + featureId, attachId);
    feature.addAttachment(attachItem);

    return attachItem;
}
 
Example 3
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int updateAttachWithFlags(
        Feature feature,
        AttachItem attachItem)
{
    String layerPathName = mPath.getName();
    long featureIdL = feature.getId();
    long attachIdL = Long.parseLong(attachItem.getAttachId());

    boolean tempFlag = hasAttachTempFlag(featureIdL, attachIdL);
    boolean notSyncFlag = hasAttachNotSyncFlag(featureIdL, attachIdL);

    if (!tempFlag && !notSyncFlag) {
        return 0;
    }

    Uri uri = Uri.parse("content://" + mAuthority + "/" + layerPathName + "/" + featureIdL + "/"
            + Constants.URI_ATTACH + "/" + attachIdL);

    if (tempFlag) {
        uri = uri.buildUpon()
                .appendQueryParameter(URI_PARAMETER_TEMP, Boolean.TRUE.toString())
                .build();
    }

    if (notSyncFlag) {
        uri = uri.buildUpon()
                .appendQueryParameter(URI_PARAMETER_NOT_SYNC, Boolean.TRUE.toString())
                .build();
    }

    return update(uri, attachItem.getContentValues(false), null, null);
}
 
Example 4
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int updateAttach(Feature feature, AttachItem attachItem) {
    String layerPathName = mPath.getName();
    long featureIdL = feature.getId();
    long attachIdL = Long.parseLong(attachItem.getAttachId());
    Uri uri = Uri.parse("content://" + mAuthority + "/" + layerPathName + "/" + featureIdL + "/" + Constants.URI_ATTACH + "/" + attachIdL);
    return update(uri, attachItem.getContentValues(false), null, null);
}
 
Example 5
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int updateFeatureWithAttachesWithFlags(Feature feature)
{
    int res = updateFeatureWithFlags(feature);

    long featureIdL = feature.getId();

    Map<String, AttachItem> attaches = getAttachMap("" + featureIdL);
    if (null != attaches) {
        for (AttachItem attachItem : attaches.values()) {
            res += updateAttachWithFlags(feature, attachItem);
        }
    }

    return res;
}
 
Example 6
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int updateFeatureWithAttaches(Feature feature) {
    int res = updateFeature(feature);
    long featureIdL = feature.getId();

    Map<String, AttachItem> attaches = getAttachMap("" + featureIdL);
    if (null != attaches)
        for (AttachItem attachItem : attaches.values())
            res += updateAttach(feature, attachItem);

    return res;
}
 
Example 7
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
public boolean saveEdits() {
    Feature feature = mEditLayerOverlay.getSelectedFeature();
    long featureId = NOT_FOUND;
    GeoGeometry geometry = null;

    if (mMode == MODE_EDIT_BY_WALK) {
        mEditLayerOverlay.stopGeometryByWalk();
        setMode(MODE_EDIT);
        mUndoRedoOverlay.clearHistory();
        mUndoRedoOverlay.defineUndoRedo();
        return true;
    }

    if (feature != null) {
        geometry = feature.getGeometry();
        featureId = feature.getId();
    }

    if (geometry == null || !geometry.isValid()) {
        Toast.makeText(getContext(), R.string.not_enough_points, Toast.LENGTH_SHORT).show();
        return false;
    }
    if (isGeometryIntersects(getContext(), geometry))
        return false;

    mMap.setLockMap(false);
    mEditLayerOverlay.setHasEdits(false);

    if (mMode == MODE_EDIT_BY_TOUCH) {
        setMode(MODE_EDIT);
        mUndoRedoOverlay.clearHistory();
        mUndoRedoOverlay.defineUndoRedo();
    }

    if (mSelectedLayer != null) {
        if (featureId == NOT_FOUND) {
            //show attributes edit activity
            IVectorLayerUI vectorLayerUI = (IVectorLayerUI) mSelectedLayer;
            vectorLayerUI.showEditForm(mActivity, featureId, geometry);
        } else {
            Uri uri = Uri.parse("content://" + mApp.getAuthority() + "/" + mSelectedLayer.getPath().getName());
            uri = ContentUris.withAppendedId(uri, featureId);
            ContentValues values = new ContentValues();

            try {
                values.put(FIELD_GEOM, geometry.toBlob());
            } catch (IOException e) {
                e.printStackTrace();
            }

            mActivity.getContentResolver().update(uri, values, null, null);
            setMode(MODE_SELECT_ACTION);
        }
    }

    return true;
}