为什么会这样(Processing 和 UnfoldingMaps 的奇怪之处)
Why is this happening (strangeness with Processing and UnfoldingMaps)
作为 UCSD Java class 课程的一部分,我们正在使用 Processing 和 Unfolding Maps 库。
本课程为您提供了入门代码,我正在尝试对其进行扩展。但是我运行遇到了问题
在我的大部分学习时间所在的工作计算机上,我启动了一个非常不错的应用程序。我决定把它带回家给我妻子看,方法是将我的 github 存储库克隆到我的家用笔记本电脑上。
None 个 librar/JAR 个文件被包含在内,所以我直接从 Processing and Unfolding 的下载页面下载了它们。结果是一场噩梦。一个接一个的错误。我假设 coursera/UCSD 使用旧版本的库,而新版本不向后兼容。看起来很蹩脚,但无论如何。
接下来,我从 coursera sight 下载了所有的 JAR 文件。结果好一点,但事情仍然很古怪。也就是说,当我创建一个 UnfoldingMap()
对象时,window 中的位置参数以及大小参数绝对没有任何作用。
1.) 我使用 Processing size()
方法来放大或缩小包含 window 的大小,它会放大或缩小地图对象。它完全忽略了 UnfoldingMap()
.
的大小和位置参数
2.) 地图对象总是被推到 window 的左下角,不管它是位置参数。
3.) 我选择的灰色 background()
确实显示在地图周围,但背景本身随后被一个大的黑色区域包围,它也随 size()
参数缩放。
这是一些代码:
package module3;
//Java utilities libraries
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
//Processing library
import processing.core.PApplet;
//Unfolding libraries
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.marker.Marker;
import de.fhpotsdam.unfolding.data.PointFeature;
import de.fhpotsdam.unfolding.marker.SimplePointMarker;
import de.fhpotsdam.unfolding.providers.Google;
import de.fhpotsdam.unfolding.providers.MBTilesMapProvider;
import de.fhpotsdam.unfolding.utils.MapUtils;
//Parsing library
import parsing.ParseFeed;
public class EarthquakeCityMap extends PApplet {
// Less than this threshold is a light earthquake
public static final float THRESHOLD_MODERATE = 5;
// Less than this threshold is a minor earthquake
public static final float THRESHOLD_LIGHT = 4;
// This is where to find the local tiles, for working without an
// Internet connection
public static String mbTilesString = "blankLight-1-3.mbtiles";
// The map
private UnfoldingMap map;
//feed with magnitude 2.5+ Earthquakes
private String earthquakesURLweek = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.atom";
private String earthquakesURLday = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.atom";
public void setup() {
size(400, 400, "processing.opengl.PGraphics3D");
background(99);
map = new UnfoldingMap(this, 50, 50, 1100, 700, new Google.GoogleMapProvider());
map.zoomToLevel(2);
MapUtils.createDefaultEventDispatcher(this, map);
//List of markers to be added to map
List<Marker> markers = new ArrayList<Marker>();
//Use parser to collect properties for each earthquake
//PointFeatures have a getLocation method
List<PointFeature> earthquakes = ParseFeed.parseEarthquake(this, earthquakesURLweek);
// for each earthqauke feature, create a custom marker and add it
// to the list.
for (PointFeature quake : earthquakes){
Marker quakeMark = createMarker(quake);
markers.add(quakeMark);
Map<String, Object> properties = quakeMark.getProperties();
}
// Add the markers to the map so that they are displayed
map.addMarkers(markers);
}
/**
* A helper method to style markers based on features (magnitude, depth,
* etc) of an earthquake.
* @param feature A PointFeature object representing a single earthquake.
* @return
*/
private SimplePointMarker createMarker(PointFeature feature){
// Create a new SimplePointMarker at the location given by the PointFeature
SimplePointMarker marker = new SimplePointMarker(feature.getLocation(), feature.getProperties());
Object magObj = feature.getProperty("magnitude");
Object ageObj = marker.getProperty("days ellapsed");
float mag = Float.parseFloat(magObj.toString());
int age = (int) ageObj;
//Set processing color and alpha data, for setting marker colors
//below.
int alpha = 255 - (age * 255 / 7);
int yellow = color(255, 255, 0, alpha);
int red = color(255, 0, 0, alpha);
int green = color(0, 255, 0, alpha);
// Style markers based on earthquake magnitude
if (mag < THRESHOLD_LIGHT){
marker.setColor(green);
}
if (mag >= THRESHOLD_LIGHT && mag < THRESHOLD_MODERATE){
marker.setColor(yellow);
}
if (mag >= THRESHOLD_MODERATE){
marker.setColor(red);
}
//set radius of marker based on quake magnitude
float radius = (float) (mag * 3.5);
marker.setStrokeColor(color(50,15));
marker.setRadius(radius);
return marker;
}
public void draw() {
map.draw();
addKey();
}
最简单的选择是使用 Unfolding 仍然支持的过时版本处理,例如 Unfolding 0.9.6 (for Processing 2.2.1)。
由于您使用的是 eclipse,因此您实际上可以编译一个更新的版本可能适合您。
(我注意到去年有一些 minor updates,但没有发布)。
要通过 Eclipse 更新,您可以:
- 获取存储库(如果您使用的是 Unix 系统 (Linux/OSX),您可能已经安装了
git
:git clone https://github.com/tillnagel/unfolding
:这样您就可以随时获取最新更新并轻松重建,否则下载 zip、解压缩等)
- 在eclipse中导入项目(通过Import Existing Project)
- 将 build.xml 从项目拖到 Ant View 和 select 目标中进行编译。
main
将编译所有这些,包括处理包装器。
如果只想使用命令行:
- 安装 Ant(如果你的系统上还没有)并将它添加到你的
PATH
环境变量中(例如检查 echo $PATH
on Unix 或 echo %PATH%
on Windows 并确保列出了 ant 所在的文件夹,如果没有添加它)
- clone/download 回购
- 运行 ant(例如
ant unfolding_processing
仅构建处理包装器或简单地 ant
(默认为 main
目标构建所有内容)
我可以确认从 github 手动编译最新版本适用于 Processing 3.4
我已经上传了 Processing wrapper here:希望您可以将 .jar 文件拖到您的 eclipse 项目之上。
作为 UCSD Java class 课程的一部分,我们正在使用 Processing 和 Unfolding Maps 库。
本课程为您提供了入门代码,我正在尝试对其进行扩展。但是我运行遇到了问题
在我的大部分学习时间所在的工作计算机上,我启动了一个非常不错的应用程序。我决定把它带回家给我妻子看,方法是将我的 github 存储库克隆到我的家用笔记本电脑上。
None 个 librar/JAR 个文件被包含在内,所以我直接从 Processing and Unfolding 的下载页面下载了它们。结果是一场噩梦。一个接一个的错误。我假设 coursera/UCSD 使用旧版本的库,而新版本不向后兼容。看起来很蹩脚,但无论如何。
接下来,我从 coursera sight 下载了所有的 JAR 文件。结果好一点,但事情仍然很古怪。也就是说,当我创建一个 UnfoldingMap()
对象时,window 中的位置参数以及大小参数绝对没有任何作用。
1.) 我使用 Processing size()
方法来放大或缩小包含 window 的大小,它会放大或缩小地图对象。它完全忽略了 UnfoldingMap()
.
2.) 地图对象总是被推到 window 的左下角,不管它是位置参数。
3.) 我选择的灰色 background()
确实显示在地图周围,但背景本身随后被一个大的黑色区域包围,它也随 size()
参数缩放。
这是一些代码:
package module3;
//Java utilities libraries
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
//Processing library
import processing.core.PApplet;
//Unfolding libraries
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.marker.Marker;
import de.fhpotsdam.unfolding.data.PointFeature;
import de.fhpotsdam.unfolding.marker.SimplePointMarker;
import de.fhpotsdam.unfolding.providers.Google;
import de.fhpotsdam.unfolding.providers.MBTilesMapProvider;
import de.fhpotsdam.unfolding.utils.MapUtils;
//Parsing library
import parsing.ParseFeed;
public class EarthquakeCityMap extends PApplet {
// Less than this threshold is a light earthquake
public static final float THRESHOLD_MODERATE = 5;
// Less than this threshold is a minor earthquake
public static final float THRESHOLD_LIGHT = 4;
// This is where to find the local tiles, for working without an
// Internet connection
public static String mbTilesString = "blankLight-1-3.mbtiles";
// The map
private UnfoldingMap map;
//feed with magnitude 2.5+ Earthquakes
private String earthquakesURLweek = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.atom";
private String earthquakesURLday = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.atom";
public void setup() {
size(400, 400, "processing.opengl.PGraphics3D");
background(99);
map = new UnfoldingMap(this, 50, 50, 1100, 700, new Google.GoogleMapProvider());
map.zoomToLevel(2);
MapUtils.createDefaultEventDispatcher(this, map);
//List of markers to be added to map
List<Marker> markers = new ArrayList<Marker>();
//Use parser to collect properties for each earthquake
//PointFeatures have a getLocation method
List<PointFeature> earthquakes = ParseFeed.parseEarthquake(this, earthquakesURLweek);
// for each earthqauke feature, create a custom marker and add it
// to the list.
for (PointFeature quake : earthquakes){
Marker quakeMark = createMarker(quake);
markers.add(quakeMark);
Map<String, Object> properties = quakeMark.getProperties();
}
// Add the markers to the map so that they are displayed
map.addMarkers(markers);
}
/**
* A helper method to style markers based on features (magnitude, depth,
* etc) of an earthquake.
* @param feature A PointFeature object representing a single earthquake.
* @return
*/
private SimplePointMarker createMarker(PointFeature feature){
// Create a new SimplePointMarker at the location given by the PointFeature
SimplePointMarker marker = new SimplePointMarker(feature.getLocation(), feature.getProperties());
Object magObj = feature.getProperty("magnitude");
Object ageObj = marker.getProperty("days ellapsed");
float mag = Float.parseFloat(magObj.toString());
int age = (int) ageObj;
//Set processing color and alpha data, for setting marker colors
//below.
int alpha = 255 - (age * 255 / 7);
int yellow = color(255, 255, 0, alpha);
int red = color(255, 0, 0, alpha);
int green = color(0, 255, 0, alpha);
// Style markers based on earthquake magnitude
if (mag < THRESHOLD_LIGHT){
marker.setColor(green);
}
if (mag >= THRESHOLD_LIGHT && mag < THRESHOLD_MODERATE){
marker.setColor(yellow);
}
if (mag >= THRESHOLD_MODERATE){
marker.setColor(red);
}
//set radius of marker based on quake magnitude
float radius = (float) (mag * 3.5);
marker.setStrokeColor(color(50,15));
marker.setRadius(radius);
return marker;
}
public void draw() {
map.draw();
addKey();
}
最简单的选择是使用 Unfolding 仍然支持的过时版本处理,例如 Unfolding 0.9.6 (for Processing 2.2.1)。
由于您使用的是 eclipse,因此您实际上可以编译一个更新的版本可能适合您。 (我注意到去年有一些 minor updates,但没有发布)。 要通过 Eclipse 更新,您可以:
- 获取存储库(如果您使用的是 Unix 系统 (Linux/OSX),您可能已经安装了
git
:git clone https://github.com/tillnagel/unfolding
:这样您就可以随时获取最新更新并轻松重建,否则下载 zip、解压缩等) - 在eclipse中导入项目(通过Import Existing Project)
- 将 build.xml 从项目拖到 Ant View 和 select 目标中进行编译。
main
将编译所有这些,包括处理包装器。
如果只想使用命令行:
- 安装 Ant(如果你的系统上还没有)并将它添加到你的
PATH
环境变量中(例如检查echo $PATH
on Unix 或echo %PATH%
on Windows 并确保列出了 ant 所在的文件夹,如果没有添加它) - clone/download 回购
- 运行 ant(例如
ant unfolding_processing
仅构建处理包装器或简单地ant
(默认为main
目标构建所有内容)
我可以确认从 github 手动编译最新版本适用于 Processing 3.4
我已经上传了 Processing wrapper here:希望您可以将 .jar 文件拖到您的 eclipse 项目之上。