To get the below code to run, I need to either:
comment out MapUtils.createDefaultEventDispatcher(this, map);
or
change map type to UnfoldingMap[] map;
it seems to me that the tutorial is wrong in this regard. the error I see in eclipse is:
The method createDefaultEventDispatcher(PApplet, UnfoldingMap[]) in the type MapUtils is not applicable for the arguments (SampleMapApp, UnfoldingMap)
Can anyone suggest to me how I can fix this?
import processing.core.PApplet;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.providers.AbstractMapProvider;
import de.fhpotsdam.unfolding.providers.Google;
import de.fhpotsdam.unfolding.geo.Location;
import de.fhpotsdam.unfolding.utils.MapUtils;
public class SampleMapApp extends PApplet {
UnfoldingMap map;
public void setup() {
AbstractMapProvider provider = new Google.GoogleTerrainProvider();
size(800, 600, P2D);
map = new UnfoldingMap(this, 50, 50, 500, 350, provider);
// Show map around the location in the given zoom level.
map.zoomAndPanTo(14, new Location(53.385f, -6.161f));
// Add mouse and keyboard interactions
MapUtils.createDefaultEventDispatcher(this, map);
}
public void draw() {
map.draw();
}
}
OK, turns out that downloading the latest and greatest processing has fixed the issue. I'd love to know why the code 'mostly' works though if it was a library issue all along. thanks tnagel for getting me to check the processing version.
Related
So, I've recently downloaded (via Maven) jzy3d library so that I can translate and improve an existing program of mine from JS to Java, and to get a handle on the new library I was trying some examples available on the library site but, as the title shows I keep getting the "Builder cannot be resolved" error.
I've tried to add the org.jzy3d.plot3d.builder.Builder import but also without success, as it returns a non used import alert.
This is my code:
package randomProjects;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.ChartLauncher;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.colormaps.ColorMapRainbow;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.Quality;
public class SurfPlotTest_JZY3D {
public static void main(String[] args){
// Define a function to plot
Mapper mapper = new Mapper() {
public double f(double x, double y) {
return 10 * Math.sin(x / 10) * Math.cos(y / 20) * x;
}
};
// Define range and precision for the function to plot
Range range = new Range(-150, 150);
int steps = 50;
// Create a surface drawing that function;
Shape surface = Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), mapper);
surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f)));
surface.setFaceDisplayed(true);
surface.setWireframeDisplayed(false);
surface.setWireframeColor(Color.BLACK);
// Create a chart and add the surface
Chart chart = new Chart(Quality.Advanced);
chart.getScene().getGraph().add(surface);
ChartLauncher.openChart(chart);
}
}
And this is the error message:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Builder cannot be resolved
The field Quality.Advanced is not visible
at randomProjects.SurfPlotTest_JZY3D.main(SurfPlotTest_JZY3D.java:30)
I also find important to mention that there is another error in the program at line #37, that I've tried fixing exchanging Quality.Advanced by Quality.Advanced(), but again, without any success what so ever.
A bit of an update in the hope of an answer
If I use the manually imported project files, also available in the library site, I don't get the builder error, but instead when compiling it returns the following error.
The project: org.jzy3d-0.9 which is referenced by the classpath, does not exist.
And this is the example code present in the project
package org.jzy3d.demos.surface;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.controllers.keyboard.camera.CameraKeyController;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.colormaps.ColorMapRainbow;
import org.jzy3d.demos.AbstractDemo;
import org.jzy3d.demos.DemoLauncher;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.builder.Builder;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.Quality;
public class ColorWaveDemo extends AbstractDemo {
public static void main(String[] args) throws Exception {
DemoLauncher.openDemo(new ColorWaveDemo());
}
public ColorWaveDemo() {
}
#Override
public void init() {
// Define a function to plot
Mapper mapper = new Mapper() {
public double f(double x, double y) {
return x * Math.sin(x * y);
}
};
// Define range and precision for the function to plot
Range range = new Range(-3, 3);
int steps = 80;
// Create the object to represent the function over the given range.
final Shape surface = Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), mapper);
surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f)));
surface.setFaceDisplayed(true);
surface.setWireframeDisplayed(false);
// Create a chart
chart = new Chart(Quality.Advanced, getCanvasType());
chart.getScene().getGraph().add(surface);
chart.addController(new CameraKeyController());
}
}
Consider me a complete noob in importing libraries via Maven or otherwise, I'm doing all this to get a handle and learn how to, so I would appreciate a detailed answer. If needed I can also include my .pom file.
The tutorial page from the website is quite outdated. You may find easier to use the tutorials that are embedded in the library, e.g. this surface example.
The readme of this module should help as well.
This is my first question at stackoverflow so if I miss information let me know.
I want to make a program which shows a worldmap in which you can zoom in and out and place marker which moves around (like a game map).
Because I would like the world map to be used offline I am using unfoldingmaps http://unfoldingmaps.org/.
This works great if I use the examples.
Now I would like to integrate this into the program I have already written.
I am trying to integrate the Papplet of the unfoldingmaps into a JPanel. This JPanel is part of a tabbedPanel.
This is the code I use to add it to the tabbedPanel:
//Create game map menu
gameMapMenu = new JPanel();
tabbedPanelMain.addTab("World map", gameMapMenu);
//tabbedPanelMain.setEnabledAt(2, false);
worldMap = map.WorldMap.getWorldMap();
gameMapMenu.add("World map", worldMap);
This is the code (in a separate Class) which is used to generate the unfolding map:
UnfoldingMap map;
public void setup() {
size(800, 600, OPENGL);
map = new UnfoldingMap(this, new MBTilesMapProvider(mbTilesString));
MapUtils.createDefaultEventDispatcher(this, map);
map.setZoomRange(1, 10);
}
public void draw() {
background(0);
map.draw();
}
public static WorldMap getWorldMap() {
WorldMap worldMap = new WorldMap();
return worldMap;
}
I have two questions I have been really struggling with and I cannot find any answers for:
The example above does not give any errors. It starts the application and tabbedPanel but does not show the map. If I run the Papplet of the world map in Eclipse as a Applet it works fine. How do I add the Papplet with the map to my existing application so it is viewed through the tabbedPanel?
To update the markers on the world map I was thinking about adding functions to the class with the worldmap Papplet. Is this the way to interact with the Papplet from the application?
After a lot of trying I found out I needed to add the .init() function.
Can someone explain to me what this does?
//Create game map menu
gameMapMenu = new JPanel();
tabbedPanelMain.addTab("World map", gameMapMenu);
tabbedPanelMain.setEnabledAt(2, false);
worldMap = map.WorldMap.getWorldMap();
gameMapMenu.add("World map", worldMap);
worldMap.init();
I am just trying to extend a SimpleStringProperty in OpenJFX 11.0.1 to add some extra functionality. But ist seems not so easy, I experienced strange behavior of my extended Property and I don't know why. I think it should work.
My in this sample code simplified SimpleStringProperty extension contains another readonly string property which should be updated every time the the user types into a bound TextField. In this case remove all not allowed characters and convert the prefix. (I know this is not perfect but short enough to show)
After starting the sample code you will get a window with a rows of Controls. Typing in a String like "001 (242) 555666" the label should show the normalized phone number like "+1242555666".
The initial conversion works correcty.
I never get any exceptions.
The conversion is called when I type in new digits.
But if you play around with typing and deleting after a few seconds the set() method of my property isn't longer triggered by the bidirectional binding to the TextField.
To simplify the example I didn't use a TextFormatter. If I use one the problem doesn't change.
Can anyone help me figure out the problem?
Windows and OS X show the same behavior with OpenJFX 11 and OpenJFX 11.0.1
I tried the same code with JDK 1.8 and there it works fine.
package testproperty;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.property.SimpleStringProperty;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
public class TestProperty extends Application {
// attempt to create an own property
public class myPhoneNumberProperty extends SimpleStringProperty {
private final ReadOnlyStringWrapper normalizedNumber = new ReadOnlyStringWrapper("");
public ReadOnlyStringProperty normalizedNumberProperty() { return normalizedNumber.getReadOnlyProperty(); }
public String getNormalizedNumber() { return normalizedNumber.get(); }
public myPhoneNumberProperty() {
super();
}
public myPhoneNumberProperty(String s) {
super(s);
calculate();
}
#Override
public void set(String s) {
super.set(s);
calculate();
}
private void calculate() {
// some calculations (only for test purposes)
String original = this.get();
String result = original.replaceAll("[^0123456789]","");
if (result.startsWith("00")) result = result.replaceFirst("00", "+");
if (original.startsWith("+")) result = "+".concat(result);
normalizedNumber.set(result);
}
}
#Override
public void start(Stage primaryStage) {
// create my property
myPhoneNumberProperty phoneNumberA = new myPhoneNumberProperty("+34 952 111 222");
// set up grid pane
GridPane grid = new GridPane();
grid.setPadding(new Insets(5,5,5,5));
grid.setVgap(20);
grid.setHgap(20);
// set up the row
Label labelA = new Label("Enter phone number");
TextField textFieldA = new TextField();
textFieldA.textProperty().bindBidirectional(phoneNumberA);
Label labelB = new Label("Normalized number");
Label labelN = new Label();
labelN.textProperty().bind(phoneNumberA.normalizedNumberProperty());
grid.addRow(0, labelA, textFieldA, labelB, labelN);
// complete scene
Scene scene = new Scene(grid, 1000, 100);
primaryStage.setTitle("PhoneNumberProperty TestProg");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Your phoneNumberA property object is being garbage collected. To fix this you must keep a strong reference to the object. One option is to make it an instance field.
JavaFX implements bindings using weak listeners/references. Bidirectional bindings have no strong references to the other property. This is different from unidirectional bindings where a reference to the observable value must be kept in order to unbind from it later.
I want to create two windows by using just one single sketch in Processing.
What I'm trying to do is that if I click a button in one window, then some image appear in another window.
I've searched Google and found some examples. Actually, I found the same question in this 'stack overflow web'. Here are the links.
Create more than one window of a single sketch in Processing
http://forum.processing.org/one/topic/multiple-windows-2-4-2011.html
Here is the codes of second links.
import java.awt.Frame;
PFrame f;
secondApplet s;
//f = new PFrame();
void setup() {
size(320, 240);
f = new PFrame();
}
void draw() {
background(255,0,0);
fill(255);
rect(10,10,frameCount%0,10);
s.background(0, 0, 255);
s.fill(100);
s.rect(10,20,frameCount%0,10);
s.redraw();
}
public class PFrame extends Frame{
public PFrame() {
setBounds(100,100,400,300);
s = new secondApplet();
add(s);
s.init();
show();
}
}
public class secondApplet extends PApplet {
public void setup() {
size(400, 300);
noLoop();
}
public void draw() {
}
}
But when I run this codes, I get the following error message at add(s);.
The method add(Component) in the type Container is not applicable for the arguments (multi_window_test.secondApplet)
Code of first comment of first link is similar, but when I run this code, I get the same error message.
Other example codes that I found are all similar. They all create PFrame class and secondApplet which extends PApplet. They said these codes works well but I can't run these codes.
I couldn't find the reason of my error message. Other people seems to have no problem when running this example code except me.
If someone knows the solution, please help me.
Also, if there is a other simple way to create multi-windows in one sketch, please let me know.
The reason for the error message is pretty self-explanatory: the add() function is expecting a Component, and PApplet is not a Component. This is because PApplet no longer extends Applet as of Processing 3, so old code that uses it as a Component will no longer work.
Instead, consider my answer to this question. Basically, just create a class that extends PApplet for your second window, and then call PApplet.runSketch() using that second PApplet as a parameter:
void setup() {
size(100, 100);
String[] args = {"TwoFrameTest"};
SecondApplet sa = new SecondApplet();
PApplet.runSketch(args, sa);
}
void draw() {
background(0);
ellipse(50, 50, 10, 10);
}
public class SecondApplet extends PApplet {
public void settings() {
size(200, 100);
}
public void draw() {
background(255);
fill(0);
ellipse(100, 50, 10, 10);
}
}
probably a very simple issue related to importing the correct libraries but I cannot seem to find anything to help me.
Basically getting this error when trying to run my code:
"Cannot find a class or type named "DataEntry"
This is my Code here:
//Variables
UnfoldingMap map;
List<Marker>countryMarkers;
HashMap<String, DataEntry> dataEntriesMap;
//Core methods...
void setup() {
size(800, 600);
smooth();
map = new UnfoldingMap(this);
MapUtils.createDefaultEventDispatcher(this, map);
//Read in GeoJSON File - Countries
List<Feature> countries = GeoJSONReader.loadData(this, "countries.geo.json");
countryMarkers = MapUtils.createSimpleMarkers(countries);
map.addMarkers(countryMarkers);//Add the countries to the map
//External Data source - CSV file
}
void draw() {
map.draw();
}
//Other methods required...
This is a list of all my Imports
import de.fhpotsdam.unfolding.mapdisplay.*;
import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.unfolding.marker.*;
import de.fhpotsdam.unfolding.tiles.*;
import de.fhpotsdam.unfolding.interactions.*;
import de.fhpotsdam.unfolding.ui.*;
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.core.*;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.geo.*;
import de.fhpotsdam.unfolding.texture.*;
import de.fhpotsdam.unfolding.events.*;
import de.fhpotsdam.utils.*;
import de.fhpotsdam.unfolding.providers.*;
import processing.opengl.*;
import java.util.List;
import java.util.HashMap;
I am experimenting with GeoSpatial data using Processing and the Unfolding Map Library.
I'd appreciate any help guys.
I am not entirely familiar with the packages you are using but based on examples I've seen, it seems as though you are missing an inner class.
Try updating the code as indicated below noting the DateEntry inner class at the very bottom:
//Variables
UnfoldingMap map;
List<Marker>countryMarkers;
HashMap<String, DataEntry> dataEntriesMap;
//Core methods...
void setup() {
size(800, 600);
smooth();
map = new UnfoldingMap(this);
MapUtils.createDefaultEventDispatcher(this, map);
//Read in GeoJSON File - Countries
List<Feature> countries = GeoJSONReader.loadData(this, "countries.geo.json");
countryMarkers = MapUtils.createSimpleMarkers(countries);
map.addMarkers(countryMarkers);//Add the countries to the map
//External Data source - CSV file
}
void draw() {
map.draw();
}
public class DataEntry {
String countryName;
String id;
Integer year;
Float value;
}