+ 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>';
+ }
+ return $code;
+}
+
+sub map_setup_code($;@) {
+ my $map=shift;
+ my $name=shift;
+ my %options=@_;
+
+ my $mapurl = $config{osm_map_url};
+
+ eval q{use JSON};
+ error $@ if $@;
+
+ $options{'format'} = preferred_format();
+
+ my %formats = get_formats();
+ if ($formats{'GeoJSON'}) {
+ $options{'jsonurl'} = urlto($map."/pois.json");
+ }
+ if ($formats{'CSV'}) {
+ $options{'csvurl'} = urlto($map."/pois.txt");
+ }
+ if ($formats{'KML'}) {
+ $options{'kmlurl'} = urlto($map."/pois.kml");
+ }
+
+ if ($mapurl) {
+ $options{'mapurl'} = $mapurl;
+ }
+ $options{'layers'} = $config{osm_layers};
+
+ $name=~s/'//g; # $name comes from user input
+ return "mapsetup('mapdiv-$name', " . to_json(\%options) . ");";