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

Great module.

I had some problems upgrading from 2.8.1 to 3.0.3. Using processwire upgrade doesn't work after several attempts on different sites I had multiple instances of MarkupAddInlineScript different versions and different paths. I finally made a backup of the database table for the field and the field definition (via export) removed the inputfield, then the complete module(s), reinstalled 3.0.3 and restored the field definition and the content to the database.

In this version in the frontend the map with several markers from a pagearray didn't show, Script console said arg.split is not a function.

Took me some time to realize that the init-function was wrong.  The default lat, lng options came with a comma instead of a point

$karte = $map->render($regLocations, 'geolocation', array('width' => '50%', 'height' => '350px', 'id' => 'locMap'));

results in:

locMap.init('locMap', 53,016109, 14,005830, 'OpenStreetMap.Mapnik');

I have to grab the lat, lng values of the first item and put them in the initialization

$karte = $map->render($regLocations, 'geolocation', array('width' => '50%', 'height' => '350px', 'id' => 'locMap', 'lat'=>$firstLoc->lat, 'lng'=>$firstLoc->lng));

to get the right output:

locMap.init('locMap', 53.016109, 14.005830, 'OpenStreetMap.Mapnik');

This might be a localization problem, since the sytem works with german settings.

Share this post


Link to post
Share on other sites

Hello, 
i have imported locations as seperate variables 
longtitude and latitude 

How to use the module with this templatevars ? 
Can anybody give me an example from scratch ? I have to add the css and js files manuelly ? And the how to call the map ? 

Thanks 

Share this post


Link to post
Share on other sites

Hello

I used this module and all work very well. Thanks for this 😄

I have just 2 questions :

  1. Is there a way/option/hook to not appy the clustering in a multi-markers map ? OR define a threshold (10 markers for example or 100 kilometers between markers or 100 pixels between markers) ?
  2. Is there a way/option/hook to add margin or padding when fitToMarkers is true ? Because some edge markers are cut...

1658934703_pwtommedesavoielocalhost_acteurs_affineurs_.thumb.png.0a31db5eaef7c82ea3a78b5d099527d2.png

Thanks a lot for your help

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 Mike Rockett
      Jumplinks for ProcessWire
      Release: 1.5.56
      Composer: rockett/jumplinks
      Jumplinks is an enhanced version of the original ProcessRedirects by Antti Peisa.
      The Process module manages your permanent and temporary redirects (we'll call these "jumplinks" from now on, unless in reference to redirects from another module), useful for when you're migrating over to ProcessWire from another system/platform. Each jumplink supports wildcards, shortening the time needed to create them.
      Unlike similar modules for other platforms, wildcards in Jumplinks are much easier to work with, as Regular Expressions are not fully exposed. Instead, parameters wrapped in curly braces are used - these are described in the documentation.
      Under Development: 2.0, to be powered by FastRoute
      As of version 1.5.0, Jumplinks requires at least ProcessWire 2.6.1 to run.
      View on GitLab
      Download via the Modules Directory
      Read the docs
      Features
      The most prominent features include:
      Basic jumplinks (from one fixed route to another) Parameter-based wildcards with "Smart" equivalents Mapping Collections (for converting ID-based routes to their named-equivalents without the need to create multiple jumplinks) Destination Selectors (for finding and redirecting to pages containing legacy location information) Timed Activation (activate and/or deactivate jumplinks at specific times) 404-Monitor (for creating jumplinks based on 404 hits) Additionally, the following features may come in handy:
      Stale jumplink management Legacy domain support for slow migrations An importer (from CSV or ProcessRedirects) Feedback & Feature Requests
      I’d love to know what you think of this module. Please provide some feedback on the module as a whole, or even regarding smaller things that make it whole. Also, please feel free to submit feature requests and their use-cases.
      Note: Features requested so far have been added to the to-do list, and will be added to 2.0, and not the current dev/master branches.
      Open Source

      Jumplinks is an open-source project, and is free to use. In fact, Jumplinks will always be open-source, and will always remain free to use. Forever. If you would like to support the development of Jumplinks, please consider making a small donation via PayPal.
      Enjoy! :)
    • By BitPoet
      As threatened in Ryan's announcement for 3.0.139, I built a little module for sliding toggles as a replacement for checkboxes. Styling of the input is CSS3 only (with all the usual caveats about older browsers), no JS necessary, and may still be a bit "rough around the edges", so to speak, since I didn't have much time for testing on different devices or brushing things up enough so I'd feel comfortable pushing it to the module directory. But here's the link to the GitHub repo for now:
      InputfieldSlideToggle
      Fieldtype and Inputfield that implements smartphone-style toggles as replacement for checkbox inputs. The visualization is CSS-only, no additional JS necessary.
      Status
      Still very alpha, use with caution!
      Features / Field Settings
      Size
      You can render the toggles in four different sizes: small, medium, large and extra large.
      Off Color
      Currently, "unchecked" toggles can be displayed either in grey (default) or red.
      On Color
      "Checked" toggles can be rendered in one of these colors: blue (default), black, green, grey, orange or red.
      Screenshots

      Some examples with checkbox label


      View all Size and Color Combinations
      Small toggles Medium toggles Big toggles Extra big toggles  









    • By Orkun
      Hi Guys
      I needed to add extended functionalities for the InputfieldDatetime Module (module is from processwire version 2.7.3) because of a Request of Customer.
      So I duplicated the module and placed it under /site/modules/.
      I have added 3 new Settings to the InputfieldDatetime Module.
      1. Day Restriction - Restrict different days based on weekdays selection (e.g. saturday, sunday) - WORKING

       
      2. Time Slots - Define Time slots based on custom Integer Value (max is 60 for 1 hour) - WORKING

       
      3. Time Range Rules per Weekday - Define a minTime and MaxTime per Weekday (e.g. Opening Hours of a Restaurant) - NOT WORKING PROPERLY

       
      The Problem
      Time Slots and Day Restriction working fine so far. But the Time Range Rules per Weekday doesn't work right.
      What should happen is, that when you click on a date, it should update the minTime and maxTime of the Time Select.
      But the change on the select only happens if you select a date 2 times or when you select a date 1 time and then close the datepicker and reopen it again.
      The time select doesn't get change when you select a date 1 time and don't close the picker.
      Here is the whole extended InputfieldDatetime Module.
      The Files that I have changed:
      InputfieldDatetime.module InputfieldDatetime.js jquery-ui-timepicker-addon.js (https://trentrichardson.com/examples/timepicker/) - updated it to the newest version, because minTime and maxTime Option was only available in the new version  
      Thats the Part of the JS that is not working correctly:
      if(datetimerules && datetimerules.length){ options.onSelect = function(date, inst) { var day = $(this).datetimepicker("getDate").getDay(); day = day.toString(); var mintime = $(this).attr('data-weekday'+day+'-mintime'); var maxtime = $(this).attr('data-weekday'+day+'-maxtime'); console.log("weekday: "+day); console.log("minTime: "+mintime); console.log("maxTime: "+maxtime); var optionsAll = $(this).datetimepicker( "option", "all" ); optionsAll.minTime = mintime; optionsAll.maxTime = maxtime; $(this).datetimepicker('destroy'); $(this).datetimepicker(optionsAll); $(this).datetimepicker('refresh'); //$.datepicker._selectDate($(this).attr("id"),date); //$.datepicker._base_getDateDatepicker(); // var inst = $.datepicker._getInst($(this)); // $.datepicker._updateDatepicker(inst); /*$(this).datetimepicker('destroy'); InputfieldDatetimeDatepicker($(this), mintime, maxtime); $(this).datetimepicker('refresh'); */ // $(this).datetimepicker('option', {minTime: mintime, maxTime: maxtime}); } } Can you have a look and find out what the Problem is?
      InputfieldDatetime.zip
       
      Kind Regards
      Orkun
    • By teppo
      This module tracks changes, additions, removals etc. of public (as in "not under admin") pages of your site. Like it's name says, it doesn't attempt to be a version control system or anything like that - just a log of what's happened.
      At the moment it's still a work in progress and will most likely be a victim of many ruthless this-won't-work-let's-try-that-instead cycles, but I believe I've nailed basic functionality well enough to post it here.. so, once again, I'll be happy to hear any comments you folks can provide
      https://modules.processwire.com/modules/process-changelog/
      https://github.com/teppokoivula/ProcessChangelog
      How does it work?
      Exactly like it's (sort of) predecessor, Process Changelog actually consists of two modules: Process Changelog and Process Changelog Hooks. Hooks module exists only to serve main module by hooking into various functions within Pages class, collecting data of performed operations, refining it and keeping up a log of events in it's own custom database table (process_changelog.) Visible part is managed by Process Changelog, which provides users a (relatively) pretty view of the contents of said log table.
      How do you use it?
      When installed this module adds new page called Changelog under Admin > Setup which provides you with a table view of collected data and basic filtering tools See attached screenshots to get a general idea about what that page should look like after a while.
      For detailed installation instructions etc. see README.md.
       


    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2019-08-08
      2019-06-15
      2019-06-02
      2019-05-25
      If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      (please have a look at the screenshots to get an idea what I'm talking about)
       




×
×
  • Create New...