public void loadData(Envelope envelope, int zoom) { long timeStart = System.currentTimeMillis(); // TODO: use fromInternal(Envelope) here MapPos minPos = projection.fromInternal(envelope.getMinX(), envelope.getMinY()); MapPos maxPos = projection.fromInternal(envelope.getMaxX(), envelope.getMaxY()); String sqlBbox = "" + minPos.x + "," + minPos.y + "," + maxPos.x + "," + maxPos.y; // load geometries List<Geometry> newVisibleElementsList = new LinkedList<Geometry>(); try { Uri.Builder uri = Uri.parse("http://kaart.maakaart.ee/poiexport/roads.php?output=gpoly&").buildUpon(); uri.appendQueryParameter("bbox", sqlBbox); uri.appendQueryParameter("max", String.valueOf(maxObjects)); Log.debug("Vector API url:" + uri.build().toString()); JSONObject jsonData = NetUtils.getJSONFromUrl(uri.build().toString()); if (jsonData == null) { Log.debug("No CartoDB data"); return; } JSONArray rows = jsonData.getJSONArray("res"); for (int i = 0; i < rows.length(); i++) { JSONObject row = rows.getJSONObject(i); String the_geom_encoded = row.getString("g"); String name = row.getString("n"); String type = row.getString("t"); Vector<MapPos> mapPos = GeoUtils.decompress(the_geom_encoded, 5, projection); Geometry newObject = new Line(mapPos, new DefaultLabel(name, type), lineStyleSet, null); newObject.attachToLayer(this); newObject.setActiveStyle(zoom); newVisibleElementsList.add(newObject); } } catch (ParseException e) { Log.error("Error parsing data " + e.toString()); } catch (JSONException e) { Log.error("Error parsing JSON data " + e.toString()); } long timeEnd = System.currentTimeMillis(); Log.debug( "OnlineVector loaded N:" + newVisibleElementsList.size() + " time ms:" + (timeEnd - timeStart)); setVisibleElements(newVisibleElementsList); }
public StoredMapConfig readConfig(final FileSystem fs) { try { final String filename = path + "/" + CONFIG_FILENAME; final byte[] data = fs.readFile(filename); final String sdata = new String(data); final String[] lines = Utils.split(sdata, "\n"); for (int i = 0; i < lines.length; i++) { // split into at most 2 tokens final String[] tokens = Tools.split(lines[i].trim(), '=', false, 2); if (tokens.length == 2) { final String name = tokens[0].trim().toLowerCase(); final String value = tokens[1].trim(); // ignore empty values if (value.length() == 0) { continue; } // ignore comments if (name.startsWith("#")) { continue; } if (name.equals("tiles_per_file")) { final int tpf = Integer.parseInt(value); if (tpf > 0 && (tpf & (-tpf)) == tpf) { setTilesPerFile(tpf); } else { throw new IOException("Invalid tiles_per_file"); } } else if (name.equals("hash_size")) { final int hs = Integer.parseInt(value); if (hs >= 1 && hs < 100) { setHashSize(hs); } else { throw new IOException("Invalid hash_size"); } } else if (name.equals("center")) { try { final String[] xyz = Tools.split(value.trim(), ',', false, 4); double lat = Float.parseFloat(xyz[0].trim()); double lon = Float.parseFloat(xyz[1].trim()); int zoom = Integer.parseInt(xyz[2].trim()); Log.debug("center zoom found = " + lat + " " + lon + " " + zoom); setCenterLocation(new WgsPoint(lon, lat), zoom); } catch (final Exception ex) { throw new IOException("invalid center location"); } } } } } catch (final IOException ex) { Log.error("Error reading " + CONFIG_FILENAME); Log.printStackTrace(ex); return null; } return new StoredMapConfig(tilesPerFile, tpfx, tpfy, hashSize); }