org.mapsforge.map.android.graphics.AndroidGraphicFactory Java Examples
The following examples show how to use
org.mapsforge.map.android.graphics.AndroidGraphicFactory.
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: HomeActivity.java From EasyVPN-Free with GNU General Public License v3.0 | 7 votes |
private void initDetailsServerOnMap() { if (markerList != null && markerList.size() > 0) { for (Marker marker : markerList) { layers.remove(marker); } } List<Server> serverList = dbHelper.getServersWithGPS(); markerList = new ArrayList<Marker>(); for (Server server : serverList) { LatLong position = new LatLong(server.getLat(), server.getLon()); Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(ContextCompat.getDrawable(this, getResources().getIdentifier(ConnectionQuality.getSimplePointIcon(server.getQuality()), "drawable", getPackageName()))); Marker serverMarker = new Marker(position, bitmap, 0, 0); markerList.add(serverMarker); layers.add(serverMarker); } }
Example #2
Source File: HomeActivity.java From EasyVPN-Free with GNU General Public License v3.0 | 6 votes |
private void initMap() { AndroidGraphicFactory.createInstance(getApplication()); mapView = new MapView(this); mapView.setClickable(true); mapView.getMapScaleBar().setVisible(false); mapView.setBuiltInZoomControls(false); mapView.setZoomLevelMin((byte) 2); mapView.setZoomLevelMax((byte) 10); mapView.setZoomLevel((byte) 2); mapView.getModel().displayModel.setBackgroundColor(ContextCompat.getColor(this, R.color.mapBackground)); layers = mapView.getLayerManager().getLayers(); MapCreator mapCreator = new MapCreator(this, layers); mapCreator.parseGeoJson("world_map.geo.json"); initServerOnMap(layers); LinearLayout map = (LinearLayout) findViewById(R.id.map); map.addView(mapView); }
Example #3
Source File: MapCreator.java From EasyVPN-Free with GNU General Public License v3.0 | 6 votes |
private void createPolygons(JSONArray coordinates) { Polygon polygon = new Polygon(paintFill, paintStroke, AndroidGraphicFactory.INSTANCE); List<LatLong> polygonList = polygon.getLatLongs(); for (int j = 0; j < coordinates.length(); j++) { try { JSONArray arrLatLong = new JSONArray(coordinates.get(j).toString()); polygonList.add(new LatLong(arrLatLong.getDouble(1), arrLatLong.getDouble(0))); } catch (JSONException e) { e.printStackTrace(); } } layers.add(polygon); }
Example #4
Source File: ForgeMap.java From Androzic with GNU General Public License v3.0 | 6 votes |
public Bitmap getTile(Tile tile) throws OutOfMemoryError { org.mapsforge.core.graphics.Bitmap bitmap = loadTile(tile); Bitmap tileBitmap = null; if (bitmap != null) tileBitmap = AndroidGraphicFactory.getBitmap(bitmap); if (tileBitmap == null) tileBitmap = generateTile(tile); if (tileBitmap != null) { if (dynZoom != 1.0) { int ss = (int) (dynZoom * tileSize); tileBitmap = Bitmap.createScaledBitmap(tileBitmap, ss, ss, true); } } return tileBitmap; }
Example #5
Source File: MapCreator.java From EasyVPN-Free with GNU General Public License v3.0 | 5 votes |
public MapCreator(Context context, Layers layers) { this.context = context; this.layers = layers; paintFill = AndroidGraphicFactory.INSTANCE.createPaint(); paintFill.setColor(ContextCompat.getColor(context,R.color.mapFill)); paintFill.setStyle(Style.FILL); paintStroke = AndroidGraphicFactory.INSTANCE.createPaint(); paintStroke.setStrokeWidth(1); paintStroke.setColor(ContextCompat.getColor(context,R.color.mapStroke)); paintStroke.setStyle(Style.STROKE); }
Example #6
Source File: MapsForgeTileSource.java From osmdroid with Apache License 2.0 | 5 votes |
public synchronized Drawable renderTile(final long pMapTileIndex) { Tile tile = new Tile(MapTileIndex.getX(pMapTileIndex), MapTileIndex.getY(pMapTileIndex), (byte) MapTileIndex.getZoom(pMapTileIndex), 256); model.setFixedTileSize(256); //You could try something like this to load a custom theme //try{ // jobTheme = new ExternalRenderTheme(themeFile); //} //catch(Exception e){ // jobTheme = InternalRenderTheme.OSMARENDER; //} if (mapDatabase==null) return null; try { //Draw the tile RendererJob mapGeneratorJob = new RendererJob(tile, mapDatabase, theme, model, scale, false, false); AndroidTileBitmap bmp = (AndroidTileBitmap) renderer.executeJob(mapGeneratorJob); if (bmp != null) return new BitmapDrawable(AndroidGraphicFactory.getBitmap(bmp)); } catch (Exception ex) { Log.d(IMapView.LOGTAG, "###################### Mapsforge tile generation failed", ex); } return null; }
Example #7
Source File: MapsforgeTileProviderSample.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void onDestroy() { super.onDestroy(); if (alertDialog != null) { alertDialog.hide(); alertDialog.dismiss(); alertDialog = null; } if (fromFiles != null) fromFiles.dispose(); if (forge != null) forge.detach(); AndroidGraphicFactory.clearResourceMemoryCache(); }
Example #8
Source File: MapSectionFragment.java From satstat with GNU General Public License v3.0 | 5 votes |
/** * Applies a style to the map overlays associated with a given location provider. * * This method changes the style (effectively, the color) of the circle and * marker overlays. Its main purpose is to switch the color of the overlays * between gray and the provider color. * * @param context The context of the caller * @param provider The name of the location provider, as returned by * {@link LocationProvider.getName()}. * @param styleName The name of the style to apply. If it is null, the * default style for the provider as returned by * assignLocationProviderStyle() is applied. */ protected void applyLocationProviderStyle(Context context, String provider, String styleName) { String sn = (styleName != null)?styleName:assignLocationProviderStyle(provider); Boolean isStyleChanged = !sn.equals(providerAppliedStyles.get(provider)); Boolean needsRedraw = false; Resources res = context.getResources(); TypedArray style = res.obtainTypedArray(res.getIdentifier(sn, "array", context.getPackageName())); // Circle layer Circle circle = mapCircles.get(provider); if (circle != null) { circle.getPaintFill().setColor(style.getColor(Const.STYLE_FILL, R.color.circle_gray_fill)); circle.getPaintStroke().setColor(style.getColor(Const.STYLE_STROKE, R.color.circle_gray_stroke)); needsRedraw = isStyleChanged && circle.isVisible(); } //Marker layer Marker marker = mapMarkers.get(provider); if (marker != null) { Drawable drawable = style.getDrawable(Const.STYLE_MARKER); Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable); marker.setBitmap(bitmap); needsRedraw = needsRedraw || (isStyleChanged && marker.isVisible()); } if (needsRedraw) { LayerManager manager = mapMap.getLayerManager(); if (manager != null) manager.redrawLayers(); } providerAppliedStyles.put(provider, sn); style.recycle(); }
Example #9
Source File: MapSectionFragment.java From satstat with GNU General Public License v3.0 | 5 votes |
@Override public void onDestroyView() { destroyLayers(true); if (mainActivity.mapSectionFragment == this) mainActivity.mapSectionFragment = null; if (mapMap != null) mapMap.destroyAll(); AndroidGraphicFactory.clearResourceMemoryCache(); super.onDestroyView(); }
Example #10
Source File: ForgeMap.java From Androzic with GNU General Public License v3.0 | 5 votes |
@Override public synchronized void activate(OnMapTileStateChangeListener listener, double mpp, boolean current) throws Throwable { Log.e("FM", "activate(): " + name); synchronized (MAGIC) { mapRedrawer.setListener(listener); if (tileCache == null) { tileCache = new MutableTwoLevelTileCache(); tileCache.setSecondLevelCache(getSecondLevelCache()); } if (databaseRenderer == null) databaseRenderer = new DatabaseRenderer(mapDataStore, AndroidGraphicFactory.INSTANCE, tileCache); if (jobQueue == null) jobQueue = new JobQueue<>(mapViewPosition, displayModel); if (mapWorker == null) { mapWorker = new MapWorker(tileCache, jobQueue, databaseRenderer, new ForgeLayer(mapRedrawer)); mapWorker.start(); } activeCount++; if (Math.abs(1 - mpp / getMPP()) < 0.1) mpp = getMPP(); super.activate(listener, mpp, current); } }
Example #11
Source File: ForgeMap.java From Androzic with GNU General Public License v3.0 | 5 votes |
private static TileCache getSecondLevelCache() { if (fileSystemTileCache != null) return fileSystemTileCache; BaseApplication application = BaseApplication.getApplication(); if (application == null) return null; File cache = application.getCacheDir(); if (cache == null) // cache is not available now return null; File cacheDirectory = new File(cache, "mapsforge"); if (!cacheDirectory.exists() && !cacheDirectory.mkdirs()) return null; int tileCacheFiles = 2000; //estimateSizeOfFileSystemCache(cacheDirectoryName, firstLevelSize, tileSize); if (! cacheDirectory.canWrite() || tileCacheFiles == 0) return null; try { fileSystemTileCache = new FileSystemTileCache(tileCacheFiles, cacheDirectory, AndroidGraphicFactory.INSTANCE, false); return fileSystemTileCache; } catch (IllegalArgumentException e) { e.printStackTrace(); } return null; }
Example #12
Source File: HomeActivity.java From EasyVPN-Free with GNU General Public License v3.0 | 4 votes |
@Override protected void onDestroy() { mapView.destroyAll(); AndroidGraphicFactory.clearResourceMemoryCache(); super.onDestroy(); }
Example #13
Source File: HomeActivity.java From EasyVPN-Free with GNU General Public License v3.0 | 4 votes |
private void initServerOnMap(Layers layers) { Type listType = new TypeToken<ArrayList<Country>>(){}.getType(); countryLatLonList = new Gson().fromJson(LoadData.fromFile(COUNTRY_FILE_NAME, this), listType); for (Server server : countryList) { for (Country country : countryLatLonList) { if (server.getCountryShort().equals(country.getCountryCode())) { LatLong position = new LatLong(country.getCapitalLatitude(), country.getCapitalLongitude()); Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(ContextCompat.getDrawable(this, getResources().getIdentifier(ConnectionQuality.getPointIcon(server.getQuality()), "drawable", getPackageName()))); MyMarker countryMarker = new MyMarker(position, bitmap, 0, 0, server) { @Override public boolean onTap(LatLong geoPoint, Point viewPosition, Point tapPoint) { if (contains(viewPosition, tapPoint)) { onSelectCountry((Server)getRelationObject()); return true; } return false; } }; layers.add(countryMarker); String localeCountryName = localeCountries.get(country.getCountryCode()) != null ? localeCountries.get(country.getCountryCode()) : country.getCountryName(); Drawable drawable = new BitmapDrawable(getResources(), BitmapGenerator.getTextAsBitmap(localeCountryName, 20, ContextCompat.getColor(this,R.color.mapNameCountry))); Bitmap bitmapName = AndroidGraphicFactory.convertToBitmap(drawable); Marker countryNameMarker = new Marker(position, bitmapName, 0, bitmap.getHeight() / 2); layers.add(countryNameMarker); } } } }
Example #14
Source File: MapsForgeTileSource.java From osmdroid with Apache License 2.0 | 4 votes |
public static void createInstance(Application app) { AndroidGraphicFactory.createInstance(app); }
Example #15
Source File: ForgeMap.java From Androzic with GNU General Public License v3.0 | 4 votes |
private static void compileRenderTheme(XmlRenderTheme xmlRenderTheme) { renderTheme = new RenderThemeFuture(AndroidGraphicFactory.INSTANCE, xmlRenderTheme, displayModel); new Thread(renderTheme).run(); }