com.nextgis.maplib.util.GeoConstants Java Examples

The following examples show how to use com.nextgis.maplib.util.GeoConstants. 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: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void fromJSON(JSONObject jsonObject)
        throws JSONException, SQLiteException
{
    super.fromJSON(jsonObject);

    mTracked = jsonObject.optBoolean(JSON_TRACKED_KEY);
    mCRS = jsonObject.optInt(GeoConstants.GEOJSON_CRS, GeoConstants.CRS_WEB_MERCATOR);
    if (jsonObject.has(JSON_NGW_VERSION_MAJOR_KEY)) {
        mNgwVersionMajor = jsonObject.getInt(JSON_NGW_VERSION_MAJOR_KEY);
    }
    if (jsonObject.has(JSON_NGW_VERSION_MINOR_KEY)) {
        mNgwVersionMinor = jsonObject.getInt(JSON_NGW_VERSION_MINOR_KEY);
    }

    setAccountName(jsonObject.optString(JSON_ACCOUNT_KEY));

    mRemoteId = jsonObject.optLong(Constants.JSON_ID_KEY);
    mSyncType = jsonObject.optInt(JSON_SYNC_TYPE_KEY, Constants.SYNC_NONE);
    mNGWLayerType = jsonObject.optInt(JSON_NGWLAYER_TYPE_KEY, Constants.LAYERTYPE_NGW_VECTOR);
    mServerWhere = jsonObject.optString(JSON_SERVERWHERE_KEY);
    mSyncDirection = jsonObject.optInt(JSON_SYNC_DIRECTION_KEY, DIRECTION_BOTH);
}
 
Example #2
Source File: TileDownloadService.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void addDownloadTask(Intent intent) {
    if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "Add task to download queue");
    }
    String layerPathName = intent.getStringExtra(KEY_PATH);
    double dfMinX = intent.getDoubleExtra(KEY_MINX, 0);
    double dfMinY = intent.getDoubleExtra(KEY_MINY, 0);
    double dfMaxX = intent.getDoubleExtra(KEY_MAXX, GeoConstants.MERCATOR_MAX);
    double dfMaxY = intent.getDoubleExtra(KEY_MAXY, GeoConstants.MERCATOR_MAX);
    GeoEnvelope env = new GeoEnvelope(dfMinX, dfMaxX, dfMinY, dfMaxY);

    if (intent.hasExtra(KEY_ZOOM_FROM) && intent.hasExtra(KEY_ZOOM_TO)) {
        int zoomFrom = intent.getIntExtra(KEY_ZOOM_FROM, 0);
        int zoomTo = intent.getIntExtra(KEY_ZOOM_TO, 18);
        addTask(layerPathName, env, zoomFrom, zoomTo);
    } else if (intent.hasExtra(KEY_ZOOM_LIST)) {
        List<Integer> zoomList = intent.getIntegerArrayListExtra(KEY_ZOOM_LIST);
        addTask(layerPathName, env, zoomList);
    }
}
 
Example #3
Source File: VectorLayerSettingsActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void fillFields() {
    mFieldNames = new ArrayList<>();
    mFieldAliases = new ArrayList<>();
    mFieldNames.add(FIELD_ID);
    mFieldAliases.add(FIELD_ID + " - " + LayerUtil.typeToString(getContext(), GeoConstants.FTInteger));

    int fieldsCount = mVectorLayer.getFields().size();
    String labelField = mVectorLayer.getPreferences().getString(SettingsConstantsUI.KEY_PREF_LAYER_LABEL, Constants.FIELD_ID);

    for (int i = 0; i < fieldsCount; i++) {
        Field field = mVectorLayer.getFields().get(i);
        String fieldInfo = field.getAlias() + " - " + LayerUtil.typeToString(getContext(), field.getType());
        if (field.getName().equals(labelField))
            mDefault = i + 1;

        mFieldNames.add(field.getName());
        mFieldAliases.add(fieldInfo);
    }
}
 
Example #4
Source File: CurrentLocationOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void autopanTo(Location autopanLocation, Location location) {
    GeoPoint oldLocation = new GeoPoint(autopanLocation.getLongitude(), autopanLocation.getLatitude());
    GeoPoint newLocation = new GeoPoint(location.getLongitude(), location.getLatitude());
    oldLocation.setCRS(GeoConstants.CRS_WGS84);
    oldLocation.project(GeoConstants.CRS_WEB_MERCATOR);
    newLocation.setCRS(GeoConstants.CRS_WGS84);
    newLocation.project(GeoConstants.CRS_WEB_MERCATOR);

    double dx = oldLocation.getX() - newLocation.getX();
    double dy = oldLocation.getY() - newLocation.getY();
    GeoPoint newCenter = mMapViewOverlays.getMapCenter();
    newCenter.setX(newCenter.getX() - dx);
    newCenter.setY(newCenter.getY() - dy);

    mMapViewOverlays.panTo(newCenter);
}
 
Example #5
Source File: LayerUtil.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static String getGeometryName(Context context, int geometryType) {
    switch (geometryType) {
        case GeoConstants.GTPoint:
            return context.getString(R.string.point);
        case GeoConstants.GTMultiPoint:
            return context.getString(R.string.multi_point);
        case GeoConstants.GTLineString:
            return context.getString(R.string.linestring);
        case GeoConstants.GTMultiLineString:
            return context.getString(R.string.multi_linestring);
        case GeoConstants.GTPolygon:
            return context.getString(R.string.polygon);
        case GeoConstants.GTMultiPolygon:
            return context.getString(R.string.multi_polygon);
        default:
            return context.getString(R.string.n_a);
    }
}
 
Example #6
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRestoreState(Bundle bundle) {
    if (null != bundle && mType == bundle.getInt(BUNDLE_KEY_TYPE, 0)) {
        mMode = bundle.getInt(BUNDLE_KEY_MODE);
        mHasEdits = bundle.getBoolean(BUNDLE_KEY_HAS_EDITS);

        if (bundle.containsKey(BUNDLE_KEY_OVERLAY_POINT)) {
            GeoPoint point = (GeoPoint) bundle.getSerializable(BUNDLE_KEY_OVERLAY_POINT);

            if (point != null) {
                point.setCRS(GeoConstants.CRS_WGS84);
                mOverlayPoint.setCoordinates(point);
                mOverlayPoint.setVisible(true);
            }
        }
    }

    super.onRestoreState(bundle);
}
 
Example #7
Source File: Layer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void fromJSON(JSONObject jsonObject)
        throws JSONException
{
    super.fromJSON(jsonObject);
    if (jsonObject.has(JSON_MAXLEVEL_KEY)) {
        mMaxZoom = (float) jsonObject.getDouble(JSON_MAXLEVEL_KEY);
    } else {
        mMaxZoom = GeoConstants.DEFAULT_MAX_ZOOM;
    }
    if (jsonObject.has(JSON_MINLEVEL_KEY)) {
        mMinZoom = (float) jsonObject.getDouble(JSON_MINLEVEL_KEY);
    } else {
        mMinZoom = GeoConstants.DEFAULT_MIN_ZOOM;
    }

    mIsVisible = jsonObject.getBoolean(JSON_VISIBILITY_KEY);

    if(Constants.DEBUG_MODE){
        Log.d(Constants.TAG, "Layer " + getName() + " is visible " + mIsVisible);
        Log.d(Constants.TAG, "Layer " + getName() + " zoom limits from " + mMinZoom + " to " + mMaxZoom);
    }
}
 
Example #8
Source File: TrackLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void loadTrack(int trackId)
{
    Cursor track = getTrack(trackId);

    if (track == null || !track.moveToFirst()) {
        return;
    }

    float x0 = track.getFloat(track.getColumnIndex(TrackLayer.FIELD_LON)),
            y0 = track.getFloat(track.getColumnIndex(TrackLayer.FIELD_LAT));

    GeoLineString trackLine = new GeoLineString();
    trackLine.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    trackLine.add(new GeoPoint(x0, y0));

    while (track.moveToNext()) {
        x0 = track.getFloat(track.getColumnIndex(TrackLayer.FIELD_LON));
        y0 = track.getFloat(track.getColumnIndex(TrackLayer.FIELD_LAT));
        trackLine.add(new GeoPoint(x0, y0));
    }

    mTracks.put(trackId, trackLine);
}
 
Example #9
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public JSONObject toJSON()
        throws JSONException
{
    JSONObject rootConfig = super.toJSON();
    rootConfig.put(JSON_NGW_VERSION_MAJOR_KEY, mNgwVersionMajor);
    rootConfig.put(JSON_NGW_VERSION_MINOR_KEY, mNgwVersionMinor);
    rootConfig.put(JSON_ACCOUNT_KEY, mAccountName);
    rootConfig.put(Constants.JSON_ID_KEY, mRemoteId);
    rootConfig.put(JSON_SYNC_TYPE_KEY, mSyncType);
    rootConfig.put(JSON_NGWLAYER_TYPE_KEY, mNGWLayerType);
    rootConfig.put(JSON_SERVERWHERE_KEY, mServerWhere);
    rootConfig.put(JSON_TRACKED_KEY, mTracked);
    rootConfig.put(GeoConstants.GEOJSON_CRS, mCRS);
    rootConfig.put(JSON_SYNC_DIRECTION_KEY, mSyncDirection);

    return rootConfig;
}
 
Example #10
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected boolean movePointToLocation() {
    Activity parent = (Activity) mContext;
    Location location = mGpsEventSource.getLastKnownLocation();

    if (null != location) {
        //change to screen coordinates
        GeoPoint pt = new GeoPoint(location.getLongitude(), location.getLatitude());
        pt.setCRS(GeoConstants.CRS_WGS84);
        pt.project(GeoConstants.CRS_WEB_MERCATOR);
        GeoPoint screenPt = mMap.mapToScreen(pt);
        return moveSelectedPoint((float) screenPt.getX(), (float) screenPt.getY());
    } else
        Toast.makeText(parent, R.string.error_no_location, Toast.LENGTH_SHORT).show();

    return false;
}
 
Example #11
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public GeoGeometry getGeometryForId(
        long rowId,
        int zoom)
{
    if (zoom > GeoConstants.DEFAULT_CACHE_MAX_ZOOM) {
        return getGeometryForId(rowId);
    }

    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    if (null == map) {
        throw new IllegalArgumentException(
                "The map should extends MapContentProviderHelper or inherited");
    }
    SQLiteDatabase db = map.getDatabase(true);
    String[] columns = new String[] {Constants.FIELD_GEOM_ + zoom};
    String selection = Constants.FIELD_ID + " = " + rowId;

    return getGeometryFromQuery(columns, selection, db);
}
 
Example #12
Source File: OverlayItem.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setCoordinates(GeoPoint point)
{
    if (point != null) {
        switch (point.getCRS()) {
            case GeoConstants.CRS_WGS84:
                setCoordinatesFromWGS(point.getX(), point.getY());
                break;
            case GeoConstants.CRS_WEB_MERCATOR:
                mCoordinates.setCoordinates(point.getX(), point.getY());
                break;
        }

        mCoordinates.setCRS(point.getCRS());
    }

    updateScreenCoordinates();
}
 
Example #13
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 #14
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoGeometry getGeometryForId(
        long rowId,
        int zoom,
        SQLiteDatabase db)
{
    if (zoom > GeoConstants.DEFAULT_CACHE_MAX_ZOOM) {
        return getGeometryForId(rowId, db);
    }

    String[] columns = new String[] {Constants.FIELD_GEOM_ + zoom};
    String selection = Constants.FIELD_ID + " = " + rowId;

    return getGeometryFromQuery(columns, selection, db);
}
 
Example #15
Source File: GeoGeometryFactory.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static GeoGeometry fromDataStream(DataInputStream stream) throws IOException {
    int geometryType = stream.readInt();
    GeoGeometry result = null;
    switch (geometryType){
        case GeoConstants.GTPoint:
            result = new GeoPoint();
            result.read(stream);
            break;
        case GeoConstants.GTLineString:
            result = new GeoLineString();
            result.read(stream);
            break;
        case GeoConstants.GTLinearRing:
            result = new GeoLinearRing();
            result.read(stream);
            break;
        case GeoConstants.GTPolygon:
            result = new GeoPolygon();
            result.read(stream);
            break;
        case GeoConstants.GTMultiPoint:
            result = new GeoMultiPoint();
            result.read(stream);
            break;
        case GeoConstants.GTMultiLineString:
            result = new GeoMultiLineString();
            result.read(stream);
            break;
        case GeoConstants.GTMultiPolygon:
            result = new GeoMultiPolygon();
            result.read(stream);
            break;
        case GeoConstants.GTGeometryCollection:
            result = new GeoGeometryCollection();
            result.read(stream);
            break;
    }
    return result;
}
 
Example #16
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected String getRulerText() {
    GeoPoint p1 = new GeoPoint(mScaleRuler.getLeft(), mScaleRuler.getBottom());
    GeoPoint p2 = new GeoPoint(mScaleRuler.getRight(), mScaleRuler.getBottom());
    p1 = mMap.getMap().screenToMap(p1);
    p2 = mMap.getMap().screenToMap(p2);
    p1.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    p2.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    GeoLineString s = new GeoLineString();
    s.add(p1);
    s.add(p2);

    return LocationUtil.formatLength(getContext(), s.getLength(), 1);
}
 
Example #17
Source File: MapDrawable.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void zoomToExtent(GeoEnvelope envelope, float maxZoom) {
    if (envelope.isInit()) {
        double size = GeoConstants.MERCATOR_MAX * 2;
        double scale = Math.min(envelope.width() / size, envelope.height() / size);
        double zoom = MapUtil.lg(1 / scale);
        if (zoom < getMinZoom())
            zoom = getMinZoom();
        if (zoom > maxZoom)
            zoom = maxZoom;

        setZoomAndCenter((float) zoom, envelope.getCenter());
    }
}
 
Example #18
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 #19
Source File: LocalTMSLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public GeoEnvelope getExtents() {
    if(null == mLimits)
        return super.getExtents();
    Integer firstZoom = GeoConstants.DEFAULT_MAX_ZOOM;
    for(Integer key: mLimits.keySet()){
        if(key < firstZoom)
            firstZoom = key;
    }

    TileCacheLevelDescItem item = mLimits.get(firstZoom);

    if(null == item)
        return super.getExtents();

    double mapTileCount = 1 << firstZoom;
    double mapTileSize = GeoConstants.MERCATOR_MAX * 2 / mapTileCount;

    GeoEnvelope env = new GeoEnvelope();
    env.setMinX(item.getMinX() * mapTileSize - GeoConstants.MERCATOR_MAX);
    if(item.getMinX() == item.getMaxX())
        env.setMaxX((item.getMaxX() +1) * mapTileSize - GeoConstants.MERCATOR_MAX);
    else
        env.setMaxX(item.getMaxX() * mapTileSize - GeoConstants.MERCATOR_MAX);

    if(mTMSType == GeoConstants.TMSTYPE_OSM) {
        if(item.getMinY() == item.getMaxY())
            env.setMinY(GeoConstants.MERCATOR_MAX - (item.getMaxY() + 1) * mapTileSize);
        else
            env.setMinY(GeoConstants.MERCATOR_MAX - item.getMaxY() * mapTileSize);
        env.setMaxY(GeoConstants.MERCATOR_MAX - item.getMinY() * mapTileSize);
    } else {
        env.setMinY(item.getMinY() * mapTileSize - GeoConstants.MERCATOR_MAX);
        if(item.getMinY() == item.getMaxY())
            env.setMaxY((item.getMaxY() + 1) * mapTileSize - GeoConstants.MERCATOR_MAX);
        else
            env.setMaxY(item.getMaxY() * mapTileSize - GeoConstants.MERCATOR_MAX);
    }
    return env;
}
 
Example #20
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 #21
Source File: Geo.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean isGeometryTypeSame(
        final int type1,
        final int type2)
{
    return type1 == type2 ||
           (type1 <= GeoConstants.GTMultiPolygon && type2 <= GeoConstants.GTMultiPolygon &&
            Math.abs(type1 - type2) == 3);
}
 
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 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 #24
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 #25
Source File: TrackerService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onLocationChanged(Location location) {
    boolean update = LocationUtil.isProviderEnabled(this, location.getProvider(), true);
    if (!mIsRunning || !update)
        return;

    if (mHasGPSFix && !location.getProvider().equals(LocationManager.GPS_PROVIDER))
        return;

    String fixType = location.hasAltitude() ? "3d" : "2d";

    mValues.clear();
    mValues.put(TrackLayer.FIELD_SESSION, mTrackId);

    mPoint.setCoordinates(location.getLongitude(), location.getLatitude());
    mPoint.setCRS(GeoConstants.CRS_WGS84);
    mPoint.project(GeoConstants.CRS_WEB_MERCATOR);
    mValues.put(TrackLayer.FIELD_LON, mPoint.getX());
    mValues.put(TrackLayer.FIELD_LAT, mPoint.getY());
    mValues.put(TrackLayer.FIELD_ELE, location.getAltitude());
    mValues.put(TrackLayer.FIELD_FIX, fixType);
    mValues.put(TrackLayer.FIELD_SAT, mSatellitesCount);
    mValues.put(TrackLayer.FIELD_SPEED, location.getSpeed());
    mValues.put(TrackLayer.FIELD_ACCURACY, location.getAccuracy());
    mValues.put(TrackLayer.FIELD_SENT, 0);
    mValues.put(TrackLayer.FIELD_TIMESTAMP, location.getTime());
    try {
        getContentResolver().insert(mContentUriTrackPoints, mValues);
    } catch (Exception ignored) {
    }
}
 
Example #26
Source File: TextEdit.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void init(Field field,
                 Bundle savedState,
                 Cursor featureCursor){
    ControlHelper.setClearAction(this);

    mFieldName = field.getName();
    String text = "";

    if (ControlHelper.hasKey(savedState, mFieldName))
        text = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
    else if (null != featureCursor) {
        int column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0)
            text = featureCursor.getString(column);
    }

    setText(text);

    switch (field.getType()) {

        case GeoConstants.FTString:
            break;

        case GeoConstants.FTInteger:
            setSingleLine(true);
            setInputType(InputType.TYPE_CLASS_NUMBER);
            break;

        case GeoConstants.FTReal:
            setSingleLine(true);
            setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            break;
    }
}
 
Example #27
Source File: DrawItem.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static int getMinPointCount(int type) {
    switch (type) {
        case GeoConstants.GTPoint:
        case GeoConstants.GTMultiPoint:
            return 1;
        case GeoConstants.GTLineString:
        case GeoConstants.GTMultiLineString:
            return 2;
        case GeoConstants.GTPolygon:
        case GeoConstants.GTMultiPolygon:
            return 3;
        default:
            return 1;
    }
}
 
Example #28
Source File: OverlayItem.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setCoordinatesFromWGS(
        double longitude,
        double latitude)
{
    mCoordinates.setCoordinates(longitude, latitude);
    mCoordinates.setCRS(GeoConstants.CRS_WGS84);
    mCoordinates.project(GeoConstants.CRS_WEB_MERCATOR);

    updateScreenCoordinates();
}
 
Example #29
Source File: OverlayItem.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoPoint getCoordinates(int CRS)
{
    if (CRS == GeoConstants.CRS_WGS84) {
        GeoPoint wgs = new GeoPoint(mCoordinates.getX(), mCoordinates.getY());
        wgs.setCRS(GeoConstants.CRS_WEB_MERCATOR);
        wgs.project(GeoConstants.CRS_WGS84);
        return wgs;
    }

    return mCoordinates;
}
 
Example #30
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setOverlayPoint(MotionEvent event) {
    GeoPoint mapPoint = mMap.screenToMap(new GeoPoint(event.getX(), event.getY()));
    mapPoint.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    mapPoint.project(GeoConstants.CRS_WGS84);
    mOverlayPoint.setCoordinates(mapPoint);
    mOverlayPoint.setVisible(true);
}