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 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_MAP_CREATOR_NAME = "OsmAndMapCreator"; //$NON-NLS-1$
|
||||
|
|
|
@ -12,15 +12,12 @@ import javax.swing.BorderFactory;
|
|||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import net.osmand.data.preparation.MapZooms;
|
||||
|
||||
public class NativePreferencesDialog extends JDialog {
|
||||
|
||||
private static final long serialVersionUID = -4862884032977071296L;
|
||||
|
@ -32,6 +29,9 @@ public class NativePreferencesDialog extends JDialog {
|
|||
private JTextField renderingStyleFile;
|
||||
private boolean okPressed;
|
||||
|
||||
private JTextField renderingPropertiesTxt;
|
||||
private static String renderingProperties = "nightMode=false, appMode=default, noPolygons=false, hmRendered=false";
|
||||
|
||||
|
||||
public NativePreferencesDialog(Component parent){
|
||||
super(JOptionPane.getFrameForComponent(parent), true);
|
||||
|
@ -119,18 +119,43 @@ public class NativePreferencesDialog extends JDialog {
|
|||
constr.gridx = 1;
|
||||
constr.gridy = 3;
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String getRenderingProperties() {
|
||||
return renderingProperties;
|
||||
}
|
||||
|
||||
private void addListeners(){
|
||||
okButton.addActionListener(new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
saveProperties();
|
||||
okPressed = true;
|
||||
renderingProperties = renderingPropertiesTxt.getText();
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
@ -15,19 +16,23 @@ import org.xml.sax.SAXException;
|
|||
|
||||
import resources._R;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.NativeLibrary;
|
||||
import net.osmand.RenderingContext;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.render.RenderingRuleProperty;
|
||||
import net.osmand.render.RenderingRuleSearchRequest;
|
||||
import net.osmand.render.RenderingRuleStorageProperties;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver;
|
||||
|
||||
public class NativeSwingRendering extends NativeLibrary {
|
||||
|
||||
RenderingRulesStorage storage;
|
||||
private HashMap<String, String> renderingProps;
|
||||
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();
|
||||
final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() {
|
||||
@Override
|
||||
|
@ -47,12 +52,20 @@ public class NativeSwingRendering extends NativeLibrary {
|
|||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
public NativeSwingRendering(){
|
||||
try {
|
||||
loadRuleStorage(null);
|
||||
loadRuleStorage(null, "");
|
||||
} catch (SAXException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
|
@ -71,9 +84,28 @@ public class NativeSwingRendering extends NativeLibrary {
|
|||
return _R.getIconData(data);
|
||||
}
|
||||
};
|
||||
rctx.nightMode = true;
|
||||
|
||||
rctx.nightMode = "true".equals(renderingProps.get("nightMode"));
|
||||
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,
|
||||
rctx, "Nothing found");
|
||||
|
||||
|
@ -81,9 +113,20 @@ public class NativeSwingRendering extends NativeLibrary {
|
|||
rctx.topY = (float) (((double)stop)/ MapUtils.getPowZoom(31-zoom));
|
||||
rctx.width = (int) ((sright - sleft) / MapUtils.getPowZoom(31 - zoom - 8));
|
||||
rctx.height = (int) ((sbottom - stop) / MapUtils.getPowZoom(31 - zoom - 8));
|
||||
rctx.shadowRenderingMode = 2;
|
||||
rctx.shadowRenderingColor = 0xff969696;
|
||||
rctx.defaultColor = 0xfff1eee8;
|
||||
|
||||
request.clearState();
|
||||
|
||||
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;
|
||||
long search = time + System.currentTimeMillis();
|
||||
final RenderingGenerationResult rres = NativeSwingRendering.generateRenderingIndirect(rctx, res.nativeHandler,
|
||||
|
|
|
@ -228,7 +228,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
NativePreferencesDialog dlg = new NativePreferencesDialog(frame);
|
||||
dlg.showDialog();
|
||||
if(dlg.isOkPressed()) {
|
||||
initNativeRendering();
|
||||
initNativeRendering(NativePreferencesDialog.getRenderingProperties());
|
||||
} else {
|
||||
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();
|
||||
if (fl != null) {
|
||||
NativeSwingRendering lib = NativeSwingRendering.loadLibrary(fl);
|
||||
if (lib != null) {
|
||||
try {
|
||||
lib.initFilesInDir(new File(DataExtractionSettings.getSettings().getBinaryFilesDir()));
|
||||
lib.loadRuleStorage(DataExtractionSettings.getSettings().getRenderXmlPath());
|
||||
lib.loadRuleStorage(DataExtractionSettings.getSettings().getRenderXmlPath(), renderingProperties);
|
||||
mapPanel.setNativeLibrary(lib);
|
||||
mapPanel.repaint();
|
||||
} catch (SAXException e) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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"
|
||||
android:value="AEdPqrEAAAAIqF3tNGT66etVBn_vgzpfAY1wmIzKV1Ss6Ku-2A" />
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<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 -->
|
||||
<string name="ga_api_key">UA-28342846-2</string>
|
||||
<string name="ga_dispatchPeriod">10</string>
|
||||
|
|
Loading…
Reference in a new issue