Adjust rendering on fly
This commit is contained in:
parent
baee0f0d4a
commit
d62472532d
6 changed files with 84 additions and 16 deletions
|
@ -5,7 +5,7 @@ import java.net.URLEncoder;
|
||||||
|
|
||||||
public class MapCreatorVersion {
|
public class MapCreatorVersion {
|
||||||
|
|
||||||
public static String APP_VERSION = "0.8.1"; //$NON-NLS-1$
|
public static String APP_VERSION = "0.8.2"; //$NON-NLS-1$
|
||||||
public static final String APP_DESCRIPTION = "alpha"; //$NON-NLS-1$
|
public static final String APP_DESCRIPTION = "alpha"; //$NON-NLS-1$
|
||||||
|
|
||||||
public static final String APP_MAP_CREATOR_NAME = "OsmAndMapCreator"; //$NON-NLS-1$
|
public static final String APP_MAP_CREATOR_NAME = "OsmAndMapCreator"; //$NON-NLS-1$
|
||||||
|
|
|
@ -12,15 +12,12 @@ import javax.swing.BorderFactory;
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JCheckBox;
|
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
import net.osmand.data.preparation.MapZooms;
|
|
||||||
|
|
||||||
public class NativePreferencesDialog extends JDialog {
|
public class NativePreferencesDialog extends JDialog {
|
||||||
|
|
||||||
private static final long serialVersionUID = -4862884032977071296L;
|
private static final long serialVersionUID = -4862884032977071296L;
|
||||||
|
@ -32,6 +29,9 @@ public class NativePreferencesDialog extends JDialog {
|
||||||
private JTextField renderingStyleFile;
|
private JTextField renderingStyleFile;
|
||||||
private boolean okPressed;
|
private boolean okPressed;
|
||||||
|
|
||||||
|
private JTextField renderingPropertiesTxt;
|
||||||
|
private static String renderingProperties = "nightMode=false, appMode=default, noPolygons=false, hmRendered=false";
|
||||||
|
|
||||||
|
|
||||||
public NativePreferencesDialog(Component parent){
|
public NativePreferencesDialog(Component parent){
|
||||||
super(JOptionPane.getFrameForComponent(parent), true);
|
super(JOptionPane.getFrameForComponent(parent), true);
|
||||||
|
@ -120,17 +120,42 @@ public class NativePreferencesDialog extends JDialog {
|
||||||
constr.gridy = 3;
|
constr.gridy = 3;
|
||||||
l.setConstraints(renderingStyleFile, constr);
|
l.setConstraints(renderingStyleFile, constr);
|
||||||
|
|
||||||
|
label = new JLabel("Rendering properties : ");
|
||||||
|
panel.add(label);
|
||||||
|
constr = new GridBagConstraints();
|
||||||
|
constr.ipadx = 5;
|
||||||
|
constr.gridx = 0;
|
||||||
|
constr.gridy = 4;
|
||||||
|
constr.anchor = GridBagConstraints.WEST;
|
||||||
|
l.setConstraints(label, constr);
|
||||||
|
|
||||||
|
renderingPropertiesTxt = new JTextField();
|
||||||
|
renderingPropertiesTxt.setText(renderingProperties);
|
||||||
|
panel.add(renderingPropertiesTxt);
|
||||||
|
constr = new GridBagConstraints();
|
||||||
|
constr.weightx = 1;
|
||||||
|
constr.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
constr.ipadx = 5;
|
||||||
|
constr.gridx = 1;
|
||||||
|
constr.gridy = 4;
|
||||||
|
l.setConstraints(renderingPropertiesTxt, constr);
|
||||||
|
|
||||||
panel.setMaximumSize(new Dimension(Short.MAX_VALUE, panel.getPreferredSize().height));
|
panel.setMaximumSize(new Dimension(Short.MAX_VALUE, panel.getPreferredSize().height));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getRenderingProperties() {
|
||||||
|
return renderingProperties;
|
||||||
|
}
|
||||||
|
|
||||||
private void addListeners(){
|
private void addListeners(){
|
||||||
okButton.addActionListener(new ActionListener(){
|
okButton.addActionListener(new ActionListener(){
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
saveProperties();
|
saveProperties();
|
||||||
okPressed = true;
|
okPressed = true;
|
||||||
|
renderingProperties = renderingPropertiesTxt.getText();
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
@ -15,19 +16,23 @@ import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import resources._R;
|
import resources._R;
|
||||||
|
|
||||||
|
import net.osmand.Algoritms;
|
||||||
import net.osmand.NativeLibrary;
|
import net.osmand.NativeLibrary;
|
||||||
import net.osmand.RenderingContext;
|
import net.osmand.RenderingContext;
|
||||||
import net.osmand.osm.MapUtils;
|
import net.osmand.osm.MapUtils;
|
||||||
|
import net.osmand.render.RenderingRuleProperty;
|
||||||
import net.osmand.render.RenderingRuleSearchRequest;
|
import net.osmand.render.RenderingRuleSearchRequest;
|
||||||
|
import net.osmand.render.RenderingRuleStorageProperties;
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
import net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver;
|
import net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver;
|
||||||
|
|
||||||
public class NativeSwingRendering extends NativeLibrary {
|
public class NativeSwingRendering extends NativeLibrary {
|
||||||
|
|
||||||
RenderingRulesStorage storage;
|
RenderingRulesStorage storage;
|
||||||
|
private HashMap<String, String> renderingProps;
|
||||||
private static NativeSwingRendering defaultLoadedLibrary;
|
private static NativeSwingRendering defaultLoadedLibrary;
|
||||||
|
|
||||||
public void loadRuleStorage(String path) throws SAXException, IOException{
|
public void loadRuleStorage(String path, String renderingProperties) throws SAXException, IOException{
|
||||||
RenderingRulesStorage storage = new RenderingRulesStorage();
|
RenderingRulesStorage storage = new RenderingRulesStorage();
|
||||||
final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() {
|
final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,12 +52,20 @@ public class NativeSwingRendering extends NativeLibrary {
|
||||||
} else {
|
} else {
|
||||||
storage.parseRulesFromXmlInputStream(new FileInputStream(path), resolver);
|
storage.parseRulesFromXmlInputStream(new FileInputStream(path), resolver);
|
||||||
}
|
}
|
||||||
|
renderingProps = new HashMap<String, String>();
|
||||||
|
String[] props = renderingProperties.split(",");
|
||||||
|
for (String s : props) {
|
||||||
|
int i = s.indexOf('=');
|
||||||
|
if (i > 0) {
|
||||||
|
renderingProps.put(s.substring(0, i).trim(), s.substring(i + 1).trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSwingRendering(){
|
public NativeSwingRendering(){
|
||||||
try {
|
try {
|
||||||
loadRuleStorage(null);
|
loadRuleStorage(null, "");
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -71,9 +84,28 @@ public class NativeSwingRendering extends NativeLibrary {
|
||||||
return _R.getIconData(data);
|
return _R.getIconData(data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
rctx.nightMode = true;
|
rctx.nightMode = "true".equals(renderingProps.get("nightMode"));
|
||||||
|
|
||||||
RenderingRuleSearchRequest request = new RenderingRuleSearchRequest(storage);
|
RenderingRuleSearchRequest request = new RenderingRuleSearchRequest(storage);
|
||||||
|
request.setBooleanFilter(request.ALL.R_NIGHT_MODE, rctx.nightMode);
|
||||||
|
for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) {
|
||||||
|
String res = renderingProps.get(customProp.getAttrName());
|
||||||
|
if (!Algoritms.isEmpty(res)) {
|
||||||
|
if (customProp.isString()) {
|
||||||
|
request.setStringFilter(customProp, res);
|
||||||
|
} else if (customProp.isBoolean()) {
|
||||||
|
request.setBooleanFilter(customProp, "true".equalsIgnoreCase(res));
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
request.setIntFilter(customProp, Integer.parseInt(res));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request.setIntFilter(request.ALL.R_MINZOOM, zoom);
|
||||||
|
request.saveState();
|
||||||
|
|
||||||
NativeSearchResult res = searchObjectsForRendering(sleft, sright, stop, sbottom, zoom, request, true,
|
NativeSearchResult res = searchObjectsForRendering(sleft, sright, stop, sbottom, zoom, request, true,
|
||||||
rctx, "Nothing found");
|
rctx, "Nothing found");
|
||||||
|
|
||||||
|
@ -81,9 +113,20 @@ public class NativeSwingRendering extends NativeLibrary {
|
||||||
rctx.topY = (float) (((double)stop)/ MapUtils.getPowZoom(31-zoom));
|
rctx.topY = (float) (((double)stop)/ MapUtils.getPowZoom(31-zoom));
|
||||||
rctx.width = (int) ((sright - sleft) / MapUtils.getPowZoom(31 - zoom - 8));
|
rctx.width = (int) ((sright - sleft) / MapUtils.getPowZoom(31 - zoom - 8));
|
||||||
rctx.height = (int) ((sbottom - stop) / MapUtils.getPowZoom(31 - zoom - 8));
|
rctx.height = (int) ((sbottom - stop) / MapUtils.getPowZoom(31 - zoom - 8));
|
||||||
rctx.shadowRenderingMode = 2;
|
|
||||||
rctx.shadowRenderingColor = 0xff969696;
|
request.clearState();
|
||||||
rctx.defaultColor = 0xfff1eee8;
|
|
||||||
|
if(request.searchRenderingAttribute(RenderingRuleStorageProperties.A_DEFAULT_COLOR)) {
|
||||||
|
rctx.defaultColor = request.getIntPropertyValue(request.ALL.R_ATTR_COLOR_VALUE);
|
||||||
|
System.out.println("!"+ Integer.toHexString(rctx.defaultColor));
|
||||||
|
}
|
||||||
|
request.clearState();
|
||||||
|
request.setIntFilter(request.ALL.R_MINZOOM, zoom);
|
||||||
|
if(request.searchRenderingAttribute(RenderingRuleStorageProperties.A_SHADOW_RENDERING)) {
|
||||||
|
rctx.shadowRenderingMode = request.getIntPropertyValue(request.ALL.R_ATTR_INT_VALUE);
|
||||||
|
rctx.shadowRenderingColor = request.getIntPropertyValue(request.ALL.R_SHADOW_COLOR);
|
||||||
|
|
||||||
|
}
|
||||||
rctx.zoom = zoom;
|
rctx.zoom = zoom;
|
||||||
long search = time + System.currentTimeMillis();
|
long search = time + System.currentTimeMillis();
|
||||||
final RenderingGenerationResult rres = NativeSwingRendering.generateRenderingIndirect(rctx, res.nativeHandler,
|
final RenderingGenerationResult rres = NativeSwingRendering.generateRenderingIndirect(rctx, res.nativeHandler,
|
||||||
|
|
|
@ -228,7 +228,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
NativePreferencesDialog dlg = new NativePreferencesDialog(frame);
|
NativePreferencesDialog dlg = new NativePreferencesDialog(frame);
|
||||||
dlg.showDialog();
|
dlg.showDialog();
|
||||||
if(dlg.isOkPressed()) {
|
if(dlg.isOkPressed()) {
|
||||||
initNativeRendering();
|
initNativeRendering(NativePreferencesDialog.getRenderingProperties());
|
||||||
} else {
|
} else {
|
||||||
showOfflineIndex.setSelected(false);
|
showOfflineIndex.setSelected(false);
|
||||||
}
|
}
|
||||||
|
@ -239,14 +239,14 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initNativeRendering() {
|
private void initNativeRendering(String renderingProperties) {
|
||||||
String fl = DataExtractionSettings.getSettings().getNativeLibFile();
|
String fl = DataExtractionSettings.getSettings().getNativeLibFile();
|
||||||
if (fl != null) {
|
if (fl != null) {
|
||||||
NativeSwingRendering lib = NativeSwingRendering.loadLibrary(fl);
|
NativeSwingRendering lib = NativeSwingRendering.loadLibrary(fl);
|
||||||
if (lib != null) {
|
if (lib != null) {
|
||||||
try {
|
try {
|
||||||
lib.initFilesInDir(new File(DataExtractionSettings.getSettings().getBinaryFilesDir()));
|
lib.initFilesInDir(new File(DataExtractionSettings.getSettings().getBinaryFilesDir()));
|
||||||
lib.loadRuleStorage(DataExtractionSettings.getSettings().getRenderXmlPath());
|
lib.loadRuleStorage(DataExtractionSettings.getSettings().getRenderXmlPath(), renderingProperties);
|
||||||
mapPanel.setNativeLibrary(lib);
|
mapPanel.setNativeLibrary(lib);
|
||||||
mapPanel.repaint();
|
mapPanel.repaint();
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="net.osmand.plus" android:installLocation="auto" android:versionName="@string/app_version" android:versionCode="62">
|
package="net.osmand.plus" android:installLocation="auto" android:versionName="@string/app_version" android:versionCode="65">
|
||||||
<meta-data android:name="com.google.android.backup.api_key"
|
<meta-data android:name="com.google.android.backup.api_key"
|
||||||
android:value="AEdPqrEAAAAIqF3tNGT66etVBn_vgzpfAY1wmIzKV1Ss6Ku-2A" />
|
android:value="AEdPqrEAAAAIqF3tNGT66etVBn_vgzpfAY1wmIzKV1Ss6Ku-2A" />
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">OsmAnd~</string>
|
<string name="app_name">OsmAnd~</string>
|
||||||
<string name="app_version">0.8.0 alpha</string>
|
<string name="app_version">0.8.2 alpha</string>
|
||||||
<!-- Not translatable -->
|
<!-- Not translatable -->
|
||||||
<string name="ga_api_key">UA-28342846-2</string>
|
<string name="ga_api_key">UA-28342846-2</string>
|
||||||
<string name="ga_dispatchPeriod">10</string>
|
<string name="ga_dispatchPeriod">10</string>
|
||||||
|
|
Loading…
Reference in a new issue