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

Thanks again.

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 Anssi
      A simple module to enable easy navigation between the public and the admin side of the site. After installation a green bar will appear to the upper side of the screen, containing a few navigation elements and displaying the PW version number.
      Heavily inspired by @apeisa's great AdminBar (Thanks!). I needed a bit simpler tool for my projects and as a result, this was made. Available on GitHub .

    • 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.
      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!
    • By David Karich
      Thanks to the great Pro module "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use this module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      With this proof of concept I have created a module which adds the feature to copy a repeater item to the clipboard so that you can paste this item to another page with the same repeater field. The module has been developed very rudimentarily so far. It is currently not possible to copy nested items. There is also no check of Min/Max. You can also only copy items that have the same field on different pages. And surely you can solve all this more elegantly with AJAX. But personally I lack the deeper understanding of the repeaters. Also missing on the Javascript side are event triggers for the repeaters, which would make it easier. Like e.g. RepeaterItemInitReady or similar.
      it would be great if @ryan would implement this functionality in the core of RepeaterMatrix. I think he has better ways to implement this. Or what do you think, Ryan?
      Everybody is welcome to work on this module and improve it, if it should not be integrated into the matrix core. Therefore I put it for testing and as download on GitHub: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDublicate
      You can best see the functionality in the screencast: 
       
    • By anderson
      Hi,
      Please take a look at this:
      https://templatemag.com/demo/Good/
      The upper nav bar, including dropdowns like "pages" and "portfolios", what do you call this whole thing? At first I guess it's called "dropdown nav bar", but seems not.
      AND of course, what's the simplest way/module to achieve this in PW?
      Thanks in advance.
    • By Sebi2020
      Hey, I'm new and I created a simple module for tagging pages because I didn't found a module for it (sadly this is not a core feature). This module is licensed under the GPL3 and cames with absolutly no warranty at all. You should test the module before using it in production environments. Currently it's an alpha release. if you like the module or have ideas for improvements feel free to post a comment. Currently this fieldtype is only compatible with the Inputfield I've created to because I haven't found  an Inputfield yet, that returns arrays from a single html input.
      Greetings Sebi2020
      FieldtypeTags.zip.asc
      InputfieldTagify.zip
      InputfieldTagify.zip.asc
      FieldtypeTags.zip