DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:maplink

maplink Plugin

Compatible with DokuWiki

  • 2020-07-29 "Hogfather" yes
  • 2018-04-22 "Greebo" unknown
  • 2017-02-19 "Frusterick Manners" unknown
  • 2016-06-26 "Elenor Of Tsort" unknown

plugin Links an address or other search text directly to Google maps

Last updated on
2021-05-01
Provides
Syntax

Similar to anchor, googlemaps3

Tagged with links, maps

By chlw

This plugin links an address or any other string directly to Google maps. This can be helpful if you want to provide a link to Google maps without embedding the map.

This plugin is based on the Plugins anchor and iCalendar. I just took parts of those plugins an merged them together. So all the kudos go to those authors!

Installation

This plugin is very simple (contains only one file) and I'm not familiar with the repository-stuff (git etc.). Therefore I'm just going to include the source code here as well (e.g. in case the link to the download is broken etc.).

The following code should be copied in the file “lib/plugins/maplink/syntax.php”, that means:

  1. Create a directory “maplink” in the “/lib/plugins”-Directory of your Dokuwiki Installation
  2. Create a file containing the code below and name it “syntax.php”
  3. Put this file in the directory, you created in step 1 (lib/plugins/maplink/)
lib/plugins/maplink/syntax.php
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');  
 
class syntax_plugin_maplink extends DokuWiki_Syntax_Plugin {
    function getType() {return 'substition';}
    function getPType() {return 'block';}
    function getSort() {return 167;}
    function getInfo() {return array('author' => 'chlw; based on work by Eli Fenton (Anchor Plugin) and J. Drost-Tenfelde (iCalendar Plugin)', 'name' => 'maplink', 'url' => 'http://dokuwiki.org/plugin:maplink');}
    function connectTo($mode){
        $this->Lexer->addSpecialPattern('\{\{maplink:[^}]*\}\}', $mode, 'plugin_maplink');
    }
 
    function handle($match, $state, $pos, Doku_Handler $handler) {
        return explode(':', substr($match, strlen('{{maplink:'), -2));
    }
 
    function render($format, Doku_Renderer $renderer, $data) {
        $renderer->doc .= '<a href="http://maps.google.com/maps?q='.str_replace(' ', '+', str_replace(',', ' ', $data[0])). '"target="_blank">' .htmlspecialchars($data[1]) . '</a>';
    }
}

You might want to delete the code

"target="_blank"

if the map should open in the same window.

Examples/Usage

Here's how you create a link:

{{maplink:string_to_search:text_to_display}}

The string_to_search part is what Google maps should search for (can be an address or any other string, see examples below). The text_to_display part is what the user sees as the clickable text.

Examples

The following code genereates a clickable link with text:

{{maplink:15010 NE 36th Street, Microsoft Campus, Redmond, WA 98052:This is a link to the Microsoft Visitor Center}}



The same link with the address as text:

{{maplink:15010 NE 36th Street, Microsoft Campus, Redmond, WA 98052:15010 NE 36th Street, Microsoft Campus, Redmond, WA 98052}}



You might want to search for other strings (e.g. names of places, hotels, attractions etc.) than plain addresses:

{{maplink:The Peninsula Hotel, Bangkok:Five Star Hotel in Thailand}}



Tip: You might want to include the words “route planner, Routenplaner, Anfahrt” or similar in your language in your search. Depending on your actual position Google Maps opens directly in the route planner mode (which is a bit scary… ;-):

{{maplink:The Peninsula Hotel route planner, Bangkok:Five Star Hotel in Thailand}}



Screenshots

Link in Action

Example Code




Configuration and Settings

The plugin has no configuration or settings. You might want to delete the code

"target="_blank"

if you want the map to open in the same window (instead of a new one).

Development

This is my first plugin and I'm not really familiar with programming, so I'm quite sure someone can improve it.

Change Log

  • 2021-05-01
    • Release 2.0: Made some code changes to work with Dokuwiki Release “Hogfather”. Still not really familiar with programming…
  • 2013-12-26
    • Initial release

Known Bugs and Issues

None, so far.

ToDo / Wish List / Questions

  • Could this be coded in a more clever way?
  • Does this code really cover all possible cases? I tried it with some Thai text and, no surprise, it did not work.
  • The link does not appear on the same line but on a separate next line / paragraph if you have a code like:
    Location of the fiesta: {{maplink:Playa del Sol Hotel Cancun Mexico:Playa del Sol -- my favourite place}}

    Any hints on that…?

Discussion

Please discuss the plugin here.

plugin/maplink.txt · Last modified: 2021-05-02 00:13 by chlw