Search in sources :

Example 1 with ITileSource

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(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()) {
                    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);
            }
        }
    });
}
Also used : SQLException(java.sql.SQLException) ActionEvent(java.awt.event.ActionEvent) OsmBoundsFilter(net.osmand.osm.io.OsmBoundsFilter) MapSelectionArea(net.osmand.swing.MapPanel.MapSelectionArea) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) IOsmStorageFilter(net.osmand.osm.io.IOsmStorageFilter) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ITileSource(net.osmand.map.ITileSource) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) JMenu(javax.swing.JMenu) JDialog(javax.swing.JDialog) JMenuBar(javax.swing.JMenuBar)

Example 2 with ITileSource

use of net.osmand.map.ITileSource in project Osmand by osmandapp.

the class MapActivityActions method createReloadTitleDialog.

private Dialog createReloadTitleDialog(final Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
    builder.setMessage(R.string.context_menu_item_update_map_confirm);
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    final OsmandMapTileView mapView = mapActivity.getMapView();
    builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            int zoom = args.getInt(KEY_ZOOM);
            BaseMapLayer mainLayer = mapView.getMainLayer();
            if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
            if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
            final QuadRect tilesRect = tb.getTileBounds();
            int left = (int) Math.floor(tilesRect.left);
            int top = (int) Math.floor(tilesRect.top);
            int width = (int) (Math.ceil(tilesRect.right) - left);
            int height = (int) (Math.ceil(tilesRect.bottom) - top);
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    ((OsmandApplication) mapActivity.getApplication()).getResourceManager().clearTileForMap(null, mapSource, i + left, j + top, zoom);
                }
            }
            mapView.refreshMap();
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseMapLayer(net.osmand.plus.views.BaseMapLayer) RotatedTileBox(net.osmand.data.RotatedTileBox) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) QuadRect(net.osmand.data.QuadRect) MapTileLayer(net.osmand.plus.views.MapTileLayer) ITileSource(net.osmand.map.ITileSource) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView)

Example 3 with ITileSource

use of net.osmand.map.ITileSource in project Osmand by osmandapp.

the class LocalIndexHelper method updateDescription.

public void updateDescription(LocalIndexInfo info) {
    File f = new File(info.getPathToData());
    if (info.getType() == LocalIndexType.MAP_DATA) {
        Map<String, String> ifns = app.getResourceManager().getIndexFileNames();
        if (ifns.containsKey(info.getFileName())) {
            try {
                Date dt = app.getResourceManager().getDateFormat().parse(ifns.get(info.getFileName()));
                info.setDescription(getInstalledDate(dt.getTime(), null));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        } else {
            info.setDescription(getInstalledDate(f));
        }
    } else if (info.getType() == LocalIndexType.TILES_DATA) {
        ITileSource template;
        if (f.isDirectory() && TileSourceManager.isTileSourceMetaInfoExist(f)) {
            template = TileSourceManager.createTileSourceTemplate(new File(info.getPathToData()));
        } else if (f.isFile() && f.getName().endsWith(SQLiteTileSource.EXT)) {
            template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates());
        } else {
            return;
        }
        String descr = "";
        descr += app.getString(R.string.local_index_tile_data_name, template.getName());
        if (template.getExpirationTimeMinutes() >= 0) {
            descr += "\n" + app.getString(R.string.local_index_tile_data_expire, template.getExpirationTimeMinutes());
        }
        info.setAttachedObject(template);
        info.setDescription(descr);
    } else if (info.getType() == LocalIndexType.SRTM_DATA) {
        info.setDescription(app.getString(R.string.download_srtm_maps));
    } else if (info.getType() == LocalIndexType.WIKI_DATA) {
        info.setDescription(getInstalledDate(f));
    } else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) {
        info.setDescription(getInstalledDate(f));
    } else if (info.getType() == LocalIndexType.DEACTIVATED) {
        info.setDescription(getInstalledDate(f));
    } else if (info.getType() == LocalIndexType.VOICE_DATA) {
        info.setDescription(getInstalledDate(f));
    } else if (info.getType() == LocalIndexType.FONT_DATA) {
        info.setDescription(getInstalledDate(f));
    }
}
Also used : ITileSource(net.osmand.map.ITileSource) ParseException(java.text.ParseException) File(java.io.File) Date(java.util.Date) SQLiteTileSource(net.osmand.plus.SQLiteTileSource)

Example 4 with ITileSource

use of net.osmand.map.ITileSource in project Osmand by osmandapp.

the class DownloadTilesDialog method openDialog.

public void openDialog() {
    BaseMapLayer mainLayer = mapView.getMainLayer();
    if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
        Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
    }
    final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
    if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
        Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
        return;
    }
    final RotatedTileBox rb = mapView.getCurrentRotatedTileBox();
    final int max = mapSource.getMaximumZoomSupported();
    // get narrow zoom
    final int zoom = rb.getZoom();
    // calculate pixel rectangle
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.download_tiles, null);
    // $NON-NLS-1$
    ((TextView) view.findViewById(R.id.MinZoom)).setText(zoom + "");
    // $NON-NLS-1$
    ((TextView) view.findViewById(R.id.MaxZoom)).setText(max + "");
    final SeekBar seekBar = (SeekBar) view.findViewById(R.id.ZoomToDownload);
    seekBar.setMax(max - zoom);
    seekBar.setProgress((max - zoom) / 2);
    final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription));
    final String template = ctx.getString(R.string.tiles_to_download_estimated_size);
    updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, seekBar.getProgress());
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    builder.setPositiveButton(R.string.shared_string_download, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            run(zoom, seekBar.getProgress(), rb.getLatLonBounds(), mapSource);
        }
    });
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.setView(view);
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseMapLayer(net.osmand.plus.views.BaseMapLayer) RotatedTileBox(net.osmand.data.RotatedTileBox) SeekBar(android.widget.SeekBar) DialogInterface(android.content.DialogInterface) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) MapTileLayer(net.osmand.plus.views.MapTileLayer) ITileSource(net.osmand.map.ITileSource) TextView(android.widget.TextView)

Example 5 with ITileSource

use of net.osmand.map.ITileSource in project Osmand by osmandapp.

the class MapillaryPlugin method updateMapLayers.

private void updateMapLayers(OsmandMapTileView mapView, final MapActivityLayers layers, boolean force) {
    if (rasterLayer == null || vectorLayer == null) {
        createLayers();
    }
    if (isActive()) {
        ITileSource rasterSource = null;
        ITileSource vectorSource = null;
        if (settings.SHOW_MAPILLARY.get() || force) {
            rasterSource = settings.getTileSourceByName(TileSourceManager.getMapillaryRasterSource().getName(), false);
            vectorSource = settings.getTileSourceByName(TileSourceManager.getMapillaryVectorSource().getName(), false);
        }
        updateLayer(mapView, rasterSource, rasterLayer, 0.61f);
        updateLayer(mapView, vectorSource, vectorLayer, 0.62f);
    } else {
        mapView.removeLayer(rasterLayer);
        rasterLayer.setMap(null);
        mapView.removeLayer(vectorLayer);
        vectorLayer.setMap(null);
    }
    layers.updateMapSource(mapView, null);
}
Also used : ITileSource(net.osmand.map.ITileSource)

Aggregations

ITileSource (net.osmand.map.ITileSource)14 QuadRect (net.osmand.data.QuadRect)4 RotatedTileBox (net.osmand.data.RotatedTileBox)4 Paint (android.graphics.Paint)3 OsmandSettings (net.osmand.plus.OsmandSettings)3 ResourceManager (net.osmand.plus.resources.ResourceManager)3 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)3 SuppressLint (android.annotation.SuppressLint)2 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 Point (com.vividsolutions.jts.geom.Point)2 File (java.io.File)2 HashMap (java.util.HashMap)2 GeometryTile (net.osmand.data.GeometryTile)2 QuadPointDouble (net.osmand.data.QuadPointDouble)2 SQLiteTileSource (net.osmand.plus.SQLiteTileSource)2 BaseMapLayer (net.osmand.plus.views.BaseMapLayer)2 MapTileLayer (net.osmand.plus.views.MapTileLayer)2 Bitmap (android.graphics.Bitmap)1 Matrix (android.graphics.Matrix)1