Jump to content
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      A community member raised a question and I thought a new sanitizer method for the purpose would be useful, hence...
      Sanitizer Transliterate
      Adds a transliterate method to $sanitizer that performs character replacements as defined in the module config. The default character replacements are based on the defaults from InputfieldPageName, but with uppercase characters included too.
      Usage
      Install the Sanitizer Transliterate module.
      Customise the character replacements in the module config as needed.
      Use the sanitizer on strings like so:
      $transliterated_string = $sanitizer->transliterate($string);
       
      https://github.com/Toutouwai/SanitizerTransliterate
      https://modules.processwire.com/modules/sanitizer-transliterate/
       
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version to 2.10, add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By thomasaull
      I created a little helper module to trigger a CI pipeline when your website has been changed. It's quite simple and works like this: As soon as you save a page the module sets a Boolean via a pages save after hook. Once a day via LazyCron the module checks if the Boolean is set and sends a POST Request to a configurable Webhook URL.
      Some ideas to extend this:
      make request type configurable (GET, POST) make the module trigger at a specified time (probably only possible with a server cronjob) trigger manually Anything else? If there's interest, I might put in some more functionality. Let me know what you're interested in. Until then, maybe it is useful for a couple of people 🙂
      Github Repo: https://github.com/thomasaull/CiTrigger
    • By Robin S
      I created this module a while ago and never got around to publicising it, but it has been outed in the latest PW Weekly so here goes the support thread...
      Unique Image Variations
      Ensures that all ImageSizer options and focus settings affect image variation filenames.

      Background
      When using methods that produce image variations such as Pageimage::size(), ProcessWire includes some of the ImageSizer settings (height, width, cropping location, etc) in the variation filename. This is useful so that if you change these settings in your size() call a new variation is generated and you see this variation on the front-end.
      However, ProcessWire does not include several of the other ImageSizer settings in the variation filename:
      upscaling cropping, when set to false or a blank string interlace sharpening quality hidpi quality focus (whether any saved focus area for an image should affect cropping) focus data (the top/left/zoom data for the focus area) This means that if you change any of these settings, either in $config->imageSizerOptions or in an $options array passed to a method like size(), and you already have variations at the requested size/crop, then ProcessWire will not create new variations and will continue to serve the old variations. In other words you won't see the effect of your changed ImageSizer options on the front-end until you delete the old variations.
      Features
      The Unique Image Variations module ensures that any changes to ImageSizer options and any changes to the focus area made in Page Edit are reflected in the variation filename, so new variations will always be generated and displayed on the front-end.
      Installation
      Install the Unique Image Variations module.
      In the module config, set the ImageSizer options that you want to include in image variation filenames.
      Warnings
      Installing the module (and keeping one or more of the options selected in the module config) will cause all existing image variations to be regenerated the next time they are requested. If you have an existing website with a large number of images you may not want the performance impact of that. The module is perhaps best suited to new sites where image variations have not yet been generated.
      Similarly, if you change the module config settings on an existing site then all image variations will be regenerated the next time they are requested.
      If you think you might want to change an ImageSizer option in the future (I'm thinking here primarily of options such as interlace that are typically set in $config->imageSizerOptions) and would not want that change to cause existing image variations to be regenerated then best to not include that option in the module config after you first install the module.
       
      https://github.com/Toutouwai/UniqueImageVariations
      https://modules.processwire.com/modules/unique-image-variations/
    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      ProcessWire-Module: http://modules.processwire.com/modules/page-access-releasetime/
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
×
×
  • Create New...