Jump to content

Module: Leaflet Map


Recommended Posts

and on the frontend my map is ghost;

	$modUrl = wire('config')->urls->siteModules.'MarkupLeafletMap/';
	$styles = array_merge($styles, [
		"leaflet" => "https://unpkg.com/leaflet@1.0.3/dist/leaflet.css",
		"leaflet-markercluster" => "{$modUrl}assets/leaflet-markercluster/MarkerCluster.css",
	$scriptsH = array_merge($scriptsH, [
		"leaflet" => "https://unpkg.com/leaflet@1.0.3/dist/leaflet.js",
		"leaflet-providers" => "{$modUrl}assets/leaflet-providers/leaflet-providers.js",
		"geocoder" => "{$modUrl}Control.Geocoder.js",

$map = $modules->get('MarkupLeafletMap');
$content .= $map->render($page, 'geolocation', ['height' => '500px']);

returns visibly blank

<div id="mleafletmap1" class="MarkupLeafletMap" style="width: 100%; height: 500px;"></div>


Link to comment
Share on other sites

On 9/1/2017 at 2:40 PM, Beluga said:

With the newest module version, PW 3, Leaflet 1.2, I get this:

jQuery.Deferred exception: L.tileLayer.provider is not a function jsMarkupLeafletMap


Did they change something again?

Turns out I had to add this script:

<script src="https://unpkg.com/leaflet-providers@1.1.17/leaflet-providers.js"></script>

Now the maps appear. Yet, the markers do not.

Link to comment
Share on other sites

On 9/7/2017 at 5:29 PM, Beluga said:

Now the maps appear. Yet, the markers do not.

Another missing script (when I checked the JS console):

<script src="https://unpkg.com/drmonty-leaflet-awesome-markers@2.0.2/js/leaflet.awesome-markers.js"></script>

Now the markers appear in a map with multiple markers, but not in maps with a single marker. The console shows no error.

Edit: I added a watcher to line 57 in MarkupLeafletMap.js (this.addMarker = function(lat, lng, url, title, extra) {) and stepped forward. The marker variable stayed blank.

Link to comment
Share on other sites

  • 1 month later...

Bit of an issue with this module. I'm on PW 3.0.62, in the upgrades page it's showing that I have version 2.8.1 of the module and that there is a newer version to install. When I go through the update process it still says the exact same thing. Maps on the front end are also no longer working. Is this a known issue?

Link to comment
Share on other sites


I have version MarkupLeaflet 3.0.2. I finally succeded to get the map on frontend (see my previous post). However, the marker still doesn't show up. It works on backend but not frontend. It works *before*, but I don't know what cause this disparition.

Upgrading leaflet version from 0.7.7 to 1.2.0 results to a no-map, so I kept 0.7.7 for now.



Link to comment
Share on other sites

6 hours ago, mel47 said:

Upgrading leaflet version from 0.7.7 to 1.2.0 results to a no-map, so I kept 0.7.7 for now.

See my previous comments regarding Leaflet 1.2.0. It needs some scripts included separately now, but there is still some mystery to be solved in the case of "single marker in map".

Link to comment
Share on other sites

  • 2 weeks later...

I'm currently developing a site using this module and I've struck a couple of issues that I'm stuck on.


I have a page showing office locations and I have it set up so that each office is a repeater including a Leaflet map using this module. In the back-end the map tiles don't display properly and in the front-end only the second item's map displays.


I have a map that displays multiple markers for scientific studies around the world. For this I have it set up so each trial is a child of the map page. All the markers get displayed correctly but I can't get the popup to display correctly. After every paragraph and between every list item it's adding a <br/> tag which spaces everything out too much. Also I'd like to remove the link to the child page on the title, however any attempt I've made so far has made it so the popup won't open. Any help with these two issues would be greatly appreciated.


I managed to remove the <br/> tags by modifying line 252 in MarkupLeafletMap.module from

$popup = str_replace("\n", '<br />', $popup); 


$popup = str_replace("\n", '', $popup);

And removed the title link by modifying a line in MarkupLeafletMap.js from

marker.bindPopup("<b><a href='" + marker.linkURL + "'>" + title + "</a></b>" + extra);


marker.bindPopup("<h4>" + title + "</h4>" + extra);


Edited by houseofdeadleg
Solved part of the issue
Link to comment
Share on other sites

  • 3 weeks later...


I am trying to get a full map with different marker colors. I use the following code (based on the documentation on the github page). But they keep being the standard blue.

<?php $items = $pages->find("template=population"); ?>
$options = array(
    'markerFormatter' => function($page, $marker_options) {
        $marker_options['markerColour'] = $page->subspecie->population_color_name;
        return $marker_options;
); ?>

<?php echo $map->render($items, 'location', $options); ?>


for a single page with template population I got it working. That is the code below.

<?php echo $page->subspecie->title; ?>
    <?php //$map = wire('modules')->get('MarkupLeafletMap'); ?>
    <?php $iconColor = $page->subspecie->population_color_name; ?>
    <?php echo $iconColor; ?>
    <?php echo $map->render($page, 'location', array('height' => '500px','markerColour' => $iconColor)); ?>

Just not for the page with all populations. What I am doing wrong?


Link to comment
Share on other sites

  • 2 weeks later...

Does this module use Google's API at some point in the geocoding process? I noticed that there are calls to:


...in LeafletMapMarker.php, and calls to...


...in Control.Geocoder.js.

I am using this Fieldtype on individual Events pages - it works well and made sense. I'm now trying to go back and add JSON+LD to all of those Events pages which requires a "Place" value (Example: https://developers.google.com/search/docs/data-types/events). Unfortunately the auto-corrected address field from the geocoder ($this->address in Leaflet) is not always something I can easily split into meaningful entities for the JSON+LD Event type's @Place type values. That said, the raw results originally returned from either geocoder (Google's being nicer in this regard, but OSM works too) can be used towards building this out.

Based on how this module handles all of its data, is it feasible to extend it somehow to allow saving of the raw geocode data? If so, any ideas on where I might begin to look?

Link to comment
Share on other sites

@BrendonKoz The JS side of this module is using the OSM geocoder while the geocode() method in LeafletMapMarker.php is using the Google geocoder.

If you wanted to save the raw data returned by Google geocoder, you would need to extend the database schema in FieldtypeLeafletMapMarker.module to add the necessary columns (e.g. streetAddress) to the table where data for this fieldtype ist stored. And extend the geocode method so it can save the raw data to the newly added columns. And add the respective keys to the construct method in LeafletMapMarker.php.

Then you should be able to access your values in your template php like:

$map = $modules->get('MarkupLeafletMap');
echo $map->streetAddress;

and use those values to render the JSON+LD JS.

You would either need to fork the original module and then add your code or write your own module that extends the original one and adds your methods.



  • Thanks 1
Link to comment
Share on other sites

I realize my question is now outside the scope of this module, so I apologize in advance, and also have no expectation of a response -- just hopeful! By looking through this though I think I might be picking up some things with Fieldtype development that I couldn't quite grasp beforehand, so it's still useful (to me).

Thank you for the response, @gebeer that was awesome! I made those, and some additional changes, but I've still been unable to get the data to save to the database (I'm instead saving an empty string value). I believe I might need some additional code somewhere, possibly in InputfieldLeafletMapMarker.module's ___processInput method? I tried commenting out the if/else block for whether a JS geocode had been done so that it would (should?) always perform a Google geocode, but that still didn't save to the DB. Any thoughts from anyone on what I might be missing here? I manually altered the database table to include the "raw" column in my field_{$name} field values.

Changes (on Github repo removed) :
[line 38] + $this->set('raw', '');
[line 96] + $this->raw = $json['results'][0];

[line 310] - "\$page->{$this->name}->zoom" .
+ "\$page->{$this->name}->zoom\n" .
+ "\$page->{$this->name}->raw" .

[line 106] + $marker->raw = $value['raw'];
[line 136] - 'zoom' => $marker->zoom/*,
+ 'zoom' => $marker->zoom,
+ 'raw' => $marker->raw/*,

[line 157] + $schema['raw'] = "TEXT"; // raw google geocode data

Link to comment
Share on other sites

  • 1 month later...

Sorry, should have given more details about my trials. I unfortunately have no experience with programming modules for processwire so I would need some more hints to fix it.

The problem is that the value does not get stored into the database. (I tested it by putting a fixed string there.) The reason for this I suppose is that InputfieldLeafletMapMarker.module requires an input field in the __render function in order for processwire to store it, when the page is saved. My problem now was to get this field dynamically populated by the javascript part of the module, i.e. add appropriate code to InputfieldLeafletMapMarker.js.

That's were I currently stand.

Link to comment
Share on other sites

13 hours ago, gebeer said:

@BrendonKoz Have you checked with some debug tool (I highly recommend Tracy Debugger Module) that $json['results'][0] has a value?

I hadn't. I had previously installed TracyDebugger and couldn't figure out how to use it -- I think my problem was as simple as having installed it in the wrong PW instance (it's working now). I'll see if I can find any additional info from that, thank you for the tip!

18 hours ago, patman said:


@BrendonKoz I ran into the same issue that I would like to use the json data returned to populate json+ld structures. Did you ever find a solution? I played around with your code from github but couldn't fix it.


I had not, unfortunately. I was pulled from that task to work on an Omeka (archival CMS of sorts) theme and subsequent issues, and an application form using GIS shapefiles. I hope to be finishing the Omeka thing up today. If I have time later in the day I'll take another look into this. I too don't have much experience working with PW Fieldset modules; I've been trying to figure them out here and there though.

Link to comment
Share on other sites

I did some deeper looks into the code, it seems that a few things are already prepared / were used previously:
InputfieldLeafletMapMarker.js already contains a variable $addrJS that could store raw json.
InputfieldLeafletMapMarker.module renders a hidden field _js_geocode_address that looks like intended for that purpose but it's coded wrong (id, no value).

My thought is to use these variables to store the raw json and generate the currently used "address" out of them (by simple extraction of the name). Then I would store the raw value into the database field "data" so there is no need to update the scheme with an extra field "raw". Original field address can again be regenerated from the raw json anyway.

I might have some time on the weekend to go deeper. Let me know if you have some more ideas/hints. I'd like to have the possibility to generate the json+ld for the website automatically.

Link to comment
Share on other sites

If the only JSON+LD to be displayed will be event type, I'm personally planning to just hardcode it into the template rather than run another module. I did install that module originally with that intention but it mostly just attempts to simplify the creation of the template code.

My `raw` field was used so that the rest of the module's code would be untouched and would continue to run as-is. If I could get it working I'd then add a module config option to offer to always save the raw data (or leave unchecked to not save it; default behavior). That way if the module author wanted to merge changes it wouldn't have any breaking changes. The schema upgrade method would have to be updated though.

I didn't notice the other variables that may have worked before -- or maybe I did; if I did, they might've been a carry-over from the fork of Ryan Cramer's GoogleMaps implementation (some code is still the same). I didn't get time to look at this today so the code is no longer fresh in my memory.

Link to comment
Share on other sites

4 hours ago, patman said:

InputfieldLeafletMapMarker.js already contains a variable $addrJS that could store raw json.
InputfieldLeafletMapMarker.module renders a hidden field _js_geocode_address that looks like intended for that purpose but it's coded wrong (id, no value).

My thought is to use these variables to store the raw json and generate the currently used "address" out of them (by simple extraction of the name). Then I would store the raw value into the database field "data" so there is no need to update the scheme with an extra field "raw". Original field address can again be regenerated from the raw json anyway.

_js_geocode_address is used to hold the address that gets returned by the JS geocoding call, thats why the value is not set when rendering the field. This address is then stored to the data field in the DB on save. If you want to store the raw data in that data field, you also would need to change the schema, because it currently allows a max of 255 characters which will not be enough to store all the raw data.

When you then retrieve the address in your template with $page->mylocationfieldname->address, it will return the raw data that you stored in that field. So you would need to extend the get method in LeafletMapMarker.php to return only the address and not the whole string.

I think it would make more sense to extend the DB scheme and have a field raw that stores the raw data.

You'd need a hidden field in the form, e.g. _js_geocode_raw that gets populated from the JS (just like the address field gets populated now) and then on save sends that value and stores it to the DB. You'd need to add that to the set method in LeafletMapMarker.php.

  • Like 1
Link to comment
Share on other sites

On 9.1.2018 at 10:44 PM, gmclelland said:

@patman  I too, would like to be able to use the address data with JSON-ld.  In case you haven't already tried it, you might want to give https://github.com/clipmagic/MarkupJsonLDSchema a shot for the JSON-ld.

@gmclelland Thanks I stumbled over it and had a quick look at it. Unfortunately, I decided to include my own php file that renders the schemata because I oversaw the customization options in that module. I'll switch at some later time, thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.

      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

    • By tcnet
      Session Viewer is a module for ProcessWire to list session files and display session data. This module is helpful to display the session data of a specific session or to kick out a logged in user by simply delete his session file. After installation the module is available in the Setup menu.

      The following conditions must be met for the module to work properly:
      Session files
      Session data must be stored in session files, which is the default way in ProcessWire. Sessions stored in the database are not supported by this module. The path to the directory where the session files are stored must be declared in the ProcessWire configuration which is by default: site/assets/sessions.
      Serialize handler
      In order to transform session data easier back to a PHP array, the session data is stored serialized. PHP offers a way to declare a custom serialize handler. This module supports only the default serialize handlers: php, php_binary and php_serialize. WDDX was dropped in PHP 7.4.0 and is therefore not supported by this module as well as any other custom serialize handler. Which serialize handler is actually used you can find out in the module configuration which is available under Modules=>Configure=>SessionViewer.

      Session data
      The session data can be displayed in two different ways. PHP's default output for arrays print_r() or by default for this module nice_r() offered on github: https://github.com/uuf6429/nice_r. There is a setting in the module configuration if someone prefers print_r(). Apart from the better handling and overview of the folded session data the output of nice_r() looks indeed nicer.

      ProcessWire module directory
    • By Robin S
      Repeater Easy Sort
      Adds a compact "easy-sort" mode to Repeater and Repeater Matrix, making those fields easier to sort when there are a large number of items.
      The module also enhances Repeater Matrix by allowing a colour to be set for each matrix type. This colour is used in the item headers and in the "add new" links, to help visually distinguish different matrix types in the inputfield.
      A Repeater field

      A Repeater Matrix field with custom header colours

      Easy-sort mode
      Each Repeater/Matrix item gets an double-arrow icon in the item header. Click this icon to enter easy-sort mode.
      While in easy-sort mode:
      The items will reduce in width so that more items can be shown on the screen at once. The minimum width is configurable in the field settings. Any items that were in an open state are collapsed, but when you exit easy-sort mode the previously open items will be reopened. You can drag an item left/right/up/down to sort it within the items. The item that you clicked the icon for is shown with a black background. This makes it easier to find the item you want to move in easy-sort mode. You can click an item header to open the item. An "Exit easy-sort mode" button appears at the bottom of the inputfield. Configuration
      In the field settings for Repeater and Repeater Matrix fields you can define a minimum width in pixels for items in easy-sort mode. While in easy-sort mode the items will be sized to neatly fill the available width on any screen size but will never be narrower than the width you set here.
      In the field settings for Repeater Matrix you can define a custom header colour for each matrix type using an HTML "color" type input. The default colour for this type of input is black, so when black is selected in the input it means that no custom colour will be applied to the header.
      The easy-sort mode is only possible on Repeater/Matrix fields that do not use the "item depth" option.
  • Create New...