Implement simple UI for offline rendering

This commit is contained in:
Victor Shcherb 2012-05-11 00:35:08 +02:00
parent a6da67223e
commit 894e669a95
13 changed files with 218 additions and 129 deletions

View file

@ -4,6 +4,8 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class RenderingContext { public class RenderingContext {
static enum ShadowRenderingMode { static enum ShadowRenderingMode {
@ -71,11 +73,13 @@ public class RenderingContext {
return val * density; return val * density;
} }
private Map<String, byte[]> precache = new HashMap<String, byte[]>();
protected byte[] getIconRawData(String data) { protected byte[] getIconRawData(String data) {
if(iconsBaseDir != null) { if(iconsBaseDir != null) {
File fs = new File(iconsBaseDir+"/h_"+data+".png"); File fs = new File(iconsBaseDir.getAbsolutePath()+"/h_"+data+".png");
if(!fs.exists()) { if(!fs.exists()) {
fs = new File(iconsBaseDir+"/g_"+data+".png"); fs = new File(iconsBaseDir.getAbsolutePath()+"/g_"+data+".png");
} }
if (fs.exists()) { if (fs.exists()) {
try { try {
@ -84,6 +88,7 @@ public class RenderingContext {
int l = fis.read(dta); int l = fis.read(dta);
fis.close(); fis.close();
if (l == dta.length) { if (l == dta.length) {
precache.put(data, dta);
return dta; return dta;
} else { } else {
System.err.println("Read data " + l + " however was expected " + dta.length + " for " + data); System.err.println("Read data " + l + " however was expected " + dta.length + " for " + data);

View file

@ -42,41 +42,6 @@ public class DataExtractionSettings {
preferences.put("working_dir", path.getAbsolutePath()); preferences.put("working_dir", path.getAbsolutePath());
} }
public File[] getDefaultRoutingFile(){
String routingFile = preferences.get("routing_file", null);
if(routingFile == null){
return null;
}
String[] files = routingFile.split(",");
List<File> fs = new ArrayList<File>();
for(String f : files){
if(new File(f.trim()).exists()){
fs.add(new File(f.trim()));
}
}
return fs.toArray(new File[fs.size()]);
}
public String getDefaultRoutingFilePath(){
File[] file = getDefaultRoutingFile();
String path = "";
if (file != null) {
for (int i = 0; i < file.length; i++) {
if (i > 0) {
path += ", ";
}
path += file[i].getAbsolutePath();
}
}
return path;
}
public void setDefaultRoutingPath(String path){
preferences.put("routing_file", path);
}
public LatLon getDefaultLocation(){ public LatLon getDefaultLocation(){
double lat = preferences.getDouble("default_lat", 53.9); double lat = preferences.getDouble("default_lat", 53.9);
double lon = preferences.getDouble("default_lon", 27.56); double lon = preferences.getDouble("default_lon", 27.56);
@ -172,6 +137,41 @@ public class DataExtractionSettings {
preferences.put("cityAdminLevel", s); preferences.put("cityAdminLevel", s);
} }
public String getNativeLibFile(){
String fl = preferences.get("nativeLibFile", null);
if(fl != null) {
return fl;
}
return getDefaultWorkingDir().getAbsolutePath() +"/osmand.lib";
}
public void setNativeLibFile(String file){
preferences.put("nativeLibFile", file);
}
public String getRenderXmlPath(){
return preferences.get("renderXmlPath", "default.render.xml");
}
public void setRenderXmlPath(String file){
preferences.put("renderXmlPath", file);
}
public String getBinaryFilesDir(){
String fl = preferences.get("binaryFilesDir", null);
if(fl != null) {
return fl;
}
return getDefaultWorkingDir().getAbsolutePath();
}
public void setBinaryFilesDir(String file){
preferences.put("binaryFilesDir", file);
}
public String getOsrmServerAddress(){ public String getOsrmServerAddress(){
return preferences.get("osrmServerAddress", "http://127.0.0.1:5000"); return preferences.get("osrmServerAddress", "http://127.0.0.1:5000");
} }

View file

@ -123,7 +123,8 @@ public class MapClusterLayer implements MapPanelLayer {
private List<Way> clustering(double lat, double lon, Set<String> roads) throws IOException{ private List<Way> clustering(double lat, double lon, Set<String> roads) throws IOException{
List<Way> res = new ArrayList<Way>(); List<Way> res = new ArrayList<Way>();
File[] files = DataExtractionSettings.getSettings().getDefaultRoutingFile(); //TODO DataExtractionSettings.getSettings().getBinaryFilesDir()
File[] files = new File[0];
BinaryMapIndexReader[] rs = new BinaryMapIndexReader[files.length]; BinaryMapIndexReader[] rs = new BinaryMapIndexReader[files.length];
for(int i=0; i<files.length; i++){ for(int i=0; i<files.length; i++){
RandomAccessFile raf = new RandomAccessFile(files[i], "r"); //$NON-NLS-1$ //$NON-NLS-2$ RandomAccessFile raf = new RandomAccessFile(files[i], "r"); //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -364,6 +364,12 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
return getHeight() / 2; return getHeight() / 2;
} }
public NativeSwingRendering getNativeLibrary() {
return nativeLibRendering;
}
public void setNativeLibrary( NativeSwingRendering nl) {
nativeLibRendering = nl;
}
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
@ -910,7 +916,8 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
sright + EXPAND_X * cf, stop - EXPAND_Y * cf, sbottom + EXPAND_Y * cf, z); sright + EXPAND_X * cf, stop - EXPAND_Y * cf, sbottom + EXPAND_Y * cf, z);
nativeLatLon = latLon; nativeLatLon = latLon;
nativeZoom = z; nativeZoom = z;
} catch (IOException e) { } catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace(); e.printStackTrace();
} }
repaint(); repaint();

View file

@ -473,7 +473,8 @@ public class MapRouterLayer implements MapPanelLayer {
public List<Way> selfRoute(LatLon start, LatLon end) { public List<Way> selfRoute(LatLon start, LatLon end) {
List<Way> res = new ArrayList<Way>(); List<Way> res = new ArrayList<Way>();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
File[] files = DataExtractionSettings.getSettings().getDefaultRoutingFile(); // TODO DataExtractionSettings.getSettings().getBinaryFilesDir()
File[] files = new File[0];
if(files == null){ if(files == null){
JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), "Please specify obf file in settings", "Obf file not found", JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), "Please specify obf file in settings", "Obf file not found",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);

View file

@ -30,7 +30,7 @@ public class NativePreferencesDialog extends JDialog {
private JTextField nativeFilesDirectory; private JTextField nativeFilesDirectory;
private JTextField renderingStyleFile; private JTextField renderingStyleFile;
private JTextField nativeLibFile; private boolean okPressed;
public NativePreferencesDialog(Component parent){ public NativePreferencesDialog(Component parent){
@ -89,7 +89,7 @@ public class NativePreferencesDialog extends JDialog {
nativeFilesDirectory = new JTextField(); nativeFilesDirectory = new JTextField();
nativeFilesDirectory.setText(DataExtractionSettings.getSettings().getDefaultWorkingDir().getAbsolutePath()); nativeFilesDirectory.setText(DataExtractionSettings.getSettings().getBinaryFilesDir());
panel.add(nativeFilesDirectory); panel.add(nativeFilesDirectory);
constr = new GridBagConstraints(); constr = new GridBagConstraints();
constr.weightx = 1; constr.weightx = 1;
@ -100,27 +100,6 @@ public class NativePreferencesDialog extends JDialog {
l.setConstraints(nativeFilesDirectory, constr); l.setConstraints(nativeFilesDirectory, constr);
label = new JLabel("City admin level : ");
panel.add(label);
constr = new GridBagConstraints();
constr.ipadx = 5;
constr.gridx = 0;
constr.gridy = 2;
constr.anchor = GridBagConstraints.WEST;
l.setConstraints(label, constr);
nativeLibFile = new JTextField();
nativeLibFile.setText(DataExtractionSettings.getSettings().getCityAdminLevel());
panel.add(nativeLibFile);
constr = new GridBagConstraints();
constr.weightx = 1;
constr.fill = GridBagConstraints.HORIZONTAL;
constr.ipadx = 5;
constr.gridx = 1;
constr.gridy = 2;
l.setConstraints(nativeLibFile, constr);
label = new JLabel("Rendering style file : "); label = new JLabel("Rendering style file : ");
panel.add(label); panel.add(label);
constr = new GridBagConstraints(); constr = new GridBagConstraints();
@ -131,7 +110,7 @@ public class NativePreferencesDialog extends JDialog {
l.setConstraints(label, constr); l.setConstraints(label, constr);
renderingStyleFile = new JTextField(); renderingStyleFile = new JTextField();
renderingStyleFile.setText(DataExtractionSettings.getSettings().getOsrmServerAddress()); renderingStyleFile.setText(DataExtractionSettings.getSettings().getRenderXmlPath());
panel.add(renderingStyleFile); panel.add(renderingStyleFile);
constr = new GridBagConstraints(); constr = new GridBagConstraints();
constr.weightx = 1; constr.weightx = 1;
@ -151,6 +130,7 @@ public class NativePreferencesDialog extends JDialog {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
saveProperties(); saveProperties();
okPressed = true;
setVisible(false); setVisible(false);
} }
@ -166,25 +146,20 @@ public class NativePreferencesDialog extends JDialog {
public void saveProperties(){ public void saveProperties(){
// TODO DataExtractionSettings settings = DataExtractionSettings.getSettings();
// DataExtractionSettings settings = DataExtractionSettings.getSettings(); if(!settings.getBinaryFilesDir().equals(nativeFilesDirectory.getText())){
// if(!settings.getSuffixesToNormalizeStreetsString().equals(streetSuffixes.getText())){ settings.setBinaryFilesDir(nativeFilesDirectory.getText());
// settings.setSuffixesToNormalizeStreets(streetSuffixes.getText()); }
// }
// if(!settings.getDefaultSuffixesToNormalizeStreetsString().equals(streetDefaultSuffixes.getText())){ if(!settings.getRenderXmlPath().equals(renderingStyleFile.getText())){
// settings.setDefaultSuffixesToNormalizeStreets(streetDefaultSuffixes.getText()); settings.setRenderXmlPath(renderingStyleFile.getText());
// } }
// if(settings.useInternetToLoadImages() != useInternet.isSelected()){
// settings.setUseInterentToLoadImages(useInternet.isSelected());
// }
//
// if(!settings.getLineSmoothness().equals(lineSmoothness.getText())){
// settings.setLineSmoothness(lineSmoothness.getText());
// }
} }
public boolean isOkPressed() {
return okPressed;
}
} }

View file

@ -2,6 +2,7 @@ package net.osmand.swing;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Iterator; import java.util.Iterator;
@ -21,14 +22,10 @@ import net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver;
public class NativeSwingRendering extends NativeLibrary { public class NativeSwingRendering extends NativeLibrary {
static {
// System.load("/home/victor/projects/OsmAnd/git/Osmand-kernel/jni-prebuilt/linux-x86/osmand.lib");
}
RenderingRulesStorage storage; RenderingRulesStorage storage;
private final File baseDirRC; private final File baseDirRC;
private RenderingRulesStorage getDefault() throws SAXException, IOException{ public void loadRuleStorage(String path) throws SAXException, IOException{
RenderingRulesStorage storage = new RenderingRulesStorage(); RenderingRulesStorage storage = new RenderingRulesStorage();
final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() { final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() {
@Override @Override
@ -43,14 +40,18 @@ public class NativeSwingRendering extends NativeLibrary {
return depends; return depends;
} }
}; };
storage.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream("default.render.xml"), resolver); if(path == null || path.equals("default.render.xml")) {
return storage; storage.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream("default.render.xml"), resolver);
} else {
storage.parseRulesFromXmlInputStream(new FileInputStream(path), resolver);
}
this.storage = storage;
} }
public NativeSwingRendering(File baseDirRC){ public NativeSwingRendering(File baseDirRC){
this.baseDirRC = baseDirRC; this.baseDirRC = baseDirRC;
try { try {
storage = getDefault(); loadRuleStorage(null);
} catch (SAXException e) { } catch (SAXException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
@ -60,6 +61,7 @@ public class NativeSwingRendering extends NativeLibrary {
public BufferedImage renderImage(int sleft, int sright, int stop, int sbottom, int zoom) throws IOException { public BufferedImage renderImage(int sleft, int sright, int stop, int sbottom, int zoom) throws IOException {
long time = -System.currentTimeMillis(); long time = -System.currentTimeMillis();
RenderingContext rctx = new RenderingContext(baseDirRC); RenderingContext rctx = new RenderingContext(baseDirRC);
@ -111,26 +113,19 @@ public class NativeSwingRendering extends NativeLibrary {
} }
} }
private static NativeSwingRendering loaded = null;
public static NativeSwingRendering loadLibrary(String path){
if(loaded == null) {
System.load(path);
// TODO images !!!
loaded = new NativeSwingRendering(new File("/home/victor/projects/OsmAnd/git/OsmAnd/res/drawable-mdpi/"));
}
return loaded;
}
public static void main(String[] args) throws SAXException, IOException { public static void main(String[] args) throws SAXException, IOException {
System.load("/home/victor/projects/OsmAnd/git/Osmand-kernel/jni-prebuilt/linux-x86/osmand.lib"); NativeSwingRendering lib = loadLibrary("/home/victor/projects/OsmAnd/git/Osmand-kernel/jni-prebuilt/linux-x86/osmand.lib");
NativeSwingRendering lib = new NativeSwingRendering(
new File("/home/victor/projects/OsmAnd/git/OsmAnd/res/drawable-mdpi/"));
lib.initFilesInDir(new File("/home/victor/projects/OsmAnd/data/version2")); lib.initFilesInDir(new File("/home/victor/projects/OsmAnd/data/version2"));
double latTop = 22.5;
double lonLeft = -80;
int zoom = 11;
float tileX = 2;
float tileY = 2;
double latBottom = MapUtils.getLatitudeFromTile(zoom, MapUtils.getTileNumberY(zoom, latTop) + tileY);
double lonRight = MapUtils.getLongitudeFromTile(zoom, MapUtils.getTileNumberX(zoom, lonLeft) + tileX);
int sleft = MapUtils.get31TileNumberX(lonLeft);
int sright = MapUtils.get31TileNumberX(lonRight);
int stop = MapUtils.get31TileNumberY(latTop);
int sbottom = MapUtils.get31TileNumberY(latBottom);
lib.renderImage(sleft, sright, stop, sbottom, zoom);
MapPanel.showMainWindow(512, 512, lib); MapPanel.showMainWindow(512, 512, lib);
} }
} }

View file

@ -35,7 +35,9 @@ public class OsmExtractionPreferencesDialog extends JDialog {
private JTextField cityAdminLevel; private JTextField cityAdminLevel;
private JTextField osrmServerAddress; private JTextField osrmServerAddress;
private JTextField renderingTypesFile; private JTextField renderingTypesFile;
private JTextField pathToObfRoutingFile; private JTextField nativeLibFile;
private JTextField nativeFilesDirectory;
private JTextField renderingStyleFile;
private JCheckBox useInternet; private JCheckBox useInternet;
@ -51,7 +53,7 @@ public class OsmExtractionPreferencesDialog extends JDialog {
} }
public void showDialog(){ public void showDialog(){
setSize(700, 380); setSize(700, 500);
double x = getParent().getBounds().getCenterX(); double x = getParent().getBounds().getCenterX();
double y = getParent().getBounds().getCenterY(); double y = getParent().getBounds().getCenterY();
setLocation((int) x - getWidth() / 2, (int) y - getHeight() / 2); setLocation((int) x - getWidth() / 2, (int) y - getHeight() / 2);
@ -102,7 +104,7 @@ public class OsmExtractionPreferencesDialog extends JDialog {
constr.anchor = GridBagConstraints.WEST; constr.anchor = GridBagConstraints.WEST;
l.setConstraints(useInternet, constr); l.setConstraints(useInternet, constr);
JLabel label = new JLabel("Path to obf files (test routing, comma separated) : "); JLabel label = new JLabel("Directory with obf binary files (routing, rendering): ");
panel.add(label); panel.add(label);
constr = new GridBagConstraints(); constr = new GridBagConstraints();
constr.ipadx = 5; constr.ipadx = 5;
@ -111,17 +113,17 @@ public class OsmExtractionPreferencesDialog extends JDialog {
constr.anchor = GridBagConstraints.WEST; constr.anchor = GridBagConstraints.WEST;
l.setConstraints(label, constr); l.setConstraints(label, constr);
pathToObfRoutingFile = new JTextField(); nativeFilesDirectory = new JTextField();
pathToObfRoutingFile.setText(DataExtractionSettings.getSettings().getDefaultRoutingFilePath()); nativeFilesDirectory.setText(DataExtractionSettings.getSettings().getBinaryFilesDir());
panel.add(pathToObfRoutingFile); panel.add(nativeFilesDirectory);
constr = new GridBagConstraints(); constr = new GridBagConstraints();
constr.weightx = 1; constr.weightx = 1;
constr.fill = GridBagConstraints.HORIZONTAL; constr.fill = GridBagConstraints.HORIZONTAL;
constr.ipadx = 5; constr.ipadx = 5;
constr.gridx = 1; constr.gridx = 1;
constr.gridy = 1; constr.gridy = 1;
l.setConstraints(pathToObfRoutingFile, constr); l.setConstraints(nativeFilesDirectory, constr);
label = new JLabel("City admin level : "); label = new JLabel("City admin level : ");
@ -166,6 +168,46 @@ public class OsmExtractionPreferencesDialog extends JDialog {
constr.gridy = 3; constr.gridy = 3;
l.setConstraints(osrmServerAddress, constr); l.setConstraints(osrmServerAddress, constr);
label = new JLabel("Rendering style file : ");
panel.add(label);
constr = new GridBagConstraints();
constr.ipadx = 5;
constr.gridx = 0;
constr.gridy = 4;
constr.anchor = GridBagConstraints.WEST;
l.setConstraints(label, constr);
renderingStyleFile = new JTextField();
renderingStyleFile.setText(DataExtractionSettings.getSettings().getRenderXmlPath());
panel.add(renderingStyleFile);
constr = new GridBagConstraints();
constr.weightx = 1;
constr.fill = GridBagConstraints.HORIZONTAL;
constr.ipadx = 5;
constr.gridx = 1;
constr.gridy = 4;
l.setConstraints(renderingStyleFile, constr);
label = new JLabel("Native lib file (osmand.lib): ");
panel.add(label);
constr = new GridBagConstraints();
constr.ipadx = 5;
constr.gridx = 0;
constr.gridy = 5;
constr.anchor = GridBagConstraints.WEST;
l.setConstraints(label, constr);
nativeLibFile = new JTextField();
nativeLibFile.setText(DataExtractionSettings.getSettings().getNativeLibFile());
panel.add(nativeLibFile);
constr = new GridBagConstraints();
constr.weightx = 1;
constr.fill = GridBagConstraints.HORIZONTAL;
constr.ipadx = 5;
constr.gridx = 1;
constr.gridy = 5;
l.setConstraints(nativeLibFile, constr);
// supressWarning = new JCheckBox(); // supressWarning = new JCheckBox();
// supressWarning.setText(Messages.getString("OsmExtractionPreferencesDialog.DUPLICATED.ID")); //$NON-NLS-1$ // supressWarning.setText(Messages.getString("OsmExtractionPreferencesDialog.DUPLICATED.ID")); //$NON-NLS-1$
// supressWarning.setSelected(DataExtractionSettings.getSettings().isSupressWarningsForDuplicatedId()); // supressWarning.setSelected(DataExtractionSettings.getSettings().isSupressWarningsForDuplicatedId());
@ -320,6 +362,9 @@ public class OsmExtractionPreferencesDialog extends JDialog {
if(settings.useInternetToLoadImages() != useInternet.isSelected()){ if(settings.useInternetToLoadImages() != useInternet.isSelected()){
settings.setUseInterentToLoadImages(useInternet.isSelected()); settings.setUseInterentToLoadImages(useInternet.isSelected());
} }
if(!settings.getNativeLibFile().equals(nativeLibFile.getText())){
settings.setNativeLibFile(nativeLibFile.getText());
}
if(!settings.getLineSmoothness().equals(lineSmoothness.getText())){ if(!settings.getLineSmoothness().equals(lineSmoothness.getText())){
settings.setLineSmoothness(lineSmoothness.getText()); settings.setLineSmoothness(lineSmoothness.getText());
@ -330,15 +375,19 @@ public class OsmExtractionPreferencesDialog extends JDialog {
if(!settings.getMapRenderingTypesFile().equals(renderingTypesFile.getText())){ if(!settings.getMapRenderingTypesFile().equals(renderingTypesFile.getText())){
settings.setMapRenderingTypesFile(renderingTypesFile.getText()); settings.setMapRenderingTypesFile(renderingTypesFile.getText());
} }
if(!settings.getDefaultRoutingFilePath().equals(pathToObfRoutingFile.getText())){
settings.setDefaultRoutingPath(pathToObfRoutingFile.getText());
}
if(!settings.getCityAdminLevel().equals(cityAdminLevel.getText())){ if(!settings.getCityAdminLevel().equals(cityAdminLevel.getText())){
settings.setCityAdminLevel(cityAdminLevel.getText()); settings.setCityAdminLevel(cityAdminLevel.getText());
} }
if(!settings.getOsrmServerAddress().equals(osrmServerAddress.getText())){ if(!settings.getOsrmServerAddress().equals(osrmServerAddress.getText())){
settings.setOsrmServerAddress(osrmServerAddress.getText()); settings.setOsrmServerAddress(osrmServerAddress.getText());
} }
if(!settings.getBinaryFilesDir().equals(nativeFilesDirectory.getText())){
settings.setBinaryFilesDir(nativeFilesDirectory.getText());
}
if(!settings.getRenderXmlPath().equals(renderingStyleFile.getText())){
settings.setRenderXmlPath(renderingStyleFile.getText());
}
// if(settings.isSupressWarningsForDuplicatedId() != supressWarning.isSelected()){ // if(settings.isSupressWarningsForDuplicatedId() != supressWarning.isSelected()){
// settings.setSupressWarningsForDuplicatedId (supressWarning.isSelected()); // settings.setSupressWarningsForDuplicatedId (supressWarning.isSelected());
// } // }

View file

@ -218,11 +218,38 @@ public class OsmExtractionUI implements IMapLocationListener {
showOfflineIndex.addActionListener(new ActionListener() { showOfflineIndex.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
NativePreferencesDialog dlg = new NativePreferencesDialog(frame); if(showOfflineIndex.isSelected()) {
dlg.showDialog(); NativePreferencesDialog dlg = new NativePreferencesDialog(frame);
dlg.showDialog();
if(dlg.isOkPressed()) {
initNativeRendering();
} else {
showOfflineIndex.setSelected(false);
}
} else {
mapPanel.setNativeLibrary(null);
}
} }
}); });
}
private void initNativeRendering() {
NativeSwingRendering lib = NativeSwingRendering.loadLibrary(
DataExtractionSettings.getSettings().getNativeLibFile());
if(lib != null) {
try {
lib.initFilesInDir(new File(DataExtractionSettings.getSettings().getBinaryFilesDir()));
lib.loadRuleStorage(DataExtractionSettings.getSettings().getRenderXmlPath());
mapPanel.setNativeLibrary(lib);
mapPanel.repaint();
} catch (SAXException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
} }
public void fillMenuWithActions(final JMenuBar bar){ public void fillMenuWithActions(final JMenuBar bar){

View file

@ -5,6 +5,7 @@ OSMAND_SKIA_ABS := $(LOCAL_PATH)/../skia/skia_library
LOCAL_C_INCLUDES := $(LOCAL_PATH)/src \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/src \
$(PROTOBUF) \ $(PROTOBUF) \
$(LOCAL_PATH)/../skia \ $(LOCAL_PATH)/../skia \
$(LOCAL_PATH)/../expat/expat_library/lib \
$(OSMAND_SKIA_ABS)/include/core \ $(OSMAND_SKIA_ABS)/include/core \
$(OSMAND_SKIA_ABS)/include/images \ $(OSMAND_SKIA_ABS)/include/images \
$(OSMAND_SKIA_ABS)/include/utils \ $(OSMAND_SKIA_ABS)/include/utils \

View file

@ -6,10 +6,12 @@ include ./Common.mk
LOCAL_SRC_FILES += src/osmand_main.cpp LOCAL_SRC_FILES += src/osmand_main.cpp
LDFLAGS = -Wl,--hash-style=both -shared #LDFLAGS = -Wl,--hash-style=both -fPIC
LDFLAGS = -Wall -fPIC -Wl,-Bsymbolic
LDRUNFLAGS = -Wl,--hash-style=both LDRUNFLAGS = -Wl,--hash-style=both
# --trace -Bsymbolic -Bsymbolic-functions
LDLIBS = -L$(PREBUILT_DIR) -lskia -lproto -lpthread -lrt -lft2 -lexpat -lpng -lz LDLIBS = -L$(PREBUILT_DIR) -lskia -lproto -lpthread -lrt -lft2 -lexpat -lz -lpng
CPP_FILE_EXTENSION = cpp CPP_FILE_EXTENSION = cpp
OBJECTS = $(LOCAL_SRC_FILES:src/%.$(CPP_FILE_EXTENSION)=build/obj/%.o) OBJECTS = $(LOCAL_SRC_FILES:src/%.$(CPP_FILE_EXTENSION)=build/obj/%.o)
@ -29,7 +31,7 @@ target : $(PREBUILT_DIR)/$(LIBNAME)
#target : $(PREBUILT_DIR)/$(LIBNAME) ../$(RUNFILE) #target : $(PREBUILT_DIR)/$(LIBNAME) ../$(RUNFILE)
../$(RUNFILE) : $(OBJECTS) $(PREBUILT_DIR)/libskia.a $(PREBUILT_DIR)/libproto.a ../$(RUNFILE) : $(OBJECTS) $(PREBUILT_DIR)/libskia.a $(PREBUILT_DIR)/libproto.a Makefile
$(CXX) $(LDRUNFLAGS) -o ../$(RUNFILE) $(OBJECTS) $(LDLIBS) $(CXX) $(LDRUNFLAGS) -o ../$(RUNFILE) $(OBJECTS) $(LDLIBS)
@chmod +x ../$(RUNFILE) @chmod +x ../$(RUNFILE)
@ -37,9 +39,8 @@ $(PREBUILT_DIR)/$(LIBNAME) : build/$(LIBNAME)
cp build/$(LIBNAME) $(PREBUILT_DIR)/$(LIBNAME) cp build/$(LIBNAME) $(PREBUILT_DIR)/$(LIBNAME)
build/$(LIBNAME): $(OBJECTS) $(PREBUILT_DIR)/libskia.a $(PREBUILT_DIR)/libproto.a build/$(LIBNAME): $(OBJECTS) $(PREBUILT_DIR)/libskia.a $(PREBUILT_DIR)/libproto.a Makefile
$(CXX) $(LDFLAGS) -o build/$(LIBNAME) $(OBJECTS) $(LDLIBS) $(CXX) -shared -o build/$(LIBNAME) $(OBJECTS) $(LDFLAGS) $(LDLIBS)
strip build/$(LIBNAME)
build/obj/%.o : src/%.$(CPP_FILE_EXTENSION) $(LOCAL_C_INCLUDES) build/obj/%.o : src/%.$(CPP_FILE_EXTENSION) $(LOCAL_C_INCLUDES)
@mkdir -p `dirname $@` @mkdir -p `dirname $@`

View file

@ -17,6 +17,24 @@
JavaVM* globalJVM = NULL; JavaVM* globalJVM = NULL;
void loadJniRenderingContext(JNIEnv* env); void loadJniRenderingContext(JNIEnv* env);
void loadJniRenderingRules(JNIEnv* env); void loadJniRenderingRules(JNIEnv* env);
static int simplePngSize = 93;
static void* simplePng = new uint8[simplePngSize]{
0x89 ,0x50 ,0x4E ,0x47 ,0x0D ,0x0A ,0x1A ,0x0A ,
0x00 ,0x00 ,0x00 ,0x0D ,0x49 ,0x48 ,0x44 ,0x52 ,
0x00 ,0x00 ,0x00 ,0x06 ,0x00 ,0x00 ,0x00 ,0x06 ,
0x08 ,0x03 ,0x00 ,0x00 ,0x00 ,0xD7 ,0x12 ,0x1F ,
0x7A ,0x00 ,0x00 ,0x00 ,0x03 ,0x50 ,0x4C ,0x54 ,
0x45 ,0x20 ,0x97 ,0xCE ,0xDD ,0xEB ,0x88 ,0x50 ,
0x00 ,0x00 ,0x00 ,0x15 ,0x49 ,0x44 ,0x41 ,0x54 ,
0x78 ,0xDA ,0x8D ,0xC1 ,0x01 ,0x01 ,0x00 ,0x00 ,
0x00 ,0x80 ,0x90 ,0xFE ,0xAF ,0x76 ,0x21 ,0xDA ,
0x00 ,0x00 ,0x2A ,0x00 ,0x01 ,0xD0 ,0x79 ,0x58 ,
0x1D ,0x00 ,0x00 ,0x00 ,0x00 ,0x49 ,0x45 ,0x4E ,
0x44 ,0xAE ,0x42 ,0x60 ,0x82
};
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
{ {
JNIEnv* globalJniEnv; JNIEnv* globalJniEnv;
@ -25,8 +43,19 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
globalJVM = vm; globalJVM = vm;
loadJniRenderingContext(globalJniEnv); loadJniRenderingContext(globalJniEnv);
loadJniRenderingRules(globalJniEnv); loadJniRenderingRules(globalJniEnv);
osmand_log_print(LOG_INFO, "JNI_OnLoad completed"); // Encode and decode png (bug in PC Java linking, currently using -Bsymbolic?)
/*SkBitmap* bmp = new SkBitmap();
if(!SkImageDecoder::DecodeMemory(simplePng, simplePngSize, bmp)) {
osmand_log_print(LOG_INFO, "Initialization jni : decode png failed!");
return JNI_VERSION_1_6;
}
SkImageEncoder* enc = SkImageEncoder::Create(SkImageEncoder::kPNG_Type);
SkDynamicMemoryWStream* stream = new SkDynamicMemoryWStream();
enc->encodeStream(stream, *bmp, 80);
delete stream;
delete bmp;*/
osmand_log_print(LOG_INFO, "JNI_OnLoad completed");
return JNI_VERSION_1_6; return JNI_VERSION_1_6;
} }
@ -186,7 +215,6 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
RenderingRuleSearchRequest* req = initSearchRequest(ienv, renderingRuleSearchRequest); RenderingRuleSearchRequest* req = initSearchRequest(ienv, renderingRuleSearchRequest);
JNIRenderingContext rc; JNIRenderingContext rc;
pullFromJavaRenderingContext(ienv, renderingContext, &rc); pullFromJavaRenderingContext(ienv, renderingContext, &rc);
rc.setUseEnglishNames(useEnglishNames);
ResultPublisher* result = ((ResultPublisher*) searchResult); ResultPublisher* result = ((ResultPublisher*) searchResult);
// std::vector <BaseMapDataObject* > mapDataObjects = marshalObjects(binaryMapDataObjects); // std::vector <BaseMapDataObject* > mapDataObjects = marshalObjects(binaryMapDataObjects);
@ -304,6 +332,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_NativeLibrary_generateRende
bitmapData = malloc(bitmapDataSize); bitmapData = malloc(bitmapDataSize);
stream->copyTo(bitmapData); stream->copyTo(bitmapData);
delete enc;
} }
bitmapBuffer = ienv->NewDirectByteBuffer(bitmapData, bitmapDataSize); bitmapBuffer = ienv->NewDirectByteBuffer(bitmapData, bitmapDataSize);
@ -428,7 +457,6 @@ SkBitmap* JNIRenderingContext::getCachedBitmap(const std::string& bitmapResource
this->nativeOperations.start(); this->nativeOperations.start();
env->ReleaseByteArrayElements(javaIconRawData, bitmapBuffer, JNI_ABORT); env->ReleaseByteArrayElements(javaIconRawData, bitmapBuffer, JNI_ABORT);
env->DeleteLocalRef(javaIconRawData); env->DeleteLocalRef(javaIconRawData);
env->DeleteLocalRef(jstr);
throwNewException(env, (std::string("Failed to decode ") + bitmapResource).c_str()); throwNewException(env, (std::string("Failed to decode ") + bitmapResource).c_str());

View file

@ -9,7 +9,6 @@ LOCAL_MODULE := png
else else
LOCAL_MODULE := png_neon LOCAL_MODULE := png_neon
endif endif
LIBPNG
ifneq ($(OSMAND_USE_PREBUILT),true) ifneq ($(OSMAND_USE_PREBUILT),true)
common_CFLAGS := -fvisibility=hidden ## -fomit-frame-pointer common_CFLAGS := -fvisibility=hidden ## -fomit-frame-pointer