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):
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 BitPoet
      I'm really in love with FormBuilder, but the one thing missing to match all my end users' expectations were repeatable field groups. Think repeaters, in ProcessWire terms. Our primary application of PW is our corporate intranet, so "lines" of fields are quite common in the forms I build. We have all kinds of request forms where the information for a varying number of colleagues needs to be entered (from meal order to flight booking request) and where it is simply impractical to send a form for each, and I don't want to clutter my forms with multiple instances of fields that may only get used ten percent of the time.
      That's why I started to build FormBuilderMultiplier (link to GitHub).
      What it does:
      Adds an option to make a regular Fieldgroup repeatable Lets you limit the number of instances of a Fieldgroup on the form Adds an "Add row" button the form that adds another instance of the Fieldgroup's fields Adds a counter suffix at the end of every affected field's label Stores the entered values just like regular fields Makes the entered values available in preview and email notifications Supports most text based fields, textareas and selects (really, I haven't had enough time to test all the available choices yet) What it doesn't do (yet):
      Support saving to ProcessWire pages (i.e. real Repeaters) I haven't tested all the validation stuff, Date/Time inputs etc. yet, but since I'm utterly swamped with other stuff at work, I didn't want to wait until I have it polished. Any feedback is welcome. There might also be some issues with different output frameworks that I haven't encountered yet. The forms I work with mostly use UIKit.
      Status:
      Still alpha, so test well before using it in the field.
      Known issues:
      When rows are added, the form's iframe needs to be resized, which isn't completely clean yet.
      How it works:
      The Fieldgroup settings are added through regular hooks, as is the logic that adds the necessary field copies for processing the form and displaying previews.
      "Multiplied" field instances are suffixed with _NUM, where NUM is an incremental integer starting from 1. So if you have add two fields named "surname" and "givenname" to a fieldgroup and check the "multiply" checkbox, the form will initially have "surname_1" and "givenname_1" field (I'm still considering changing that to make the risk to shoot oneself into the foot by having a regular "surname_1" field somewhere else in the form less likely).
      When a "row" is added, the first row is cloned through JS and the counter in the fields' IDs, names and "for" attributes as well as the counter in the label are incremented before appending the copies to the Fieldset container in the form.
      To keep backend and frontend in sync, a hidden field named [name of the fieldset]__multiplier_rows is added to the form. Both the backend and the frontend script use this to store and retrieve the number of "rows".
      ToDo:
      Naturally, add the option to store the data in real repeaters when saving to pages. Do a lot of testing (and likely fixing). Make a few things (like the "Add row" button label etc.) configurable in field(set) context. Add a smooth API to retrieve the multiplied values as WireArrays. The mandatory moving screenshot:

    • By MoritzLost
      Hello there,
      I'm working on a tiny textformatter module that searches the text for titles of other pages on your site and creates hyperlinks to them. I'm not sure if something like this exists already, but I haven't found anything in the module directory, so I wrote my own solution 🙂
      It's not properly tested yet and is still missing some functionality I would like to implement, so at the moment it should be considered in BETA. Features include limiting the pages that will get searched by template, and adding a custom CSS class to the generated hyperlinks. As I'm writing this I noticed that it will probably include unpublished and hidden pages at the moment, so yeah ... it's still in development alright 😅
      You can download the module from Github:
      https://github.com/MoritzLost/TextformatterPageTitleLinks
      There's some more information in the readme as well.
      Anyway, let me know what you think! I'm happy about any feedback, possible improvements or ideas on how to improve the module. Cheers.
    • By adrian
      This module provides a way to rapidly generate Page fields and the required templates and pages for use as a drop down select (or any other Page field type).
      This module will let you create a full page field setup in literally a few seconds 
      To use, run Page Field Select Creator from the Setup Menu
      Enter a Field Title, eg: Room Types Select Options - These will become the child pages that will populate the page field select options. There are two different options.
       
      Option 1. TITLE FIELD ONLY - enter one option per line, eg:
       
      Single
      Double
      Suite
       
       
      Option 2. MULTIPLE FIELDS - the first line is used for the field names and the first field must be 'Title'. Subsequent lines are the values for the fields, eg:
       
      Title, Number of Beds, Number of People, Kitchen Facilities
      Single, 1, 1, Fridge Only
      Double, 2, 2, Fridge Only
      Suite, 3, 6, Full Kitchen
        Choose the parent where the page tree of options will be created, eg a hidden "Options" parent page Select a "Deference in API as" option depending on your needs Choose the input field type Check whether "Allow new pages to be created from field?" should be enabled. As an example, if you entered "Room Types" as the field title, you would end up with all of the following automatically created:
      a fully configured page field called: room_types MULTIPLE FIELDS OPTION - 3 additional fields - number_of_beds, number_of_people, kitchen a parent template called: room_types a child template called: room_types_items (with either just a title field, or with the 3 additional fields as well) a parent page called: Room Types a series of child pages named and titled based on the per line entries in the Select Options textarea The templates are configured such that the "room_types_items" child template can only have the main "room_types" template as a parent, and vice versa.

      Then all you have to do is add the newly created page field to any template you want and you're ready to go!
       
      You can grab it from:
       
      Modules directory: http://modules.processwire.com/modules/process-page-field-select-creator/
      Github: https://github.com/adrianbj/ProcessPageFieldSelectCreator
       

    • By bernhard
      WHY?
      This module was built to fill the gap between simple $pages->find() operations and complex SQL queries.
      The problem with $pages->find() is that it loads all pages into memory and that can be a problem when querying multiple thousands of pages. Even $pages->findMany() loads all pages into memory and therefore is a lot slower than regular SQL.
      The problem with SQL on the other hand is, that the queries are quite complex to build. All fields are separate tables, some repeatable fields use multiple rows for their content that belong to only one single page, you always need to check for the page status (which is not necessary on regular find() operations and therefore nobody is used to that).
      In short: It is far too much work to efficiently and easily get an array of data based on PW pages and fields and I need that a lot for my RockGrid module to build all kinds of tabular data.

      Basic Usage

       
      Docs & Download
      https://modules.processwire.com/modules/rock-finder/
      https://github.com/BernhardBaumrock/RockFinder
       
      Changelog
      180817, v1.0.6, support for joining multiple finders 180810, v1.0.5, basic support for options fields 180528, v1.0.4, add custom select statement option 180516, change sql query method, bump version to 1.0.0 180515, multilang bugfix 180513, beta release <180513, preview/discussion took place here: https://processwire.com/talk/topic/18983-rocksqlfinder-highly-efficient-and-flexible-sql-finder-module/
    • By BitPoet
      MediaLibrary
      Update: MediaLibrary can now be found in the official module list.
      Out of necessity, I've started to implement a simple media library module.
      The basic mechanism is that it adds a MediaLibrary template with file and image fields. Pages of this type can be added anywhere in the page tree.
      The link and image pickers in CKEditor are extended to allow quick selection of library pages from dropdowns. In the link picker this happens in the MediaLibrary tab, where you can also see a preview of the selected image. In the image picker, simply select a library from the dropdown at the top, everything else is handled by standard functionality.
      I've put the code onto github. This module is compatible with ProcessWire 3.
      Steps to usage:
      Download the module's zip from github (switch to the pw3 branche beforehand if you want to test on PW 3.x) and unpack it into site/modules Click "Modules" -> "Refresh" in the admin Click "Install" for MediaLibrary For testing, create a page with the MediaLibrary template under home (give it an expressive title like 'Global Media') and add some images and files Edit a differnt page with a CKEditor field and add a link and an image to see the MediaLibrary features in action (see the screencap for details) Optionally, go into the module settings for MediaLibrary Note: this module is far from being as elaborate as Kongondo's Media Manager (and doesn't plan to be). If you need a feature-rich solution for integrated media management, give it a look.
      Feel free to change the settings for MediaFiles and MediaImages fields, just keep the type as multiple.
      There are some not-so-pretty hacks for creating and inserting the correct markup, which could probably be changed to use standard input fields, though I'm a bit at a loss right now how to get it to work. I've also still got to take a look at error handling before I can call it fit for production. All feedback and pointers are appreciated (that's also why I post this in the development section).

      Edit 09.03.2016 / version 0.0.4: there's now also a "Media" admin page with a shortcut to quickly add a new library.

      Edit 01.05.2016:
      Version 0.0.8:
      - The module now supports nested media libraries (all descendants of eligible media libraries are also selectable in link/image picker).
      - There's a MediaLibrary::getPageMediaLibraries method you can hook after to modify the array of available libraries.
      - You can switch between (default) select dropdowns or radio boxes in the module configuration of MediaLIbrary to choose libraries.
      Edit 10.10.2018:
      Version 0.1.3:
      - Dropped compatibility for ProcessWire legacy versions by adding namespaces
      - Allow deletion of libraries from the Media overview admin page
      - Added an option to hide media libraries from the page tree (optionally also for superusers)