Mats

Module: Leaflet Map

Recommended Posts

I'm in PW 3.0.42 and in the page editor the entire fieldset is disabled, can't click on it, no map (just gray with +- zoom buttons).

Share this post


Link to post
Share on other sites
24 minutes ago, Mats said:

@hellomoto Hi! Do you get any console errors?

 

Nope! When there's a value input the map appears dutifully marked, however the Address input is still disabled, and clicking on it opens a search input within the map. 

Share this post


Link to post
Share on other sites

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>

:mellow:

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Hi

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.

Thanks

 

Share this post


Link to post
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".

Share this post


Link to post
Share on other sites

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

Firstly:

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.

Secondly:

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.

Update:

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

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

to

$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);

to

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

 

Edited by houseofdeadleg
Solved part of the issue

Share this post


Link to post
Share on other sites

Hello,

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"); ?>
<?php
$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?

 

Share this post


Link to post
Share on other sites

@webhoes Can you try changing to the following and see if that sorts it out...

// from this...
$marker_options['markerColour'] = $page->subspecie->population_color_name;

// to this...
$marker_options['markerColor'] = $page->subspecie->population_color_name;

 

Share this post


Link to post
Share on other sites

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

http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=

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

http://nominatim.openstreetmap.org

...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?

Share this post


Link to post
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

Share this post


Link to post
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) :
LeafletMapMarker.php
[line 38] + $this->set('raw', '');
[line 96] + $this->raw = $json['results'][0];

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

FieldtypeLeafletMapMarker.module
[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

Share this post


Link to post
Share on other sites

Hi!

@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.

Thanks!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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:

Hi!

@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.

Thanks!

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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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!

Share this post


Link to post
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 anderson
      Hi all,
      I'm a new to website building. Learned some CRASH course of js,jquery,php. Then I found CMS. Still learning around forum, youtube....
      Anyway, please help me with some beginer questions:
      1, About template - please correct me if I understand wrong : every page should be (or recommended) built on a template. So if in total I'll have 10 pages, 2 of them have same layout, I'll need 9 templates.  And, what fields a page includes, is not defined in page, but defined in the template that page uses. 
      2,  Where to see what modules I've installed? is it in "Modules - Site"? 
      3, I installed "PageTable Extended", then what?  As in a youtube tutorial, it should appear in Setup tab, but it doesn't.  What's in there: templates,fields,logs,comments. (I installed "Uikit 3 site_blog profile".)
      4, I did a search in Processwire website for the famous "repeater matrix" module, and can not find it, there's a Repeater, as well as a Matrix. Is it not a module?
      5, I watched this youtube tuts: https://www.youtube.com/watch?v=IHqnLQy9R1A
      Anybody familiar with this tuts please help: 
      After he analysed a target webpage layout he wanted to mimic, he created some fields, some template, then based on those he created a page and input some "content" in there, then clicked "view", it's just some text. So, here comes my question, he copied a folder "assets" (subfolders are: css,fonts,js,img) over, then the page have the appearance/layout he wanted to mimic. Where does that assets folder come from?
      Appreciate any help.
    • By mtwebit
      I've created a set of modules for importing (manipulating and displaying) data from external resources. A key requirement was to handle large (100k+) number of pages easily.
      Main features
      import data from CSV and XML sources in the background (using Tasker) purge, update or overwrite existing pages using selectors user configurable input <-> field mappings on-the-fly data conversion and composition (e.g. joining CSV columns into a single field) download external resources (files, images) during import handle page references by any (even numeric) fields How it works
      You can upload CSV or XML files to DataSet pages and specify import rules in their description.
      The module imports the content of the file and creates/updates child pages automatically.
      How to use it
      Create a DataSet page that stores the source file. The file's description field specifies how the import should be done:
      After saving the DataSet page an import button should appear below the file description.

      When you start the import the DataSet module creates a task (executed by Tasker) that will import the data in the background.
      You can monitor its execution and check its logs for errors.

      See the module's wiki for more details.
      The module was already used in three projects to import and handle large XML and CSV datasets. It has some rough edges and I'm sure it needs improvement so comments are welcome.
    • By dreerr
      TemplateEnginePug (formally TemplateEngineJade)
       
      This module adds Pug templates to the TemplateEngineFactory. It uses https://github.com/pug-php/pug to render templates.
      doctype html html(lang='en') head meta(http-equiv='content-type', content='text/html; charset=utf-8') title= $page->title link(rel='stylesheet', type='text/css', href=$config->urls->templates . 'styles/main.css') body include header.pug h1= $page->title if $page->editable() p: a(href=$page->editURL) Edit Project on GitHub: github.com/dreerr/TemplateEnginePug
      Project in modules directory: modules.processwire.com/modules/template-engine-pug/
       
      For common problems/features/questions about the Factory, use the TemplateEngineFactory thread.
       
    • By Robin S
      Pages At Bottom
      Keeps selected pages at the bottom of their siblings.
      A "bottom page" will stay at the bottom even if it is drag-sorted to a different location or another page is drag-sorted below it (after Page List is refreshed the bottom page will still be at the bottom).
      Newly added sibling pages will not appear below a bottom page.
      The module also prevents the API methods $pages->sort() and $pages->insertAfter() from affecting the position of bottom pages.
      Note: the module only works when the sort setting for children on the parent page/template is "Manual drag-n-drop".
      Why?
      Because you want some pages to always be at the bottom of their siblings for one reason or another. And someone requested it. 🙂
      Usage
      Install the Pages At Bottom module.
      Select one or more pages to keep at the bottom of their siblings. If you select more than one bottom page per parent then their sort order in the page list will be the same as the sort order in the module config.

       
      https://github.com/Toutouwai/PagesAtBottom
      https://modules.processwire.com/modules/pages-at-bottom/
    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/