リビジョン b532e058
| nbproject/project.properties | ||
|---|---|---|
|
dist.javadoc.dir=${dist.dir}/javadoc
|
||
|
endorsed.classpath=
|
||
|
excludes=
|
||
|
file.reference.proj4j-0.1.0.jar=lib/proj4j-0.1.0.jar
|
||
|
file.reference.shapefilereader-1.0.jar=lib/shapefilereader-1.0.jar
|
||
|
includes=**
|
||
|
# Non-JavaFX jar file creation is deactivated in JavaFX 2.0+ projects
|
||
| ... | ... | |
|
jar.compress=false
|
||
|
javac.classpath=\
|
||
|
${javafx.classpath.extension}:\
|
||
|
${file.reference.shapefilereader-1.0.jar}
|
||
|
${file.reference.shapefilereader-1.0.jar}:\
|
||
|
${file.reference.proj4j-0.1.0.jar}
|
||
|
# Space-separated list of extra javac options
|
||
|
javac.compilerargs=
|
||
|
javac.deprecation=false
|
||
| ... | ... | |
|
javadoc.nonavbar=false
|
||
|
javadoc.notree=false
|
||
|
javadoc.private=false
|
||
|
javadoc.reference.proj4j-0.1.0.jar=lib/proj4j-0.1.0-javadoc.jar
|
||
|
javadoc.splitindex=true
|
||
|
javadoc.use=true
|
||
|
javadoc.version=false
|
||
| src/com/torutk/tinymap/TinyMapModel.java | ||
|---|---|---|
|
import org.nocrala.tools.gis.data.esri.shapefile.shape.PointData;
|
||
|
import org.nocrala.tools.gis.data.esri.shapefile.shape.ShapeType;
|
||
|
import org.nocrala.tools.gis.data.esri.shapefile.shape.shapes.PolylineShape;
|
||
|
import org.osgeo.proj4j.CRSFactory;
|
||
|
import org.osgeo.proj4j.CoordinateReferenceSystem;
|
||
|
import org.osgeo.proj4j.CoordinateTransform;
|
||
|
import org.osgeo.proj4j.CoordinateTransformFactory;
|
||
|
import org.osgeo.proj4j.ProjCoordinate;
|
||
|
|
||
|
/**
|
||
|
*
|
||
| ... | ... | |
|
private File mapFile;
|
||
|
private List<TinyMapPolyline> polylines = new ArrayList<>();
|
||
|
private Function<PointData, Point2D> projection;
|
||
|
|
||
|
|
||
|
public TinyMapModel(File selected) {
|
||
|
mapFile = selected;
|
||
|
projection = p -> new Point2D(p.getX() * 100_000, p.getY() * 100_000); // 1度100kmとした直交座標変換
|
||
| ... | ... | |
|
polylines.add(new TinyMapPolyline(xs, ys));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static enum MapProjection {
|
||
|
MOLLWEIDE("ESRI:54009"),
|
||
|
MERCATOR("ESRI:54004"),
|
||
|
ECKERT6("ESRI:54010"),
|
||
|
CASSINI("ESRI:54028");
|
||
|
|
||
|
private CRSFactory crsFactory = new CRSFactory();
|
||
|
private CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
|
||
|
|
||
|
private CoordinateReferenceSystem crsWgs84;
|
||
|
private CoordinateReferenceSystem crsProjected;
|
||
|
private CoordinateTransform transform;
|
||
|
|
||
|
private MapProjection(String name) {
|
||
|
crsWgs84 = crsFactory.createFromName("EPSG:4326");
|
||
|
crsProjected = crsFactory.createFromName(name);
|
||
|
transform = ctFactory.createTransform(crsWgs84, crsProjected);
|
||
|
}
|
||
|
|
||
|
public Function<PointData, Point2D> projection() {
|
||
|
return point -> {
|
||
|
ProjCoordinate gcsPoint = new ProjCoordinate(point.getX(), point.getY());
|
||
|
ProjCoordinate pcsPoint = new ProjCoordinate();
|
||
|
pcsPoint = transform.transform(gcsPoint, pcsPoint);
|
||
|
return new Point2D(pcsPoint.x, pcsPoint.y);
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
}
|
||
| src/com/torutk/tinymap/TinyMapView.fxml | ||
|---|---|---|
|
<AnchorPane id="AnchorPane" fx:id="rootPane" prefHeight="520.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.torutk.tinymap.TinyMapViewController">
|
||
|
<children>
|
||
|
<Button fx:id="button" layoutX="241.0" layoutY="161.0" onAction="#loadShapefile" text="読み込み" AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="17.0" />
|
||
|
<Label fx:id="scaleLabel" layoutX="241.0" layoutY="14.0" minHeight="16" minWidth="69" text="1:10000000" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="14.0" />
|
||
|
<Label fx:id="scaleLabel" alignment="CENTER_RIGHT" layoutX="522.0" layoutY="14.0" minHeight="16" minWidth="69" prefHeight="17.0" prefWidth="114.0" text="1:10000000" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="14.0" />
|
||
|
<Canvas fx:id="mapCanvas" height="200.0" width="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="120.0" AnchorPane.topAnchor="0.0" />
|
||
|
<ComboBox fx:id="projectionComboBox" layoutX="239.0" layoutY="47.0" prefHeight="25.0" prefWidth="77.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="47.0" />
|
||
|
<ComboBox fx:id="projectionComboBox" layoutX="239.0" layoutY="47.0" prefHeight="25.0" prefWidth="114.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="47.0" />
|
||
|
</children>
|
||
|
</AnchorPane>
|
||
| src/com/torutk/tinymap/TinyMapViewController.java | ||
|---|---|---|
|
*/
|
||
|
package com.torutk.tinymap;
|
||
|
|
||
|
import com.torutk.tinymap.TinyMapModel.MapProjection;
|
||
|
import java.io.File;
|
||
|
import java.net.URL;
|
||
|
import java.nio.file.Paths;
|
||
|
import java.util.ResourceBundle;
|
||
|
import javafx.beans.property.DoubleProperty;
|
||
|
import javafx.beans.property.SimpleDoubleProperty;
|
||
|
import javafx.collections.FXCollections;
|
||
|
import javafx.collections.ObservableList;
|
||
|
import javafx.event.ActionEvent;
|
||
|
import javafx.fxml.FXML;
|
||
|
import javafx.fxml.Initializable;
|
||
| ... | ... | |
|
@FXML
|
||
|
private Label scaleLabel; // 縮尺表示用ラベル
|
||
|
@FXML
|
||
|
private ComboBox projectionComboBox; // 投影法選択コンボボックス
|
||
|
private ComboBox<MapProjection> projectionComboBox; // 投影法選択コンボボックス
|
||
|
@FXML
|
||
|
private Canvas mapCanvas; // 地図描画領域
|
||
|
@FXML
|
||
| ... | ... | |
|
return;
|
||
|
}
|
||
|
mapModel = new TinyMapModel(selected);
|
||
|
MapProjection mapProj = projectionComboBox.getValue();
|
||
|
if (mapProj != null) {
|
||
|
mapModel.setProjection(mapProj.projection());
|
||
|
}
|
||
|
try {
|
||
|
mapModel.loadLines();
|
||
|
} catch (TinyMapException ex) {
|
||
| ... | ... | |
|
|
||
|
@Override
|
||
|
public void initialize(URL url, ResourceBundle rb) {
|
||
|
// 投影法コンボボックス
|
||
|
ObservableList<MapProjection> list =
|
||
|
FXCollections.observableArrayList(MapProjection.values());
|
||
|
projectionComboBox.getItems().addAll(list);
|
||
|
// 実行環境でのドットピッチを計算
|
||
|
dotPitchInMeter = 1 / Screen.getPrimary().getDpi() * METER_PER_INCH;
|
||
|
// 拡大率の変更に縮尺ラベルの表示を連動
|
||
proj4Jライブラリを用いて複数の投影法を指定して地図データを読み込み表示する。