From 500f530aaecf7d3a62c9e848cda6333d47248a46 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sat, 4 Aug 2012 22:29:35 +0200 Subject: Draft osm plugin hack to support Leaflet. --- IkiWiki/Plugin/osm.pm | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'IkiWiki/Plugin') 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!]*id="mapdiv-[^"]*"[^>]*>!g) { - if (! ($params{content}=~s!!include_javascript($params{page}).""!em)) { + if (! ($params{content}=~s!!include_javascript($params{page}).""!em)) { #" # no 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 = ''."\n". - ''."\n"; + my $code; + if (get_slippy_engine() eq 'openlayers') { + my $olurl = $config{osm_openlayers_url} || "http://www.openlayers.org/api/OpenLayers.js"; + $code = ''."\n". + ''."\n"; + } + if (get_slippy_engine() eq 'leaflet') { + my $leafurlbase = $config{osm_leaflet_url_stem} || "http://cdn.leafletjs.com/leaflet-0.6.4/leaflet"; + $code = ''."\n". + ''."\n". + ''."\n". + ''."\n"; + } if ($config{'osm_google_apikey'}) { $code .= ''; } -- cgit v1.2.3