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 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://gitlab.com/baumrock/RockFinder/tree/master
       
      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 OLSA
      Hello for all,
      ConfigurationForm fieldtype module is one my experiment from 2016.
      Main target to build this module was to store multiple setup and configuration values in just 1 field and avoid to use 1 db table to store just single "number of items on page", or another db table to store "layout type" etc. Thanks to JSON formatted storage this module can help you to reduce number of PW native fields in project, save DB space, and reduce number of queries at front-end.
      Install and setup:
      Download (at the bottom ), unzip and install like any other PW module (site/modules/...). Create some filed using this type of field (ConfigurationForm Fieldtype) Go to field setup Input tab and drag some subfields to container area (demo). Set "Name" and other params for subfields Save and place field to templates ("Action tab") How to use it:
      In my case, I use it to store setup and configurations values, but also for contact details, small content blocks... (eg. "widgets").
      Basic usage example:
      ConfigForm fieldtype "setup" has subfields:
      "limit", type select, option values: 5, 10, 15, 20
      "sort", type select, option values: "-date", "date",  "-sort", "sort"
      // get page children (items) $limit = isset($page->setup->limit) ? $page->setup->limit : 10; $sort = isset($page->setup->sort) ? $page->setup->sort : '-sort'; $items = $page->children("limit=$limit, sort=$sort");  
      Screenshots:


       
      Notes:
      Provide option to search inside subfields Provide multilanguage inputs for text and textarea field types Provide option for different field layout per-template basis Do not place/use field type "Button" or "File input" because it won't works. Please read README file for more details and examples Module use JSON format to store values. Text and textarea field types are multilanguage compatible, but please note that main target for this module was to store setup values and small content blocks and save DB space. Search part inside JSON is still a relatively new in MySQL (>=5.77) and that's on you how and for what to use this module.
      Thanks:
      Initial point for this fieldtype was jQuery plugin FormBuiled and thanks to Kevin Chappel for this plugin.
      In field type "link" I use javascript part from @marcostoll module and thanks to him for that part.
      Download:
      FieldtypeConfigForm.zip
      Edit: 14. August 2018. please delete/uninstall previously downloaded zip
      Regards.
         
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://gitlab.com/baumrock/RockPdf
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
    • By Thomas Diroll
      Hi guys I'm relatively new to PW and just finished developing a page for a client. I was able to include all necessary functionality using the core fieldtypes but now I it seems that I need to extend them with a custom one. What I need is a simple button, that copies the absolute url (frontend not PW-backend) of the page which is currently edited to the clipboard. As this feature is only needed inside a specific template, I tend to use a custom fieldtype which provides this feature. I've been looking inside the core modules code (eg. FieldtypeCheckbox.module) but I don't really get the structure of it and how its rendered to the admin page. I also didn't find a lot of tutorials covering custom fieldtypes.
      Maybe some of you could give me some tips on how to write a basic custom fieldtype that renders a button which copies the value of
      page->httpUrl() to the clipboard using JS. Thanks!
    • By bernhard
      Some of you might have followed the development of this module here: https://processwire.com/talk/topic/15524-previewdiscussion-rockdatatables/ . It is the successor of "RockDataTables" and requires RockFinder to get the data for the grid easily and efficiently. It uses the open source part of agGrid for grid rendering.
       
      WHY?
      ProcessWire is awesome for creating all kinds of custom backend applications, but where it is not so awesome in my opinion is when it comes to listing this data. Of course we have the built in page lister and we have ListerPro, but none of that solutions is capable of properly displaying large amounts of data, for example lists of revenues, aggregations, quick and easy sorts by the user, instant filter and those kind of features. RockGrid to the rescue 😉 
       
      Features/Highlights:
      100k+ rows Instant (client side) filter, search, sort (different sort based on data type, eg "lower/greater than" for numbers, "contains" for strings) extendable via plugins (available plugins at the moment: fullscreen, csv export, reload, batch-processing of data, column sum/statistics, row selection) all the agGrid features (cell renderers, cell styling, pagination, column grouping etc) vanilla javascript, backend and frontend support (though not all plugins are working on the frontend yet and I don't plan to support it as long as I don't need it myself)  
      Limitations:
      While there is an option to retrieve data via AJAX the actual processing of the grid (displaying, filtering, sorting) is done on the client side, meaning that you can get into troubles when handling really large datasets of several thousands of rows. agGrid should be one of the most performant grid options in the world (see the official example page with a 100k row example) and does a lot to prevent problems (such as virtual row rendering), but you should always have this limitation in mind as this is a major difference to the available lister options that do not have this limitation.
      Currently it only supports AdminThemeUikit and I don't plan to support any other admin theme.
       
      Download: https://gitlab.com/baumrock/RockGrid
      Installation: https://gitlab.com/baumrock/RockGrid/wikis/Installation
      Quikckstart: https://gitlab.com/baumrock/RockGrid/wikis/quickstart
      Further instructions: https://gitlab.com/baumrock/RockGrid/wikis/quickstart#further-instructions
       
      Module status: alpha, License: MIT
      Note that every installation and uninstallation sends an anonymous google analytics event to my google analytics account. If you don't want that feel free to remove the appropriate lines of code before installation/uninstallation.
       
      Contribute:
      You can contribute to the development of this and other modules or just say thank you by
      testing, reporting issues and making PRs at gitlab liking this post buying me a drink: paypal.me/baumrock/5 liking my facebook page: facebook.com/baumrock hiring me for pw work: baumrock.com  
      Support: Please note that this module might not be as easy and plug&play as many other modules. It needs a good understanding of agGrid (and JavaScript in general) and it likely needs some looks into the code to get all the options. Please understand that I can not provide free support for every request here in the forum. I try to answer all questions that might also help others or that might improve the module but for individual requests I offer paid support for 60€ per hour.
       
      Changelog
      180730 support subdir installations 180711 bugfix (naming issue) 180630 alpha realease  
      Use Cases / Examples:
      Colored grid cells, Icons, Links etc. The Grid also has a "batcher" feature built in that helps communicating with the server via AJAX and managing resource intensive tasks in batches:

      Filters, PW panel links and instant reload on panel close:

      You can combine the grid with a chart library like I did with the (outdated) RockDataTables module: