Blame |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2014 Steve Ratcliffe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 or
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package test.svg;
import java.util.Formatter;
import java.util.List;
import uk.me.parabola.imgfmt.app.Coord;
import uk.me.parabola.imgfmt.app.trergn.Subdivision;
import org.dom4j.Element;
import test.display.CommonDisplay;
import test.elements.Line;
/**
* Convert the road layer to svg.
*
* @author Steve Ratcliffe
*/
public class Roads
extends CommonDisplay
{
private SvgDoc doc
;
private Element layer1
;
//private int citySize = 1;
//private int zipSize = 1;
protected void print
() {
openLbl
();
//if (lbl.getCities().size() > 255)
// citySize = 2;
//if (lbl.getZips().size() > 255)
// zipSize = 2;
openTre
();
openNet
();
openRgn
();
rgn.
setNetFile(net
);
drawRoads
();
}
/**
* Fetch all the roads and call out to draw each one.
*/
private void drawRoads
() {
Subdivision
[] subdivisions = tre.
subdivForLevel(0);
for (Subdivision sub : subdivisions
) {
List<Line> lines = rgn.
linesForSubdiv(sub
);
// Currently just getting all lines in range, rather than fetching the routable
// roads from net first.
for (Line line : lines
) {
if (line.
getType() < 12) {
drawRoad
(line
);
}
}
}
}
/**
* Draw an individual road to the canvas.
* @param line The line representing the road.
*/
private void drawRoad
(Line line
) {
List<Coord
> coords = line.
getCoords();
Formatter fmt =
new Formatter();
for (int i =
0; i
< coords.
size(); i++
) {
Coord c = coords.
get(i
);
XY co = doc.
coord(c.
getLatitude(), c.
getLongitude());
if (i ==
0) {
fmt.
format("M %d %d", co.
getXi(), co.
getYi());
} else {
fmt.
format(" L %d %d", co.
getXi(), co.
getYi());
}
}
String colour
;
switch (line.
getType()) {
case 1: colour =
"blue"; break;
case 2: colour =
"green"; break;
case 3: colour =
"red"; break;
default: colour =
"black"; break;
}
layer1.
addElement("path")
.
addAttribute("stroke", colour
)
.
addAttribute("opacity",
"0.3")
.
addAttribute("fill",
"none")
.
addAttribute("d", fmt.
toString());
}
public void run
(SvgDoc doc,
String name
) {
this.
doc = doc
;
this.
layer1 = doc.
getRoads();
this.
setOutStream(System.
err);
this.
display(name,
"NOD");
}
}