diff options
author | Jonas Smedegaard <dr@jones.dk> | 2012-08-04 22:29:35 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2021-03-24 23:17:59 +0100 |
commit | e786bc689f664d818b61a51a98db7f0c61ef6aa4 (patch) | |
tree | 6db26ff84d99233aa5710c4416f312509282b97b | |
parent | 40bc840da8ce60cb49e6545211d96ecb150451ce (diff) |
extend plugin osm, to support Leaflet [draft]
-rw-r--r-- | IkiWiki/Plugin/osm.pm | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/IkiWiki/Plugin/osm.pm b/IkiWiki/Plugin/osm.pm index 27db31a..d1d0691 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&v=2&key='.$config{'osm_google_apikey'}.'&sensor=false" type="text/javascript" charset="utf-8"></script>'; } |