com.nextgis.maplib.util.NGWUtil Java Examples
The following examples show how to use
com.nextgis.maplib.util.NGWUtil.
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: Connection.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
public boolean connect(boolean guest) { setNgwVersion(); fillCapabilities(); mRootResource = new ResourceGroup(0, this); mRootResource.setParent(this); if (!guest) { try { AtomicReference<String> reference = new AtomicReference<>(mURL); mCookie = NGWUtil.getConnectionCookie(reference, mLogin, mPassword); if (null == mCookie) { return false; } } catch (IOException e) { e.printStackTrace(); return false; } } mIsConnected = true; return true; }
Example #2
Source File: VectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
protected Void doInBackground(Void... params) { try { NGWVectorLayer layer = (NGWVectorLayer) MapDrawable.getInstance().getLayerByPathName(getPath().getName()); FeatureChanges.initialize(layer.getChangeTableName()); List<Long> ids = query(null); for (Long id : ids) { Feature feature = getFeatureWithAttaches(id); layer.addChange(feature.getId(), CHANGE_OPERATION_NEW); Map<String, AttachItem> attaches = feature.getAttachments(); for (AttachItem attach : attaches.values()) layer.addChange(feature.getId(), Long.parseLong(attach.getAttachId()), CHANGE_OPERATION_NEW); } Pair<Integer, Integer> ver = NGWUtil.getNgwVersion(mContext, layer.getAccountName()); layer.sync(mAuthority, ver, new SyncResult()); } catch (Exception ignored) { } return null; }
Example #3
Source File: LayerWithStyles.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
public void fillExtent() { try { mExtent = new GeoEnvelope(); String url = NGWUtil.getExtent(mConnection.getURL(), mRemoteId); HttpResponse response = NetworkUtil.get(url, mConnection.getLogin(), mConnection.getPassword(), false); if (!response.isOk()) return; JSONObject extent = new JSONObject(response.getResponseBody()).getJSONObject(JSON_EXTENT_KEY); double x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MAX_LON_KEY)); double y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MAX_LAT_KEY)); mExtent.setMax(x, y); x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MIN_LON_KEY)); y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MIN_LAT_KEY)); mExtent.setMin(x, y); } catch (IOException | JSONException ignored) { } }
Example #4
Source File: SyncAdapter.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
protected void sync( LayerGroup layerGroup, String authority, SyncResult syncResult) { for (int i = 0; i < layerGroup.getLayerCount(); i++) { if (isCanceled()) { return; } ILayer layer = layerGroup.getLayer(i); if (layer instanceof LayerGroup) { sync((LayerGroup) layer, authority, syncResult); } else if (layer instanceof INGWLayer) { INGWLayer ngwLayer = (INGWLayer) layer; String accountName = ngwLayer.getAccountName(); if (!mVersions.containsKey(accountName)) mVersions.put(accountName, NGWUtil.getNgwVersion(getContext(), accountName)); Pair<Integer, Integer> ver = mVersions.get(accountName); ngwLayer.sync(authority, ver, syncResult); } else if (layer instanceof TrackLayer) { ((TrackLayer) layer).sync(); } } }
Example #5
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
protected HttpResponse sendFeatureAttachOnServer(JSONObject result, long featureId, AttachItem attach) throws JSONException, IOException { // add attachment to row JSONObject postJsonData = new JSONObject(); JSONArray uploadMetaArray = result.getJSONArray("upload_meta"); postJsonData.put("file_upload", uploadMetaArray.get(0)); postJsonData.put("description", attach.getDescription()); String postload = postJsonData.toString(); if (Constants.DEBUG_MODE) { Log.d(Constants.TAG, "postload: " + postload); } // get account data AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); // upload file String url = NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId); // update record in NGW return NetworkUtil.post(url, postload, accountData.login, accountData.password, false); }
Example #6
Source File: NGWLookupTable.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
protected void fillFromNGW(Map<String, String> dataMap, IProgressor progressor) throws IOException, NGException, JSONException { if (!mNet.isNetworkAvailable()) { //return tile from cache throw new NGException(getContext().getString(R.string.error_network_unavailable)); } if(null != progressor){ progressor.setMessage(getContext().getString(R.string.message_loading)); } Log.d(Constants.TAG, "download layer " + getName()); HttpResponse response = NetworkUtil.get(NGWUtil.getResourceUrl(mCacheUrl, mRemoteId), mCacheLogin, mCachePassword, false); if (!response.isOk()) { throw new NGException(NetworkUtil.getError(mContext, response.getResponseCode())); } JSONObject geoJSONObject = new JSONObject(response.getResponseBody()); JSONObject lookupTable = geoJSONObject.getJSONObject("lookup_table"); JSONObject itemsObject = lookupTable.getJSONObject("items"); for (Iterator<String> iter = itemsObject.keys(); iter.hasNext(); ) { String key = iter.next(); String value = itemsObject.getString(key); dataMap.put(key, value); } }
Example #7
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected String getFeaturesUrl(AccountUtil.AccountData accountData) { if (mTracked) return NGWUtil.getTrackedFeaturesUrl(accountData.url, mRemoteId, getPreferences().getLong(SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP, 0)); else return NGWUtil.getFeaturesUrl(accountData.url, mRemoteId, mServerWhere); }
Example #8
Source File: MainActivity.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
void testSync() { IGISApplication application = (IGISApplication) getApplication(); MapBase map = application.getMap(); NGWVectorLayer ngwVectorLayer; for (int i = 0; i < map.getLayerCount(); i++) { ILayer layer = map.getLayer(i); if (layer instanceof NGWVectorLayer) { ngwVectorLayer = (NGWVectorLayer) layer; Pair<Integer, Integer> ver = NGWUtil.getNgwVersion(this, ngwVectorLayer.getAccountName()); ngwVectorLayer.sync(application.getAuthority(), ver, new SyncResult()); } } }
Example #9
Source File: NGWWebMapLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
public String updateURL() { ArrayList<Long> visibleIds = new ArrayList<>(); for (WebMapChild child : mChildren) if (child.isVisible()) visibleIds.add(child.getId()); String server = getURL().replaceAll("/api/component/render/.*", ""); server = NGWUtil.getTMSUrl(server, visibleIds.toArray(new Long[visibleIds.size()])); setURL(server); return server; }
Example #10
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected HttpResponse changeFeatureOnServer(long featureId, String payload) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); // change on server String url = NGWUtil.getFeatureUrl(accountData.url, mRemoteId, featureId); return NetworkUtil.put(url, payload, accountData.login, accountData.password, false); }
Example #11
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected void readFeatures(JsonReader reader, List<Feature> features) throws IOException, IllegalStateException, NumberFormatException, OutOfMemoryError { reader.beginArray(); while (reader.hasNext()) { final Feature feature = NGWUtil.readNGWFeature(reader, getFields(), mCRS); if (feature.getGeometry() == null || !feature.getGeometry().isValid()) continue; features.add(feature); } reader.endArray(); }
Example #12
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected HttpResponse sendAttachOnServer(long featureId, AttachItem attach) throws IOException { // fill attach info String fileName = attach.getDisplayName(); File filePath = new File(mPath, featureId + File.separator + attach.getAttachId()); String fileMime = attach.getMimetype(); // get account data AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); // upload file String url = NGWUtil.getFileUploadUrl(accountData.url); return NetworkUtil.postFile(url, fileName, filePath, fileMime, accountData.login, accountData.password, false); }
Example #13
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 #14
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
public String getRemoteUrl() { try { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); return NGWUtil.getResourceUrl(accountData.url, mRemoteId); } catch (IllegalStateException e) { return null; } }
Example #15
Source File: NGWRasterLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Bitmap getBitmap(TileItem tile) { if (!mExtentReceived) { HttpResponse result = null; try { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, getAccountName()); result = NetworkUtil.get(NGWUtil.getExtent(accountData.url, mRemoteId), getLogin(), getPassword(), false); if (!result.isOk()) { throw new IllegalStateException(""); } JSONObject extent = new JSONObject(result.getResponseBody()).getJSONObject(JSON_EXTENT_KEY); double x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MAX_LON_KEY)); double y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MAX_LAT_KEY)); mExtents.setMax(x, y); x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MIN_LON_KEY)); y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MIN_LAT_KEY)); mExtents.setMin(x, y); mExtentReceived = true; } catch (IOException | JSONException | IllegalStateException ignored) { if (result != null && result.getResponseCode() == 404) mExtentReceived = true; } } if (mExtents.intersects(tile.getEnvelope())) return super.getBitmap(tile); return null; }
Example #16
Source File: Resource.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
public void fillPermissions() { try { String sURL = NGWUtil.getResourceUrl(mConnection.getURL(), mRemoteId) + "/permission"; HttpResponse response = NetworkUtil.get(sURL, mConnection.getLogin(), mConnection.getPassword(), false); if (!response.isOk()) return; mPermissions = new JSONObject(response.getResponseBody()); if (!mPermissions.has(Constants.JSON_RESOURCE_KEY)) mPermissions = null; } catch (IOException | JSONException e) { e.printStackTrace(); } }
Example #17
Source File: WebMap.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
@Override public String getTMSUrl(int styleNo) { ArrayList<Long> visibleIds = new ArrayList<>(); for (WebMapChild child : mChildren) if (child.isVisible()) visibleIds.add(child.getId()); return NGWUtil.getTMSUrl(mConnection.getURL(), visibleIds.toArray(new Long[visibleIds.size()])); }
Example #18
Source File: LayerWithStyles.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
public String getTMSUrl(int styleNo) { Long id = mRemoteId; if (getType() == Connection.NGWResourceTypePostgisLayer || getType() == Connection.NGWResourceTypeWMSClient || getType() == Connection.NGWResourceTypeRasterLayer || getType() == Connection.NGWResourceTypeVectorLayer) id = getStyleId(styleNo); return NGWUtil.getTMSUrl(mConnection.getURL(), new Long[]{id}); }
Example #19
Source File: Connection.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected void setNgwVersion() { Pair<Integer, Integer> ver = null; try { ver = NGWUtil.getNgwVersion(mURL, mLogin, mPassword); } catch (IOException | JSONException | NumberFormatException ignored) { } if (null != ver) { mNgwVersionMajor = ver.first; mNgwVersionMinor = ver.second; } }
Example #20
Source File: HTTPLoader.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
protected String signIn() throws IOException { String url = mUrl.trim(); if (mReference == null) mReference = new AtomicReference<>(url); try { return NGWUtil.getConnectionCookie(mReference, mLogin, mPassword); } catch (IllegalArgumentException | IllegalStateException e) { e.printStackTrace(); return null; } }
Example #21
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected String getResourceMetaUrl(AccountUtil.AccountData accountData) { return NGWUtil.getResourceUrl(accountData.url, mRemoteId); }
Example #22
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected HttpResponse changeAttachOnServer(long featureId, long attachId, String putData) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); String url = NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId) + attachId; return NetworkUtil.put(url, putData, accountData.login, accountData.password, false); }
Example #23
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected HttpResponse deleteAttachOnServer(long featureId, long attachId) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); return NetworkUtil.delete(NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId) + attachId, accountData.login, accountData.password, false); }
Example #24
Source File: LayerWithStyles.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
public String getResourceUrl() { return NGWUtil.getResourceUrl(mConnection.getURL(), mRemoteId); }
Example #25
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected HttpResponse addFeatureOnServer(String payload) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); return NetworkUtil.post(NGWUtil.getFeaturesUrl(accountData.url, mRemoteId), payload, accountData.login, accountData.password, false); }
Example #26
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected HttpResponse deleteFeatureOnServer(long featureId) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); return NetworkUtil.delete(NGWUtil.getFeatureUrl(accountData.url, mRemoteId, featureId), accountData.login, accountData.password, false); }
Example #27
Source File: LayerWithStyles.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
public String getGeoJSONUrl() { return NGWUtil.getGeoJSONUrl(mConnection.getURL(), mRemoteId); }
Example #28
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected String cursorToJson(Cursor cursor) throws JSONException, IOException { JSONObject rootObject = new JSONObject(); if (0 != (mSyncType & Constants.SYNC_ATTRIBUTES)) { JSONObject valueObject = new JSONObject(); for (int i = 0; i < cursor.getColumnCount(); i++) { String name = cursor.getColumnName(i); if (name.equals(Constants.FIELD_ID) || name.equals(Constants.FIELD_GEOM)) { continue; } Field field = mFields.get(cursor.getColumnName(i)); if (null == field) { continue; } switch (field.getType()) { case GeoConstants.FTReal: valueObject.put(name, cursor.getFloat(i)); break; case GeoConstants.FTInteger: valueObject.put(name, cursor.getInt(i)); break; case GeoConstants.FTString: String stringVal = cursor.getString(i); if (null != stringVal && !stringVal.equals("null")) { valueObject.put(name, stringVal); } break; case GeoConstants.FTDateTime: TimeZone timeZoneDT = TimeZone.getDefault(); timeZoneDT.setRawOffset(0); // set to UTC Calendar calendarDT = Calendar.getInstance(timeZoneDT); calendarDT.setTimeInMillis(cursor.getLong(i)); JSONObject jsonDateTime = new JSONObject(); jsonDateTime.put("year", calendarDT.get(Calendar.YEAR)); jsonDateTime.put("month", calendarDT.get(Calendar.MONTH) + 1); jsonDateTime.put("day", calendarDT.get(Calendar.DAY_OF_MONTH)); jsonDateTime.put("hour", calendarDT.get(Calendar.HOUR_OF_DAY)); jsonDateTime.put("minute", calendarDT.get(Calendar.MINUTE)); jsonDateTime.put("second", calendarDT.get(Calendar.SECOND)); valueObject.put(name, jsonDateTime); break; case GeoConstants.FTDate: TimeZone timeZoneD = TimeZone.getDefault(); timeZoneD.setRawOffset(0); // set to UTC Calendar calendarD = Calendar.getInstance(timeZoneD); calendarD.setTimeInMillis(cursor.getLong(i)); JSONObject jsonDate = new JSONObject(); jsonDate.put("year", calendarD.get(Calendar.YEAR)); jsonDate.put("month", calendarD.get(Calendar.MONTH) + 1); jsonDate.put("day", calendarD.get(Calendar.DAY_OF_MONTH)); valueObject.put(name, jsonDate); break; case GeoConstants.FTTime: TimeZone timeZoneT = TimeZone.getDefault(); timeZoneT.setRawOffset(0); // set to UTC Calendar calendarT = Calendar.getInstance(timeZoneT); calendarT.setTimeInMillis(cursor.getLong(i)); JSONObject jsonTime = new JSONObject(); jsonTime.put("hour", calendarT.get(Calendar.HOUR_OF_DAY)); jsonTime.put("minute", calendarT.get(Calendar.MINUTE)); jsonTime.put("second", calendarT.get(Calendar.SECOND)); valueObject.put(name, jsonTime); break; default: break; } } rootObject.put(NGWUtil.NGWKEY_FIELDS, valueObject); } if (0 != (mSyncType & Constants.SYNC_GEOMETRY)) { //may be found geometry in cache by id is faster GeoGeometry geometry = GeoGeometryFactory.fromBlob( cursor.getBlob(cursor.getColumnIndex(Constants.FIELD_GEOM))); geometry.setCRS(GeoConstants.CRS_WEB_MERCATOR); if (mCRS != GeoConstants.CRS_WEB_MERCATOR) geometry.project(mCRS); rootObject.put(NGWUtil.NGWKEY_GEOM, geometry.toWKT(true)); //rootObject.put("id", cursor.getLong(cursor.getColumnIndex(FIELD_ID))); } return rootObject.toString(); }