summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2012-08-04 22:29:35 +0200
committerJonas Smedegaard <dr@jones.dk>2013-10-28 01:14:14 +0100
commit500f530aaecf7d3a62c9e848cda6333d47248a46 (patch)
tree42026b252e1ae40cedc7a9ae175a8426af3294bf /IkiWiki
parent0ad5b658cb0b6b1fe875edc59788a72a22377150 (diff)
Draft osm plugin hack to support Leaflet.
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/osm.pm50
1 files changed, 45 insertions, 5 deletions
diff --git a/IkiWiki/Plugin/osm.pm b/IkiWiki/Plugin/osm.pm
index c9650d0..c7078ca 100644
--- a/IkiWiki/Plugin/osm.pm
+++ b/IkiWiki/Plugin/osm.pm
@@ -67,6 +67,13 @@ sub getsetup () {
safe => 0,
rebuild => 1,
},
+ osm_leaflet_url_stem => {
+ type => "string",
+ example => "http://cdn.leafletjs.com/leaflet-0.6.4/leaflet",
+ description => "Url used as stem for the Leaflet files",
+ safe => 0,
+ rebuild => 1,
+ },
osm_layers => {
type => "string",
example => { 'OSM', 'GoogleSatellite' },
@@ -81,6 +88,13 @@ sub getsetup () {
safe => 1,
rebuild => 1,
},
+ osm_slippy_engine => {
+ type => "string",
+ example => "openlayers",
+ description => "the slippy map engine to use, can be openlayers or leaflet (leaflet always uses GeoJSON, disregarding osm_format)",
+ safe => 0,
+ rebuild => 1,
+ },
}
sub register_rendered_files {
@@ -472,7 +486,7 @@ sub format (@) {
my %params=@_;
if ($params{content}=~m!<div[^>]*id="mapdiv-[^"]*"[^>]*>!g) {
- if (! ($params{content}=~s!</body>!include_javascript($params{page})."</body>"!em)) {
+ if (! ($params{content}=~s!</body>!include_javascript($params{page})."</body>"!em)) { #"
# no <body> tag, probably in preview mode
$params{content}=$params{content} . include_javascript($params{page});
}
@@ -481,6 +495,9 @@ sub format (@) {
}
sub preferred_format() {
+ if (get_slippy_engine() eq 'leaflet') {
+ $config{'osm_format'} = 'GeoJSON';
+ }
if (!defined($config{'osm_format'}) || !$config{'osm_format'}) {
$config{'osm_format'} = 'KML';
}
@@ -489,12 +506,22 @@ sub preferred_format() {
}
sub get_formats() {
+ if (get_slippy_engine() eq 'leaflet') {
+ $config{'osm_format'} = 'GeoJSON';
+ }
if (!defined($config{'osm_format'}) || !$config{'osm_format'}) {
$config{'osm_format'} = 'KML';
}
map { $_ => 1 } split(/, */, $config{'osm_format'});
}
+sub get_slippy_engine() {
+ if (!defined($config{'osm_slippy_engine'}) || !$config{'osm_slippy_engine'}) {
+ $config{'osm_slippy_engine'} = 'openlayers';
+ }
+ return $config{'osm_slippy_engine'};
+}
+
sub include_javascript ($) {
my $page=shift;
my $loader;
@@ -551,10 +578,23 @@ sub cgi($) {
sub embed_map_code(;$) {
my $page=shift;
- my $olurl = $config{osm_openlayers_url} || "http://www.openlayers.org/api/OpenLayers.js";
- my $code = '<script src="'.$olurl.'" type="text/javascript" charset="utf-8"></script>'."\n".
- '<script src="'.urlto("ikiwiki/osm.js", $page).
- '" type="text/javascript" charset="utf-8"></script>'."\n";
+ my $code;
+ if (get_slippy_engine() eq 'openlayers') {
+ my $olurl = $config{osm_openlayers_url} || "http://www.openlayers.org/api/OpenLayers.js";
+ $code = '<script src="'.$olurl.'" type="text/javascript" charset="utf-8"></script>'."\n".
+ '<script src="'.urlto("ikiwiki/osm.js", $page).
+ '" type="text/javascript" charset="utf-8"></script>'."\n";
+ }
+ if (get_slippy_engine() eq 'leaflet') {
+ my $leafurlbase = $config{osm_leaflet_url_stem} || "http://cdn.leafletjs.com/leaflet-0.6.4/leaflet";
+ $code = '<link href="'.$leafurlbase.'.css" rel="stylesheet" type="text/css">'."\n".
+ '<!--[if lte IE 8]>'."\n".
+ '<link href="'.$leafurlbase.'.ie.css" rel="stylesheet" type="text/css">'."\n".
+ '<![endif]-->'."\n".
+ '<script src="'.$leafurlbase.'.js" type="text/javascript" charset="utf-8"></script>'."\n".
+ '<script src="'.urlto("ikiwiki/leaflet.js", $page).
+ '" type="text/javascript" charset="utf-8"></script>'."\n";
+ }
if ($config{'osm_google_apikey'}) {
$code .= '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='.$config{'osm_google_apikey'}.'&sensor=false" type="text/javascript" charset="utf-8"></script>';
}