Java Code Examples for com.nextgis.maplib.util.GeoConstants

The following examples show how to use com.nextgis.maplib.util.GeoConstants. These examples are extracted from open source projects. 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 Project: android_maplibui   Author: nextgis   File: OverlayItem.java    License: 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 #2
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: 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 #3
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: 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 #4
Source Project: android_maplibui   Author: nextgis   File: CurrentLocationOverlay.java    License: 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 Project: android_maplibui   Author: nextgis   File: TileDownloadService.java    License: 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 #6
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 #7
Source Project: android_maplibui   Author: nextgis   File: LayerUtil.java    License: 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 #8
Source Project: android_maplib   Author: nextgis   File: Layer.java    License: 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 #9
Source Project: android_maplib   Author: nextgis   File: TrackLayer.java    License: 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 #10
Source Project: android_maplib   Author: nextgis   File: NGWVectorLayer.java    License: 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 #11
Source Project: android_maplib   Author: nextgis   File: NGWVectorLayer.java    License: 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 #12
Source Project: android_maplib   Author: nextgis   File: VectorLayer.java    License: 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 #13
Source Project: android_gisapp   Author: nextgis   File: CreateVectorLayerActivity.java    License: 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 Project: android_maplibui   Author: nextgis   File: TextEdit.java    License: 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 #15
Source Project: android_maplibui   Author: nextgis   File: DrawItem.java    License: 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 #16
Source Project: android_maplibui   Author: nextgis   File: OverlayItem.java    License: 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 #17
Source Project: android_maplibui   Author: nextgis   File: OverlayItem.java    License: 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 #18
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: 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);
}
 
Example #19
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean onOptionsItemSelected(int id) {
    if (mLayer == null || mSelectedItem == null)
        return false;

    boolean result = false;
    if (id == R.id.menu_edit_move_point_to_center) {
        result = moveSelectedPoint(mCanvasCenterX, mCanvasCenterY);
    } else if (id == R.id.menu_edit_move_point_to_current_location) {
        result = movePointToLocation();
    } else if (id == R.id.menu_edit_add_new_point) {
        result = addGeometryToMulti(GeoConstants.GTPoint);
    } else if (id == R.id.menu_edit_add_new_line) {
        result = addGeometryToMulti(GeoConstants.GTLineString);
    } else if (id == R.id.menu_edit_add_new_polygon) {
        result = addGeometryToMulti(GeoConstants.GTPolygon);
    } else if (id == R.id.menu_edit_add_new_inner_ring) {
        result = addInnerRing();
    } else if (id == R.id.menu_edit_delete_inner_ring) {
        result = deleteInnerRing();
    } else if (id == R.id.menu_edit_delete_line || id == R.id.menu_edit_delete_polygon) {
        result = deleteGeometry();
    } else if (id == R.id.menu_edit_delete_point) {
        result = deletePoint();
    } else if (id == R.id.menu_edit_by_walk) {
        result = true;
    } else if (id == R.id.menu_edit_by_touch) {
        result = true;
    }

    if (result)
        update();

    return result;
}
 
Example #20
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
protected boolean addGeometryToMulti(int geometryType) {
    //insert geometry in appropriate position
    switch (geometryType) {
        case GeoConstants.GTPoint:
        case GeoConstants.GTLineString:
        case GeoConstants.GTPolygon:
            float[] geoPoints = getNewGeometry(geometryType, mTolerancePX, mMap);
            mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, geoPoints);
            mDrawItems.add(mSelectedItem);
            break;
    }

    return true;
}
 
Example #21
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
protected boolean addInnerRing() {
    mSelectedItem.addVertices(getNewGeometry(GeoConstants.GTLinearRing, mTolerancePX, mMap));
    mSelectedItem.setSelectedRing(mSelectedItem.getRingCount() - 1);
    mSelectedItem.setSelectedPoint(0);

    return true;
}
 
Example #22
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void drawOnPanning(
        Canvas canvas,
        PointF currentMouseOffset) {
    if (mOverlayPoint.isVisible())
        drawOnPanning(canvas, currentMouseOffset, mOverlayPoint);

    List<DrawItem> drawItems = mDrawItems;
    for (DrawItem drawItem : drawItems) {
        boolean isSelected = mSelectedItem == drawItem;

        if (mMode != MODE_CHANGE && mMode != MODE_EDIT_BY_TOUCH) {
            drawItem = drawItem.pan(currentMouseOffset);

            if (isSelected) {
                drawItem.setSelectedRing(mSelectedItem.getSelectedRingId());
                drawItem.setSelectedPoint(mSelectedItem.getSelectedPointId());
            }
        }

        drawItem(drawItem, canvas, isSelected);
        if (mLayer != null) {
            int type = mLayer.getGeometryType();
            if (type == GeoConstants.GTPoint || type == GeoConstants.GTMultiPoint) {
                GeoPoint geometry = (GeoPoint) getBaseGeometry(mMap, GeoConstants.GTPoint, mSelectedItem);
                Location last = mGpsEventSource.getLastKnownLocation();
                updateDistance(last, geometry);
            }
        }
    }

    drawCross(canvas);
}
 
Example #23
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Bundle onSaveState() {
    Bundle bundle = super.onSaveState();
    bundle.putInt(BUNDLE_KEY_TYPE, mType);
    bundle.putInt(BUNDLE_KEY_MODE, mMode);
    bundle.putBoolean(BUNDLE_KEY_HAS_EDITS, mHasEdits);

    if (mOverlayPoint.isVisible())
        bundle.putSerializable(BUNDLE_KEY_OVERLAY_POINT, mOverlayPoint.getCoordinates(GeoConstants.CRS_WGS84));

    return bundle;
}
 
Example #24
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setGeometryFromWalkEdit(GeoGeometry geometry) {
    int selectedGeometry = mDrawItems.indexOf(mSelectedItem);
    int selectedRing = mSelectedItem.getSelectedRingId();

    switch (mLayer.getGeometryType()) {
        case GeoConstants.GTLineString:
            mFeature.setGeometry(geometry);
            break;
        case GeoConstants.GTMultiLineString:
            GeoMultiLineString multiLine = (GeoMultiLineString) mFeature.getGeometry();
            multiLine.set(selectedGeometry, geometry);
            mFeature.setGeometry(multiLine);
            break;
        case GeoConstants.GTPolygon:
            GeoPolygon polygon = (GeoPolygon) mFeature.getGeometry();

            if (selectedRing == 0)
                polygon.setOuterRing((GeoLinearRing) geometry);
            else
                polygon.setInnerRing(selectedRing - 1, (GeoLinearRing) geometry);

            mFeature.setGeometry(polygon);
            break;
        case GeoConstants.GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) mFeature.getGeometry();
            GeoPolygon selectedPolygon = multiPolygon.get(selectedGeometry);
            selectedPolygon.setOuterRing((GeoLinearRing) geometry);

            if (selectedRing == 0)
                selectedPolygon.setOuterRing((GeoLinearRing) geometry);
            else
                selectedPolygon.setInnerRing(selectedRing - 1, (GeoLinearRing) geometry);

            multiPolygon.set(selectedGeometry, selectedPolygon);
            mFeature.setGeometry(multiPolygon);
            break;
    }
}
 
Example #25
Source Project: android_maplibui   Author: nextgis   File: TrackerService.java    License: 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 Project: android_maplibui   Author: nextgis   File: LayerFillService.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
LayerFillTask(Bundle bundle) {
    mUri = bundle.getParcelable(KEY_URI);
    mLayerName = bundle.getString(KEY_NAME);
    mLayerPath = bundle.containsKey(KEY_LAYER_PATH) ?
            (File) bundle.getSerializable(KEY_LAYER_PATH) :
            mLayerGroup.createLayerStorage();
    mMinZoom = bundle.getFloat(KEY_MIN_ZOOM, GeoConstants.DEFAULT_MIN_ZOOM);
    mMaxZoom = bundle.getFloat(KEY_MAX_ZOOM, GeoConstants.DEFAULT_MAX_ZOOM);
    mVisible = bundle.getBoolean(KEY_VISIBLE, true);
}
 
Example #27
Source Project: android_maplib   Author: nextgis   File: GeoGeometryFactory.java    License: 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 #28
Source Project: android_maplib   Author: nextgis   File: Geo.java    License: 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 #29
Source Project: android_maplib   Author: nextgis   File: LocalTMSLayer.java    License: 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 #30
Source Project: android_maplib   Author: nextgis   File: MapDrawable.java    License: 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());
    }
}