aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2015-02-28 15:08:57 +0000
committerChristopher Baines <mail@cbaines.net>2017-10-31 20:32:45 +0000
commitce42bcaad90b9c445abf16d1aeaecbd837f86054 (patch)
treed98d8f3e87a14736faa42eebe56aa015722fc4d3
parent32592cf4f72fb8187904364d8c15e783dedc9c33 (diff)
downloadikiwiki-ce42bcaad90b9c445abf16d1aeaecbd837f86054.tar
ikiwiki-ce42bcaad90b9c445abf16d1aeaecbd837f86054.tar.gz
Icon related fixes in the OSM pluginosm-icon-fixes-rebased
- Use the icon parameter to the waypoint directive - Fix the KML output to handle different icons for waypoints with the same tag. This might cause breakage in wiki's using Ikiwiki if they were depending on the existing style format
-rw-r--r--IkiWiki/Plugin/osm.pm74
-rw-r--r--underlays/osm/ikiwiki/osm.js6
2 files changed, 56 insertions, 24 deletions
diff --git a/IkiWiki/Plugin/osm.pm b/IkiWiki/Plugin/osm.pm
index 33e2e0d4d..eb1bc0882 100644
--- a/IkiWiki/Plugin/osm.pm
+++ b/IkiWiki/Plugin/osm.pm
@@ -177,9 +177,10 @@ sub process_waypoint {
my $name = scrub($params{'name'} || $p, $page, $dest); # sanitized here
my $desc = scrub($params{'desc'} || '', $page, $dest); # sanitized here
my $zoom = scrub($params{'zoom'} // $config{'osm_default_zoom'} // 15, $page, $dest); # sanitized below
- my $icon = $config{'osm_default_icon'} || "ikiwiki/images/osm.png"; # sanitized: we trust $config
+ my $icon = $params{'icon'}; # not sanitized?
my $map = scrub($params{'map'} || 'map', $page, $dest); # sanitized here
my $alt = $config{'osm_alt'} ? "alt=\"$config{'osm_alt'}\"" : ''; # sanitized: we trust $config
+ my $tag = $params{'tag'};
if ($zoom !~ /^\d\d?$/ || $zoom < 2 || $zoom > 18) {
error("Bad zoom");
}
@@ -189,20 +190,28 @@ sub process_waypoint {
error("Must specify lat and lon");
}
- my $tag = $params{'tag'};
- foreach my $t (keys %{$typedlinks{$page}{'tag'}}) {
- if ($icon = get_tag_icon($t)) {
- $tag = $t;
- last;
- }
- $t =~ s!/$config{'tagbase'}/!!;
- if ($icon = get_tag_icon($t)) {
- $tag = $t;
- last;
+ unless ($icon) {
+ foreach my $t (keys %{$typedlinks{$page}{'tag'}}) {
+ if ($icon = get_tag_icon($t)) {
+ $tag = $t;
+ last;
+ }
+ $t =~ s!/$config{'tagbase'}/!!;
+ if ($icon = get_tag_icon($t)) {
+ $tag = $t;
+ last;
+ }
}
}
+
+ # Use the default icon, if none has been given
+ $icon = $icon || $config{'osm_default_icon'} || "ikiwiki/images/osm.png";
+
$icon = urlto($icon, $dest, 1);
$icon =~ s!/*$!!; # hack - urlto shouldn't be appending a slash in the first place
+
+ add_depends($params{page}, $icon);
+
$tag = '' unless $tag;
register_rendered_files($map, $page, $dest);
$pagestate{$page}{'osm'}{$map}{'waypoints'}{$name} = {
@@ -242,8 +251,10 @@ sub process_waypoint {
sub get_tag_icon($) {
my $tag = shift;
# look for an icon attached to the tag
- my $attached = $tag . '/' . $config{'osm_tag_default_icon'};
- if (srcfile($attached)) {
+ my $attached = $tag . '/' . ($config{'osm_tag_default_icon'} || "icon.png");
+ # Try and find the icon, second argument indicates to return undef if it cannot be found
+ if (srcfile($attached, 1)) {
+
return $attached;
}
else {
@@ -379,14 +390,28 @@ sub writekml($;$) {
$writer->startTag("kml", "xmlns" => "http://www.opengis.net/kml/2.2");
$writer->startTag("Document");
- # first pass: get the icons
- my %tags_map = (); # keep track of tags seen
+ # Each waypoint has an icon, this is set in process_waypoint, as the
+ # kml output has styles, there must be one for each icon, such that the
+ # placemarks using that icon can have that style.
+
+ # Used to generate unique names for each style
+ my $iconNum = 0;
+ # Maps the name of the style (id) to the icon
+ # This is used to determine if a new style is needed
+ my %iconStyle = ();
+ # Maps each waypoint to the style, used below
+ my %waypointStyle = ();
+
+ # first pass: compute the styles
foreach my $name (keys %{$waypoints{$map}}) {
my %options = %{$waypoints{$map}{$name}};
- if (!$tags_map{$options{tag}}) {
- debug("found new style " . $options{tag});
- $tags_map{$options{tag}} = ();
- $writer->startTag("Style", id => $options{tag});
+
+ # Find the style by the tag
+ my $style = $iconStyle{$options{icon}};
+ unless ($style) {
+ $style = $style = "_icon" . ($iconNum++);
+
+ $writer->startTag("Style", id => $style);
$writer->startTag("IconStyle");
$writer->startTag("Icon");
$writer->startTag("href");
@@ -395,10 +420,13 @@ sub writekml($;$) {
$writer->endTag();
$writer->endTag();
$writer->endTag();
- }
- $tags_map{$options{tag}}{$name} = \%options;
+
+ # Add this style to the hash
+ $iconStyle{$options{'icon'}} = $style;
+ }
+ $waypointStyle{$name} = $style;
}
-
+
foreach my $name (keys %{$waypoints{$map}}) {
my %options = %{$waypoints{$map}{$name}};
$writer->startTag("Placemark");
@@ -406,7 +434,7 @@ sub writekml($;$) {
$writer->characters($name);
$writer->endTag();
$writer->startTag("styleUrl");
- $writer->characters('#' . $options{tag});
+ $writer->characters('#' . $waypointStyle{$name});
$writer->endTag();
#$writer->emptyTag('atom:link', href => $options{href});
# to make it easier for us as the atom:link parameter is
diff --git a/underlays/osm/ikiwiki/osm.js b/underlays/osm/ikiwiki/osm.js
index 37e588f7b..fe10b5ad2 100644
--- a/underlays/osm/ikiwiki/osm.js
+++ b/underlays/osm/ikiwiki/osm.js
@@ -86,7 +86,11 @@ function mapsetup(divname, options) {
format: new OpenLayers.Format.GeoJSON()
}),
strategies: [new OpenLayers.Strategy.Fixed()],
- projection: new OpenLayers.Projection("EPSG:4326")
+ projection: new OpenLayers.Projection("EPSG:4326"),
+ styleMap: new OpenLayers.StyleMap({
+ pointRadius: 16,
+ externalGraphic: "${icon}"
+ })
});
} else {
pois = new OpenLayers.Layer.Vector("KML", {