com.nextgis.maplib.datasource.Field Java Examples
The following examples show how to use
com.nextgis.maplib.datasource.Field.
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: CreateVectorLayerActivity.java From android_gisapp with GNU General Public License v3.0 | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { LayoutInflater inflater = LayoutInflater.from(CreateVectorLayerActivity.this); view = inflater.inflate(R.layout.item_field, parent, false); } final Field field = mFields.get(position); TextView fieldName = (TextView) view.findViewById(R.id.tv_field_name); TextView fieldType = (TextView) view.findViewById(R.id.tv_field_type); fieldName.setText(field.getAlias()); fieldType.setText(LayerUtil.typeToString(CreateVectorLayerActivity.this, field.getType())); view.findViewById(R.id.ib_remove_field).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFields.remove(field); notifyDataSetChanged(); } }); return view; }
Example #2
Source File: NGWUtil.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
public static List<Field> getFieldsFromJson(JSONArray fieldsJSONArray) throws JSONException { List<Field> fields = new LinkedList<>(); for (int i = 0; i < fieldsJSONArray.length(); i++) { JSONObject fieldJSONObject = fieldsJSONArray.getJSONObject(i); String type = fieldJSONObject.getString("datatype"); String alias = fieldJSONObject.getString("display_name"); String name = fieldJSONObject.getString("keyname"); int nType = LayerUtil.stringToType(type); if (Constants.NOT_FOUND != nType) { fields.add(new Field(nType, name, alias)); } } return fields; }
Example #3
Source File: VectorLayerSettingsActivity.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
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: FormBuilderModifyAttributesActivity.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
protected Object putFieldValue(ContentValues values, Field field) { Object value = super.putFieldValue(values, field); IFormControl control = (IFormControl) mFields.get(field.getName()); if (null == control) return null; if (null != value) { if (value instanceof DoubleComboboxValue) { DoubleComboboxValue dcValue = (DoubleComboboxValue) value; values.put(dcValue.mFieldName, dcValue.mValue); values.put(dcValue.mSubFieldName, dcValue.mSubValue); } } return value; }
Example #5
Source File: FormBuilderModifyAttributesActivity.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
protected void addToLayout(IFormControl control, JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, LinearLayout layout) throws JSONException { if (null != control) { appendData(mLayer, mPreferences, mTable, mRow, control, element); control.init(element, fields, savedState, featureCursor, mSharedPreferences, mTranslations); control.addToLayout(layout); if (mIsViewOnly) control.setEnabled(false); String fieldName = control.getFieldName(); if (null != fieldName) mFields.put(fieldName, control); if (control instanceof Tabs) { Tabs tabs = (Tabs) control; mFields.putAll(tabs.getFields()); } } }
Example #6
Source File: CreateVectorLayerActivity.java From android_gisapp with GNU General Public License v3.0 | 6 votes |
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 #7
Source File: Averaging.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences, Map<String, Map<String, String>> translations) throws JSONException { JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mMeasures = attributes.getLong(MEASUREMENT_COUNT); if (null != featureCursor) { // feature exists int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) mValue = featureCursor.getDouble(column); } else if (ControlHelper.hasKey(savedState, mFieldName)) { mValue = savedState.getDouble(ControlHelper.getSavedStateKey(mFieldName)); } else { // new feature mValue = 0.0; } setEnabled(false); setValue(); Button average = findViewById(R.id.average); average.setOnClickListener(this); }
Example #8
Source File: Tabs.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
protected void addToLayout(IFormControl control, JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, LinearLayout layout) throws JSONException { if (null != control) { appendData(mLayer, mPreferences, mTable, mRow, control, element); if (control instanceof PhotoGallery) { if (savedState != null) savedState.putBoolean("<tabs&", true); } control.init(element, fields, savedState, featureCursor, mSharedPreferences, mTranslations); control.addToLayout(layout); if (mIsViewOnly) control.setEnabled(false); String fieldName = control.getFieldName(); if (null != fieldName) mFields.put(fieldName, control); if (control instanceof Tabs) { Tabs tabs = (Tabs) control; mFields.putAll(tabs.getFields()); } } }
Example #9
Source File: Coordinates.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences, Map<String, Map<String, String>> translations) throws JSONException{ JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mHidden = attributes.optBoolean(JSON_HIDDEN_KEY); // TODO crs, format String value; if (ControlHelper.hasKey(savedState, mFieldName)) value = savedState.getString(ControlHelper.getSavedStateKey(mFieldName)); else value = getFormattedValue(); setText(value); setSingleLine(true); setEnabled(false); }
Example #10
Source File: TextLabel.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences, Map<String, Map<String, String>> translations) throws JSONException { JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); setText(ControlHelper.translate(attributes.getString(JSON_TEXT_KEY), translations)); }
Example #11
Source File: VectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
public List<Field> getFields() { if (null == mFields) { return new ArrayList<>(); } return new LinkedList<>(mFields.values()); }
Example #12
Source File: VectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void fromJSON(JSONObject jsonObject) throws JSONException, SQLiteException { super.fromJSON(jsonObject); mGeometryType = jsonObject.getInt(JSON_GEOMETRY_TYPE_KEY); mIsEditable = jsonObject.optBoolean(JSON_EDITABLE_KEY, true); if (jsonObject.has(JSON_FIELDS_KEY)) { mFields = new HashMap<>(); JSONArray fields = jsonObject.getJSONArray(JSON_FIELDS_KEY); for (int i = 0; i < fields.length(); i++) { Field field = new Field(); field.fromJSON(fields.getJSONObject(i)); mFields.put(field.getName(), field); } } if (jsonObject.has(Constants.JSON_BBOX_MAXX_KEY)) { mExtents.setMaxX(jsonObject.getDouble(Constants.JSON_BBOX_MAXX_KEY)); } if (jsonObject.has(Constants.JSON_BBOX_MAXY_KEY)) { mExtents.setMaxY(jsonObject.getDouble(Constants.JSON_BBOX_MAXY_KEY)); } if (jsonObject.has(Constants.JSON_BBOX_MINX_KEY)) { mExtents.setMinX(jsonObject.getDouble(Constants.JSON_BBOX_MINX_KEY)); } if (jsonObject.has(Constants.JSON_BBOX_MINY_KEY)) { mExtents.setMinY(jsonObject.getDouble(Constants.JSON_BBOX_MINY_KEY)); } reloadCache(); if (jsonObject.has(Constants.JSON_RENDERERPROPS_KEY)) { setRenderer(jsonObject.getJSONObject(Constants.JSON_RENDERERPROPS_KEY)); } else { setDefaultRenderer(); } }
Example #13
Source File: VectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
@Override public JSONObject toJSON() throws JSONException { JSONObject rootConfig = super.toJSON(); rootConfig.put(JSON_GEOMETRY_TYPE_KEY, mGeometryType); rootConfig.put(JSON_EDITABLE_KEY, mIsEditable); if (null != mFields) { JSONArray fields = new JSONArray(); for (Field field : mFields.values()) { JSONObject fieldJsonObject = field.toJSON(); fields.put(fieldJsonObject); } rootConfig.put(JSON_FIELDS_KEY, fields); } if (null != mRenderer && mRenderer instanceof IJSONStore) { IJSONStore jsonStore = (IJSONStore) mRenderer; rootConfig.put(Constants.JSON_RENDERERPROPS_KEY, jsonStore.toJSON()); } if (mExtents.isInit()) { rootConfig.put(Constants.JSON_BBOX_MAXX_KEY, mExtents.getMaxX()); rootConfig.put(Constants.JSON_BBOX_MINX_KEY, mExtents.getMinX()); rootConfig.put(Constants.JSON_BBOX_MAXY_KEY, mExtents.getMaxY()); rootConfig.put(Constants.JSON_BBOX_MINY_KEY, mExtents.getMinY()); } if (!mIsCacheRebuilding) { mCache.save(new File(mPath, RTREE)); if (DEBUG_MODE) Log.d(Constants.TAG, "mCache: saving toJSON"); } return rootConfig; }
Example #14
Source File: NGWUtil.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
public static Feature readNGWFeature( JsonReader reader, List<Field> fields, int nSRS) throws IOException, IllegalStateException, NumberFormatException, OutOfMemoryError { final Feature feature = new Feature(Constants.NOT_FOUND, fields); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals(NGWUtil.NGWKEY_ID)) { feature.setId(reader.nextLong()); } else if (name.equals(NGWUtil.NGWKEY_GEOM)) { String wkt = reader.nextString(); GeoGeometry geom = GeoGeometryFactory.fromWKT(wkt, nSRS); geom.setCRS(nSRS); if (nSRS != GeoConstants.CRS_WEB_MERCATOR) { geom.project(GeoConstants.CRS_WEB_MERCATOR); } feature.setGeometry(geom); } else if (name.equals(NGWUtil.NGWKEY_FIELDS)) { readNGWFeatureFields(feature, reader, fields); } else if (name.equals(NGWUtil.NGWKEY_EXTENSIONS)) { if (reader.peek() != JsonToken.NULL) { readNGWFeatureAttachments(feature, reader); } } else { reader.skipValue(); } } reader.endObject(); return feature; }
Example #15
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void create( int geometryType, List<Field> fields) throws SQLiteException { if (mNgwVersionMajor < Constants.NGW_v3 && geometryType < 4 && mNGWLayerType == Connection.NGWResourceTypeVectorLayer) { // to multi geometryType += 3; } super.create(geometryType, fields); FeatureChanges.initialize(getChangeTableName()); }
Example #16
Source File: ControlHelper.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean isEnabled( List<Field> fields, String fieldName) { for (Field field : fields) { if (field.getName().equals(fieldName)) { return true; } } return false; }
Example #17
Source File: Counter.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences, Map<String, Map<String, String>> translations) throws JSONException{ JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mIsShowLast = true; String value = null; if (null != featureCursor) { // feature exists int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) value = featureCursor.getString(column); } else if (ControlHelper.hasKey(savedState, mFieldName)) { mIncremented = savedState.getLong(ControlHelper.getSavedStateKey(mFieldName)); value = getNewValue(attributes); } else { // new feature String last = preferences.getString(mFieldName, null); if (last == null) mIncremented = attributes.getInt(JSON_INIT_VALUE_KEY); else { int inc = attributes.getInt(INCREMENT); mIncremented = Long.valueOf(last) + inc; } value = getNewValue(attributes); } setEnabled(false); setText(value); setSingleLine(true); }
Example #18
Source File: ModifyAttributesActivity.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
protected Object putFieldValue( ContentValues values, Field field) { String fieldName = field.getName(); IControl control = mFields.get(fieldName); if (null == control) { return null; } Object value = control.getValue(); fieldName = "'" + fieldName + "'"; if (null != value) { Log.d(TAG, "field: " + field.getName() + " value: " + value.toString()); if (value instanceof Long) { values.put(fieldName, (Long) value); } else if (value instanceof Integer) { values.put(fieldName, (Integer) value); } else if (value instanceof String) { values.put(fieldName, (String) value); } else if (value instanceof Double) { values.put(fieldName, (Double) value); } else if (value instanceof Float) { values.put(fieldName, (Float) value); } } return value; }
Example #19
Source File: Checkbox.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences, Map<String, Map<String, String>> translations) throws JSONException { JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mIsShowLast = ControlHelper.isSaveLastValue(attributes); Boolean value = null; if (ControlHelper.hasKey(savedState, mFieldName)) value = savedState.getBoolean(ControlHelper.getSavedStateKey(mFieldName)); else if (null != featureCursor) { int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) value = featureCursor.getInt(column) != 0; } else { value = attributes.getBoolean(JSON_INIT_VALUE_KEY); if (mIsShowLast) value = preferences.getBoolean(mFieldName, value); } if (value == null) value = false; setChecked(value); setText(ControlHelper.translate(attributes.getString(JSON_TEXT_KEY), translations)); setEnabled(ControlHelper.isEnabled(fields, mFieldName)); }
Example #20
Source File: FormBuilderModifyAttributesActivity.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected boolean saveFeature() { boolean success = super.saveFeature(); if (success) for (Field field : mLayer.getFields()) saveLastValue(field); return success; }
Example #21
Source File: FormBuilderModifyAttributesActivity.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
protected void fillTabControls( LinearLayout layout, Bundle savedState, JSONArray elements) throws JSONException { Cursor featureCursor = getFeatureCursor(); List<Field> fields = mLayer.getFields(); for (int i = 0; i < elements.length(); i++) { IFormControl control; JSONObject element = elements.getJSONObject(i); String type = element.optString(JSON_TYPE_KEY); if (type.equals(JSON_COORDINATES_VALUE)) { JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); String fieldY = attributes.optString(JSON_FIELD_NAME_KEY + "_lat"); attributes.put(JSON_FIELD_NAME_KEY, fieldY); element.put(JSON_TYPE_KEY, type + "_lat"); control = getControl(this, element, mLayer, mFeatureId, mGeometry, mIsViewOnly); addToLayout(control, element, fields, savedState, featureCursor, layout); attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); String fieldX = attributes.optString(JSON_FIELD_NAME_KEY + "_long"); attributes.put(JSON_FIELD_NAME_KEY, fieldX); element.put(JSON_TYPE_KEY, type + "_lon"); } control = getControl(this, element, mLayer, mFeatureId, mGeometry, mIsViewOnly); if (type.equals(JSON_TABS_KEY)) ((Tabs) control).init(mLayer, mFeatureId, mGeometry, mTable, mRow, mSharedPreferences, mPreferences, getSupportFragmentManager(), mIsViewOnly); addToLayout(control, element, fields, savedState, featureCursor, layout); } if (null != featureCursor) { featureCursor.close(); } layout.requestLayout(); }
Example #22
Source File: LayerFillService.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@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; }
Example #23
Source File: MainApplication.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
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 #24
Source File: TextEdit.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@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 #25
Source File: CreateVectorLayerActivity.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
@Override public void OnFieldChosen(String alias, int type) { if (TextUtils.isEmpty(alias)) Toast.makeText(this, R.string.empty_name, Toast.LENGTH_SHORT).show(); else if (mFieldAdapter.containsField(alias)) Toast.makeText(this, R.string.same_field_name, Toast.LENGTH_LONG).show(); else mFieldAdapter.addField(new Field(type, null, alias)); }
Example #26
Source File: CreateVectorLayerActivity.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
public boolean containsField(String fieldName) { for (Field field : mFields) if (field.getAlias().equalsIgnoreCase(fieldName)) return true; return false; }
Example #27
Source File: Distance.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences, Map<String, Map<String, String>> translations) throws JSONException { JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mHidden = attributes.optBoolean(JSON_HIDDEN_KEY); String value; if (null != featureCursor) { // feature exists int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) mValue = featureCursor.getDouble(column); value = getFormattedValue(); } else if (ControlHelper.hasKey(savedState, mFieldName)) value = savedState.getString(ControlHelper.getSavedStateKey(mFieldName)); else { calculate(false); value = getFormattedValue(); } ((AppCompatEditText) findViewById(R.id.distance)).setText(value); findViewById(R.id.refresh).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { calculate(true); ((AppCompatEditText) findViewById(R.id.distance)).setText(getFormattedValue()); } }); }
Example #28
Source File: NGWUtil.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
public static HttpResponse createNewLayer( Connection connection, VectorLayer layer, long parentId, String keyName) { JSONObject payload = new JSONObject(); try { JSONObject resource = new JSONObject(); resource.put(NGWKEY_CLS, NGWKEY_VECTOR_LAYER); JSONObject id = new JSONObject(); id.put(JSON_ID_KEY, parentId); resource.put(NGWKEY_PARENT, id); resource.put(JSON_DISPLAY_NAME, layer.getName()); if (keyName != null) { resource.put(NGWKEY_KEYNAME, keyName); } payload.put(JSON_RESOURCE_KEY, resource); JSONObject vectorLayer = new JSONObject(); JSONObject srs = new JSONObject(); srs.put(JSON_ID_KEY, GeoConstants.CRS_WEB_MERCATOR); vectorLayer.put(NGWKEY_SRS, srs); vectorLayer.put( NGWKEY_GEOMETRY_TYPE, GeoGeometryFactory.typeToString(layer.getGeometryType())); JSONArray fields = new JSONArray(); for (Field field : layer.getFields()) { JSONObject current = new JSONObject(); current.put(NGWKEY_KEYNAME, field.getName()); current.put(NGWKEY_DISPLAY_NAME, field.getAlias()); current.put(NGWKEY_DATATYPE, LayerUtil.typeToString(field.getType())); fields.put(current); } vectorLayer.put(NGWKEY_FIELDS, fields); payload.put(NGWKEY_VECTOR_LAYER, vectorLayer); } catch (JSONException e) { e.printStackTrace(); return new HttpResponse(500); } return createNewResource(layer.getContext(), connection, payload); }
Example #29
Source File: MainApplication.java From android_gisapp with GNU General Public License v3.0 | 4 votes |
public void initBaseLayers() { if (mMap.getLayerByPathName(LAYER_OSM) == null) { //add OpenStreetMap layer String layerName = getString(R.string.osm); String layerURL = SettingsConstantsUI.OSM_URL; final RemoteTMSLayerUI layer = new RemoteTMSLayerUI(getApplicationContext(), mMap.createLayerStorage(LAYER_OSM)); layer.setName(layerName); layer.setURL(layerURL); layer.setTMSType(TMSTYPE_OSM); layer.setVisible(true); layer.setMinZoom(GeoConstants.DEFAULT_MIN_ZOOM); layer.setMaxZoom(19); mMap.addLayer(layer); mMap.moveLayer(0, layer); new Handler().post(new Runnable() { @Override public void run() { try { layer.fillFromZip(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.mapnik), null); } catch (IOException | NGException | RuntimeException e) { e.printStackTrace(); } } }); } // create empty layers for first experimental editing List<Field> fields = new ArrayList<>(2); fields.add(new Field(GeoConstants.FTInteger, "FID", "FID")); fields.add(new Field(GeoConstants.FTString, "TEXT", "TEXT")); if (mMap.getLayerByPathName(LAYER_A) == null) mMap.addLayer(createEmptyVectorLayer(getString(R.string.points_for_edit), LAYER_A, GeoConstants.GTPoint, fields)); if (mMap.getLayerByPathName(LAYER_B) == null) mMap.addLayer(createEmptyVectorLayer(getString(R.string.lines_for_edit), LAYER_B, GeoConstants.GTLineString, fields)); if (mMap.getLayerByPathName(LAYER_C) == null) mMap.addLayer(createEmptyVectorLayer(getString(R.string.polygons_for_edit), LAYER_C, GeoConstants.GTPolygon, fields)); mMap.save(); }
Example #30
Source File: NGWUtil.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
public static void readNGWFeatureFields(Feature feature, JsonReader reader, List<Field> fields) throws IOException, IllegalStateException, NumberFormatException { reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (reader.peek() == JsonToken.NULL) { reader.skipValue(); } else { boolean bAdded = false; for (Field field : fields) { if (field.getName().equals(name) || field.getName().equals(LayerUtil.normalizeFieldName(name))) { switch (field.getType()) { case GeoConstants.FTReal: feature.setFieldValue(field.getName(), reader.nextDouble()); bAdded = true; break; case GeoConstants.FTInteger: feature.setFieldValue(field.getName(), reader.nextInt()); bAdded = true; break; case GeoConstants.FTString: feature.setFieldValue(field.getName(), reader.nextString()); bAdded = true; break; case GeoConstants.FTDate: case GeoConstants.FTTime: case GeoConstants.FTDateTime: readNGWDate(feature, reader, field.getName()); bAdded = true; break; default: break; } break; } } if (!bAdded) { reader.skipValue(); } } } reader.endObject(); }