use of net.osmand.map.ITileSource in project OsmAnd-tools by osmandapp.
the class OsmExtractionUI method fillMenuWithActions.
public void fillMenuWithActions(final JMenuBar bar) {
// $NON-NLS-1$
JMenu menu = new JMenu(Messages.getString("OsmExtractionUI.MENU_FILE"));
bar.add(menu);
// $NON-NLS-1$
JMenuItem loadFile = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_SELECT_FILE"));
menu.add(loadFile);
// $NON-NLS-1$
JMenuItem loadSpecifiedAreaFile = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_SELECT_OSM_FILE_AREA"));
menu.add(loadSpecifiedAreaFile);
// $NON-NLS-1$
JMenuItem specifyWorkingDir = new JMenuItem(Messages.getString("OsmExtractionUI.SPECIFY_WORKING_DIR"));
menu.add(specifyWorkingDir);
menu.addSeparator();
// $NON-NLS-1$
JMenuItem exitMenu = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_EXIT"));
menu.add(exitMenu);
// JMenu tileSource = new JMenu(Messages.getString("OsmExtractionUI.MENU_MAPS")); //$NON-NLS-1$MapPanel.getMenuToChooseSource(mapPanel);
// $NON-NLS-1$
final JMenuItem sqliteDB = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_CREATE_SQLITE"));
// tileSource.addSeparator();
// tileSource.add(sqliteDB);
JMenu tileSource = MapPanel.getMenuToChooseSource(mapPanel);
tileSource.addSeparator();
tileSource.add(sqliteDB);
bar.add(tileSource);
// $NON-NLS-1$
menu = new JMenu(Messages.getString("OsmExtractionUI.MENU_WINDOW"));
bar.add(menu);
// $NON-NLS-1$
JMenuItem settings = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_SETTINGS"));
menu.add(settings);
menu.addSeparator();
// $NON-NLS-1$
JMenuItem openLogFile = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_OPEN_LOG"));
menu.add(openLogFile);
// $NON-NLS-1$
menu = new JMenu(Messages.getString("OsmExtractionUI.MENU_ABOUT"));
bar.add(menu);
// $NON-NLS-1$
JMenuItem aboutApplication = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_ABOUT_2"));
menu.add(aboutApplication);
aboutApplication.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame, MapCreatorVersion.APP_MAP_CREATOR_FULL_NAME);
}
});
openLogFile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
File file = new File(OsmExtractionUI.LOG_PATH);
if (file != null && file.exists()) {
if (System.getProperty("os.name").startsWith("Windows")) {
// $NON-NLS-1$ //$NON-NLS-2$
try {
// $NON-NLS-1$
Runtime.getRuntime().exec(new String[] { "notepad.exe", file.getAbsolutePath() });
} catch (IOException es) {
// $NON-NLS-1$
ExceptionHandler.handle(Messages.getString("OsmExtractionUI.UNABLE_OPEN_FILE"), es);
}
} else {
// $NON-NLS-1$
JOptionPane.showMessageDialog(frame, Messages.getString("OsmExtractionUI.OPEN_LOG_FILE_MANUALLY") + LOG_PATH);
}
} else {
// $NON-NLS-1$
ExceptionHandler.handle(Messages.getString("OsmExtractionUI.LOG_FILE_NOT_FOUND"));
}
}
});
sqliteDB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// $NON-NLS-1$
final String regionName = OsmExtractionUI.this.regionName == null ? Messages.getString("OsmExtractionUI.REGION") : OsmExtractionUI.this.regionName;
final ITileSource map = mapPanel.getMap();
if (map != null) {
try {
// $NON-NLS-1$
final ProgressDialog dlg = new ProgressDialog(frame, Messages.getString("OsmExtractionUI.CREATING_INDEX"));
dlg.setRunnable(new Runnable() {
@Override
public void run() {
try {
SQLiteBigPlanetIndex.createSQLiteDatabase(new net.osmand.SQLiteBigPlanetIndex.SQLiteParams(DataExtractionSettings.getSettings().getTilesDirectory(), regionName, map));
} catch (SQLException e1) {
throw new IllegalArgumentException(e1);
} catch (IOException e1) {
throw new IllegalArgumentException(e1);
}
}
});
dlg.run();
} catch (InterruptedException e1) {
// $NON-NLS-1$
log.error("Interrupted", e1);
} catch (InvocationTargetException e1) {
// $NON-NLS-1$
ExceptionHandler.handle("Can't create big planet sqlite index", e1.getCause());
}
}
}
});
exitMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
exit();
}
});
settings.addActionListener(new ActionListener() {
private void applySettings() {
mapPanel.applySettings();
}
@Override
public void actionPerformed(ActionEvent e) {
OsmExtractionPreferencesDialog dlg = new OsmExtractionPreferencesDialog(frame);
dlg.showDialog();
applySettings();
}
});
specifyWorkingDir.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
// $NON-NLS-1$
fc.setDialogTitle(Messages.getString("OsmExtractionUI.CHOOSE_WORKING_DIR"));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
File workingDir = DataExtractionSettings.getSettings().getDefaultWorkingDir();
if (workingDir != null) {
fc.setCurrentDirectory(workingDir);
}
if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null && fc.getSelectedFile().isDirectory()) {
DataExtractionSettings.getSettings().saveDefaultWorkingDir(fc.getSelectedFile());
mapPanel.setTilesLocation(DataExtractionSettings.getSettings().getTilesDirectory());
// $NON-NLS-1$
statusBarLabel.setText(Messages.getString("OsmExtractionUI.WORKING_DIR") + fc.getSelectedFile().getAbsolutePath());
JMenu tileSource = MapPanel.getMenuToChooseSource(mapPanel);
tileSource.add(sqliteDB);
bar.remove(1);
bar.add(tileSource, 1);
}
}
});
loadSpecifiedAreaFile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = getOsmFileChooser();
int answer = fc.showOpenDialog(frame);
if (answer == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null) {
final JDialog dlg = new JDialog(frame, true);
// $NON-NLS-1$
dlg.setTitle(Messages.getString("OsmExtractionUI.SELECT_AREA_TO_FILTER"));
MapPanel panel = new MapPanel(DataExtractionSettings.getSettings().getTilesDirectory());
panel.setLatLon(mapPanel.getLatitude(), mapPanel.getLongitude());
panel.setZoom(mapPanel.getZoom());
final StringBuilder res = new StringBuilder();
panel.getLayer(MapInformationLayer.class).setAreaActionHandler(new // $NON-NLS-1$
AbstractAction(// $NON-NLS-1$
Messages.getString("OsmExtractionUI.SELECT_AREA")) {
private static final long serialVersionUID = -3452957517341961969L;
@Override
public void actionPerformed(ActionEvent e) {
res.append(true);
dlg.setVisible(false);
}
});
dlg.add(panel);
JMenuBar bar = new JMenuBar();
bar.add(MapPanel.getMenuToChooseSource(panel));
dlg.setJMenuBar(bar);
dlg.setSize(512, 512);
double x = frame.getBounds().getCenterX();
double y = frame.getBounds().getCenterY();
dlg.setLocation((int) x - dlg.getWidth() / 2, (int) y - dlg.getHeight() / 2);
dlg.setVisible(true);
if (res.length() > 0 && panel.getSelectionArea().isVisible()) {
MapPanelSelector.MapSelectionArea area = panel.getSelectionArea();
IOsmStorageFilter filter = new OsmBoundsFilter(area.getLat1(), area.getLon1(), area.getLat2(), area.getLon2());
loadCountry(fc.getSelectedFile(), filter);
}
}
}
});
loadFile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = getOsmFileChooser();
int answer = fc.showOpenDialog(frame);
if (answer == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null) {
loadCountry(fc.getSelectedFile(), null);
}
}
});
}
use of net.osmand.map.ITileSource in project Osmand by osmandapp.
the class MapillaryImageDialog method fetchTiles.
public void fetchTiles() {
RotatedTileBox tileBox = getMapActivity().getMapView().getCurrentRotatedTileBox().copy();
if (fetchedTileLat == tileBox.getLatitude() && fetchedTileLon == tileBox.getLongitude()) {
return;
}
ITileSource map = TileSourceManager.getMapillaryVectorSource();
int nzoom = tileBox.getZoom();
if (nzoom < map.getMinimumZoomSupported()) {
return;
}
ResourceManager mgr = getMapActivity().getMyApplication().getResourceManager();
final QuadRect tilesRect = tileBox.getTileBounds();
// recalculate for ellipsoid coordinates
float ellipticTileCorrection = 0;
if (map.isEllipticYTile()) {
ellipticTileCorrection = (float) (MapUtils.getTileEllipsoidNumberY(nzoom, tileBox.getLatitude()) - tileBox.getCenterTileY());
}
int left = (int) Math.floor(tilesRect.left);
int top = (int) Math.floor(tilesRect.top + ellipticTileCorrection);
int width = (int) Math.ceil(tilesRect.right - left);
int height = (int) Math.ceil(tilesRect.bottom + ellipticTileCorrection - top);
int dzoom = nzoom - TILE_ZOOM;
int div = (int) Math.pow(2.0, dzoom);
Map<String, Pair<QuadPointDouble, GeometryTile>> tiles = new HashMap<>();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int tileX = (left + i) / div;
int tileY = (top + j) / div;
String tileId = mgr.calculateTileId(map, tileX, tileY, TILE_ZOOM);
Pair<QuadPointDouble, GeometryTile> p = tiles.get(tileId);
if (p == null) {
GeometryTile tile = null;
// asking tile image async
boolean imgExist = mgr.tileExistOnFileSystem(tileId, map, tileX, tileY, TILE_ZOOM);
if (imgExist) {
if (sync) {
tile = mgr.getGeometryTilesCache().getTileForMapSync(tileId, map, tileX, tileY, TILE_ZOOM, false);
sync = false;
} else {
tile = mgr.getGeometryTilesCache().getTileForMapAsync(tileId, map, tileX, tileY, TILE_ZOOM, false);
}
}
if (tile != null) {
tiles.put(tileId, new Pair<>(new QuadPointDouble(tileX, tileY), tile));
}
}
}
}
fetchedTileLat = tileBox.getLatitude();
fetchedTileLon = tileBox.getLongitude();
this.tiles = new ArrayList<>(tiles.values());
}
use of net.osmand.map.ITileSource in project Osmand by osmandapp.
the class MapillaryVectorLayer method drawTileMap.
@Override
public void drawTileMap(Canvas canvas, RotatedTileBox tileBox) {
ITileSource map = this.map;
if (map == null) {
return;
}
int nzoom = tileBox.getZoom();
if (nzoom < map.getMinimumZoomSupported()) {
return;
}
ResourceManager mgr = resourceManager;
final QuadRect tilesRect = tileBox.getTileBounds();
// recalculate for ellipsoid coordinates
float ellipticTileCorrection = 0;
if (map.isEllipticYTile()) {
ellipticTileCorrection = (float) (MapUtils.getTileEllipsoidNumberY(nzoom, tileBox.getLatitude()) - tileBox.getCenterTileY());
}
int left = (int) Math.floor(tilesRect.left);
int top = (int) Math.floor(tilesRect.top + ellipticTileCorrection);
int width = (int) Math.ceil(tilesRect.right - left);
int height = (int) Math.ceil(tilesRect.bottom + ellipticTileCorrection - top);
int dzoom = nzoom - TILE_ZOOM;
int div = (int) Math.pow(2.0, dzoom);
boolean useInternet = (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null || OsmandPlugin.getEnabledPlugin(MapillaryPlugin.class) != null) && settings.USE_INTERNET_TO_DOWNLOAD_TILES.get() && settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet();
Map<String, GeometryTile> tiles = new HashMap<>();
Map<QuadPointDouble, Map> visiblePoints = new HashMap<>();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int tileX = (left + i) / div;
int tileY = (top + j) / div;
String tileId = mgr.calculateTileId(map, tileX, tileY, TILE_ZOOM);
GeometryTile tile = tiles.get(tileId);
if (tile == null) {
// asking tile image async
boolean imgExist = mgr.tileExistOnFileSystem(tileId, map, tileX, tileY, TILE_ZOOM);
if (imgExist || useInternet) {
tile = mgr.getGeometryTilesCache().getTileForMapAsync(tileId, map, tileX, tileY, TILE_ZOOM, useInternet);
}
if (tile != null) {
tiles.put(tileId, tile);
if (tile.getData() != null) {
drawLines(canvas, tileBox, tileX, tileY, tile);
if (nzoom > 15) {
drawPoints(canvas, tileBox, tileX, tileY, tile, visiblePoints);
}
}
}
}
}
}
this.visiblePoints = visiblePoints;
drawSelectedPoint(canvas, tileBox);
}
use of net.osmand.map.ITileSource in project Osmand by osmandapp.
the class LocalIndexesFragment method openPopUpMenu.
private void openPopUpMenu(View v, final LocalIndexInfo info) {
IconsCache iconsCache = getMyApplication().getIconsCache();
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
final boolean restore = info.isBackupedData();
MenuItem item;
if ((info.getType() == LocalIndexType.MAP_DATA) || (info.getType() == LocalIndexType.DEACTIVATED)) {
item = optionsMenu.getMenu().add(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup).setIcon(iconsCache.getThemedIcon(R.drawable.ic_type_archive));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup, info);
return true;
}
});
}
item = optionsMenu.getMenu().add(R.string.shared_string_rename).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.shared_string_rename, info);
return true;
}
});
if (info.getType() == LocalIndexType.TILES_DATA && (info.getAttachedObject() instanceof ITileSource) && ((ITileSource) info.getAttachedObject()).couldBeDownloadedFromInternet()) {
item = optionsMenu.getMenu().add(R.string.clear_tile_data).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.clear_tile_data, info);
return true;
}
});
}
final IndexItem update = filesToUpdate.get(info.getFileName());
if (update != null) {
item = optionsMenu.getMenu().add(R.string.update_tile).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_import));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
getDownloadActivity().startDownload(update);
return true;
}
});
}
item = optionsMenu.getMenu().add(R.string.shared_string_delete).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.shared_string_delete, info);
return true;
}
});
optionsMenu.show();
}
use of net.osmand.map.ITileSource in project Osmand by osmandapp.
the class MapActivityLayers method updateMapSource.
public void updateMapSource(OsmandMapTileView mapView, CommonPreference<String> settingsToWarnAboutMap) {
OsmandSettings settings = getApplication().getSettings();
// update transparency
int mapTransparency = settings.MAP_UNDERLAY.get() == null ? 255 : settings.MAP_TRANSPARENCY.get();
mapTileLayer.setAlpha(mapTransparency);
mapVectorLayer.setAlpha(mapTransparency);
ITileSource newSource = settings.getMapTileSource(settings.MAP_TILE_SOURCES == settingsToWarnAboutMap);
ITileSource oldMap = mapTileLayer.getMap();
if (newSource != oldMap) {
if (oldMap instanceof SQLiteTileSource) {
((SQLiteTileSource) oldMap).closeDB();
}
mapTileLayer.setMap(newSource);
}
boolean vectorData = !settings.MAP_ONLINE_DATA.get();
mapTileLayer.setVisible(!vectorData);
mapVectorLayer.setVisible(vectorData);
if (vectorData) {
mapView.setMainLayer(mapVectorLayer);
} else {
mapView.setMainLayer(mapTileLayer);
}
}
Aggregations