@Override protected void initialize(String pId, String aUrl, boolean enableSSL) { mId = pId; super.initialize(pId, aUrl, enableSSL); }
private void initWithTileJSON(JSONObject aTileJSON) { this.setTileJSON((aTileJSON != null) ? aTileJSON : new JSONObject()); if (aTileJSON != null) { if (this.tileJSON.has("tiles")) { try { setURL(this.tileJSON.getJSONArray("tiles").getString(0).replace(".png", "{2x}.png")); } catch (JSONException e) { Log.e(TAG, "Couldn't set tile url", e); } } mMinimumZoomLevel = getJSONFloat(this.tileJSON, "minzoom"); mMaximumZoomLevel = getJSONFloat(this.tileJSON, "maxzoom"); mName = this.tileJSON.optString("name"); mDescription = this.tileJSON.optString("description"); mAttribution = this.tileJSON.optString("attribution"); mLegend = this.tileJSON.optString("legend"); double[] center = getJSONDoubleArray(this.tileJSON, "center", 3); if (center != null) { mCenter = new LatLng(center[0], center[1], center[2]); } double[] bounds = getJSONDoubleArray(this.tileJSON, "bounds", 4); if (bounds != null) { mBoundingBox = new BoundingBox(bounds[3], bounds[2], bounds[1], bounds[0]); } } if (UtilConstants.DEBUGMODE) { Log.d(TAG, "TileJSON " + this.tileJSON.toString()); } }
public TileJsonTileLayer(final String pId, final String url, final boolean enableSSL) { super(pId, url, enableSSL); File cacheDir = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); try { cache = NetworkUtils.getCache(cacheDir, 1024); } catch (Exception e) { Log.e(TAG, "Cache creation failed.", e); } String jsonURL = this.getBrandedJSONURL(); if (jsonURL != null) { fetchBrandedJSONAndInit(jsonURL); } }
@Override public TileLayer setURL(final String aUrl) { if (!TextUtils.isEmpty(aUrl) && !aUrl.toLowerCase(Locale.US).contains("http://") && !aUrl.toLowerCase(Locale.US).contains("https://")) { super.setURL(MAPBOX_BASE_URL_V4 + aUrl + "/{z}/{x}/{y}{2x}.png?access_token=" + MapboxUtils.getAccessToken()); } else { super.setURL(aUrl); } return this; }
protected JSONObject doInBackground(String... urls) { InputStream in = null; try { URL url = new URL(urls[0]); HttpURLConnection connection = NetworkUtils.getHttpURLConnection(url, cache); in = connection.getInputStream(); byte[] response = readFully(in); String result = new String(response, "UTF-8"); return new JSONObject(result); } catch (Exception e) { e.printStackTrace(); return null; } finally { try { if (in != null) { in.close(); } } catch (IOException e) { Log.e(TAG, "Error closing InputStream: " + e.toString()); } } } }