Time to make my escape

Fixed a bug from a while ago where it doesn't properly escape weird
characters in HTML. Also corrected the Kavrayskiy description and
tweaked text sizes on the supermap.
This commit is contained in:
Justin Kunimune 2018-12-22 08:33:54 -10:00
parent 74cd5aca4c
commit 2b483ac24a
3 changed files with 12 additions and 7 deletions

View File

@ -137,8 +137,13 @@ public class SVGMap implements Iterable<SVGMap.Path> {
@Override
public void characters(char[] ch, int start, int length) {
for (int i = 0; i < length; i ++)
currentFormatString += ch[start+i];
for (int i = 0; i < length; i ++) {
char c = ch[start+i];
if (c >= 128 || c == '\'' || c == '"' || c == '<' || c == '>' || c == '&') // some characters must be escaped here
currentFormatString += "&#" + (int)c + ";";
else
currentFormatString += ch[start+i];
}
}
@Override

View File

@ -95,7 +95,7 @@ public class Pseudocylindrical {
public static final Projection KAVRAYSKIY_VII = new Projection(
"Kavrayskiy VII", Math.PI*Math.sqrt(3), Math.PI, 0b1111, Type.PSEUDOCYLINDRICAL,
Property.COMPROMISE, 3, "mostly popular in the former Soviet Union") {
Property.COMPROMISE, 3, null, "mostly popular in the former Soviet Union") {
public double[] project(double lat, double lon) {
return new double[] { 1.5*lon*Math.sqrt(1/3.-Math.pow(lat/Math.PI, 2)), lat };

View File

@ -6,7 +6,7 @@ import math
from helpers import line_break, get_centroid
def plot_texts(data, label_class, source, max_rank, regulate_case=False, secondary_attr=None, force_points=False):
def plot_texts(data, label_class, source, max_rank, regulate_case=False, secondary_attr=None, force_points=False, text_size=None):
"""data from http://www.naturalearthdata.com/"""
sf = shapefile.Reader("data/{}_{}".format(source, data))
lat_idx = None
@ -39,14 +39,14 @@ def plot_texts(data, label_class, source, max_rank, regulate_case=False, seconda
label = label.upper()
if secondary_attr is not None and record[7] == 'Dependency':
label = "{} ({})".format(label, record[secd_idx]) #indicate dependencies
text_size = ['sm', 'md', 'lg', 'xl'][min(3, int(max_rank-rank))] #lower ranks get bigger text
label_size = ['sm', 'md', 'lg', 'xl'][min(3, int(max_rank-rank))] if text_size is None else text_size #lower ranks get bigger text
print('\t<text class="label-{} label-{}" x="{:.03f}" y="{:.03f}">{}</text>'.format(
label_class, text_size, 180+x, 90-y, label))
label_class, label_size, 180+x, 90-y, label))
if force_points or record[type_idx] in ['mountain', 'depression', 'pole', 'waterfall']: #add circles to the ones that need markers
print('\t<circle cx="{:.03f}" cy="{:.03f}" r="{:.03f}" />'.format(180+x, 90-y, math.sqrt(max_rank-rank+1)*0.15))
def generate_political_labels(source, max_rank=4):
plot_texts('admin_0_countries', 'pol', source, max_rank, secondary_attr='NOTE_ADM0')
plot_texts('admin_0_countries', 'pol', source, max_rank, secondary_attr='NOTE_ADM0', text_size='md')
def generate_topographical_labels(source, max_rank=2):
plot_texts('geography_regions_points', 'geo', source, max_rank)