Jump to content
Mats

Module: Leaflet Map

Recommended Posts

The ProcessWire modules directory link for Fieldtype Leaflet Map Marker is pointing to the master branch's ZIP archive which is the 2.8.1 version. I'm assuming that needs to be updated to point to the proper Github location.

  • Like 2

Share this post


Link to post
Share on other sites

I installed the version 3.0.3 (PW3) and tested the geocoding and It can't find many places and even street numbers. Please correct me if I'm wrong but Google Geocoding can't work without an API key and the module doesn't ask for a key so it's probably using Leaflet's default geocoding cause when I search for example "Terra Vibe Park" I'm getting Nothing found but if I go on this sample that uses Leaflet with Esri Geocoding and search for "Terra Vibe Park" it will find it. Shouldn't be better to update the module to use Esri Geocoding? According to that sample code it doesn't seem to require any API key.

Share this post


Link to post
Share on other sites

I started working on a module that will use exclusively the Esri Geocoding.

Since you're using the Leaflet Control Geocoder on your module that supports various geocoders, you should update it to let the user select which one they want to use by supplying their API key if the selected geocoder requires it.

EDIT: Unfortunately Esri isn't free.

Share this post


Link to post
Share on other sites

Is it possible to use Leaflet's layer groups with this module? I have three pages, each containing a map, each one showing a different kind of data. I'd like to be able to have one map that shows all three types of data with the ability to turn layers on and off, each type being a different layer.

I'm thinking that the best way to do this is going to be by using the module to handle the backend, geocoding the data in the relevant pages/child pages, but using plain Leaflet.js to output the data on the front-end. Any other thoughts/suggestions would be appreciated though.

Share this post


Link to post
Share on other sites

Dear Mats,

I'm trying to get your Leaflet Map Module with PJAX to work. I'm using the MoXo https://github.com/MoOx/pjax library but seem to have some troubles with it: I managed to configure PJAX that the inline JavaScript is executed after every page fetch, but I get Error: Map container is already initialized.

Any ideas how to approach this? 

EDIT:

I decided to use my own code with the standard Leaflet library and getting the marker with data attributes:

.map(data-lat=$map->lat data-lng=$map->lng data-zoom=$map->zoom data-address=$map->address)

initializing the map with 

import L from "leaflet";
document.addEventListener("DOMContentLoaded", function(event) {
  let container = document.querySelector(".map");
  let mymap = L.map(container).setView([container.dataset.lat, container.dataset.lng], container.dataset.zoom);
  L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
  maxZoom: 18,
  id: 'mapbox.outdoors'}).addTo(mymap);
  let marker = L.marker([container.dataset.lat, container.dataset.lng])
  }).addTo(mymap);
});

and triggering DOMContentLoaded in pjax:

document.addEventListener("pjax:success", function(event){
  window.document.dispatchEvent(new Event("DOMContentLoaded", {
    bubbles: true,
    cancelable: true
  }));
});

 

  • Like 1

Share this post


Link to post
Share on other sites

I tried using this module on a new website and it looks like it's no longer functioning, probably due to the Google Api issues.

When I add a new Field I immediately get the error "Error geocoding address" and cannot update the address without getting this error, and it no longer returns the lat/lng points when I change the address.

Share this post


Link to post
Share on other sites

This module is great, essential. Unfortunately I can't yet get it to work on my front end. The map doesn't show up due to a javascript/jquery conflict.

The module outputs regular jquery script starting with $(function() { ... If I manually add the following alternative to the footer it works fine, the map shows up in all its CartoDB glory:

Spoiler

var jMap = jQuery.noConflict(); 

jMap(function() {
var mleafletmap1 = new jsMarkupLeafletMap();
mleafletmap1.setOption('zoom', 18);
mleafletmap1.setOption('scrollWheelZoom', 1);

mleafletmap1.init('mleafletmap1', 43.660072, -79.354134, 'CartoDB.Positron');
var default_marker_icon = L.AwesomeMarkers.icon({ icon: 'home', iconColor: 'white', prefix: 'fa', markerColor: 'darkblue' });
mleafletmap1.addMarkerIcon(default_marker_icon, 43.660072, -79.354134, '/events/myeventtitle/', 'My Event Title', '');
});

 

How can I get the module to do the same? Or get around this problem some other way?

Edit:

I have replaced the following line in MarkupLeafletMap.module:

$inlineScript = "<script type='text/javascript'>\n$(function() {\n" .

with this:

$inlineScript = "<script type='text/javascript'>\nvar jMap = jQuery.noConflict();\njMap(function() {\n" .

Now the module works as expected. 

Could you make that part of the module for next updates? With jLeaflet instead of the more generic jMap. Or is there a good reason not to do it like this or a more cleverer way to avoid jquery conflicts?

 

 

 

Share this post


Link to post
Share on other sites

The 'address' field is supposed to output the address you entered.

echo $page->map->address;	// outputs the address you entered

But it actually outputs whatever the map thinks is at that lat-long, with a lot of unnecessary details added, something like this:

Quote

WhatThisPlaceUsedToBeCalled, 12, Street Name, Corktown, Old Toronto, Toronto, Ontario, M4M 1L9, Canada

The address search also insists Water Street is in lower Manhattan when I mean Water Street in Brooklyn. Brooklyn becomes Kings County in map->address; nobody calls it that!

You can force the map to select the right location by dragging the pointer. Now the address is:

Quote

DUMBO Historic District Proposal, Manhattan Bridge lower level, Two Bridges, Manhattan, Manhattan Community Board 3, New York County, New York City, New York, 10002, USA

Which is hilarious and completely useless.

Is there a way to keep/store the actual "address you entered"? Or else a way to format that map->address into something usable?

Share this post


Link to post
Share on other sites

Thank you for this module! 
It works great but I have some problems with the options not getting recognised.
(Iam using the dev version, because of the geocoding issues with google maps)

Since I use the map as a fullscreen background I need to disable the zoom on scroll feature for usability.
The option for the marker are working but the leaflet options scrollWheelZoom and dragging are ignored.
This is my code:

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

$options = array('markerIcon' => 'flag', 'markerColour' => 'red', 'scrollWheelZoom' => false, 'dragging' => false);
echo $map->render($page, 'map', $options);

another option would be to disable this after init with map.scrollWheelZoom.disable()
But this is also not working, because map is not defined. Whats the name of the map instance in js?

Share this post


Link to post
Share on other sites

Hi everybody,

I'm using the dev-version, sans google api with ProcessWire 3.0.123 but unfortunately my map doesn't appear (blank div on the page): http://processwire.marcoangeli.net/about/

here are my settings:

 

_init.php

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


_head.php

<?php echo $map->getLeafletMapHeaderLines(); ?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>


basic-page.php

echo $map->render($page, 'map');

 

Do I miss some basic setting?

 

Thanks!

 

 

 

Share this post


Link to post
Share on other sites

There's a problem with your JavaScript and CSS Files, many 404 Errors (Console output of google chrome):

font-awesome.min.css:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
MarkerCluster.css:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
MarkerCluster.Default.css:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
leaflet-providers.js:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
leaflet.awesome-markers.css:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
leaflet.markercluster.js:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
MarkupLeafletMap.js:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
leaflet.awesome-markers.min.js:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
leaflet-providers.js:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
MarkupLeafletMap.js:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
leaflet.awesome-markers.min.js:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
leaflet.awesome-markers.css:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
(index):67 Uncaught ReferenceError: jsMarkupLeafletMap is not defined
    at HTMLDocument.<anonymous> ((index):67)
    at j (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at Function.ready (jquery.min.js:2)
    at HTMLDocument.K (jquery.min.js:2)
/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)
font-awesome.min.css:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
leaflet.awesome-markers.css:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
MarkerCluster.css:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)
MarkerCluster.Default.css:1 Failed to load resource: the server responded with a status of 404 (Page Not Found)

And the links:

		<link rel="stylesheet" type="text/css" href="/site/modules/FieldtypeLeafletMapMarker/assets/font-awesome-4.6.3/css/font-awesome.min.css">        <!-- Styles supporting the use of Leaflet.js -->
        <link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
        <link rel="stylesheet" type="text/css" href="/site/modules/FieldtypeLeafletMapMarker/assets/leaflet-markercluster/MarkerCluster.css" />
        <link rel="stylesheet" type="text/css" href="/site/modules/FieldtypeLeafletMapMarker/assets/leaflet-markercluster/MarkerCluster.Default.css" />

        <!-- Scripts supporting the use of Leaflet.js -->
        <script type="text/javascript" src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
        <script type="text/javascript" src="/site/modules/FieldtypeLeafletMapMarker/assets/leaflet-markercluster/leaflet.markercluster.js"></script>
        <script type="text/javascript" src="/site/modules/FieldtypeLeafletMapMarker/assets/leaflet-providers/leaflet-providers.js"></script>
        <script type="text/javascript" src="/site/modules/FieldtypeLeafletMapMarker/MarkupLeafletMap.js"></script>

        <!-- Extend Leaflet with Awesome.Markers -->
        <link rel="stylesheet" type="text/css" href="/site/modules/FieldtypeLeafletMapMarker/assets/leaflet-awesome-markers/leaflet.awesome-markers.css" />
        <script type="text/javascript" src="/site/modules/FieldtypeLeafletMapMarker/assets/leaflet-awesome-markers/leaflet.awesome-markers.min.js"></script>

 

  • Like 1

Share this post


Link to post
Share on other sites

hey zoeck,

thanks for the suggestions.

On my html I've got this code:

<link rel="stylesheet" type="text/css" href="/site/modules/FieldtypeLeafletMapMarker/assets/font-awesome-4.6.3/css/font-awesome.min.css">

but there's no FieldtypeLeafletMapMarker folder inside my module directory.

Instead I have MarkupLeafletMap folder with all the assets inside...

very strange.

I'll investigate further...

Share this post


Link to post
Share on other sites

Can you check which version of the module is installed?

Share this post


Link to post
Share on other sites

hey zoeck, thank you for the feedback.

I finally resolved the issue: I installed the module by uploading the zip file: that didn't work. Then I uninstalled everything and followed the instructions:

I created a folder named "FieldtypeLeafleftMapMarker" with everything inside and that worked.

Thanks again.

Share this post


Link to post
Share on other sites

Hey @Mats,
great module! I was playing around with pages->find today and was getting matches for pages that didn't have map markers stored to them, or at least I thought. On closer inspection in MySQL I found that there were DB rows for all pages that had the template with my map marker field, not just the ones with actual markers stored.

Most of the empty records look like this

data: EMPTY lat: 0.000000 lng: 0.000000 status: -1 zoom: 0

Some like

data: EMPTY lat: 0.000000 lng: 0.000000 status: -100 zoom: 0

Which I'm assuming would be the ones that once had a marker which was later removed through "Clear"

And some like this:

data: EMPTY lat: 0.000000 lng: 0.000000 status: -100 zoom: 16

Which I guess are pages that someone just fumbled around with the zoom on in the backend 🙂

So in order to find pages with actual map markers right now I'd need to set up my selector like

 template=mytemplate, map_marker.lat!=0, map_marker.lng!=0 

Instead of just

map_marker!=""

This might also explain why the marker input field keeps popping up in page edit mode, even though I've set the visibilty to "closed when blank & open when populated".

Am I missing something obvious or is this unintentional behaviour?

Best regards!

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