Jump to content

Module: Leaflet Map


Mats

Recommended Posts

@mr-fan if you are still having the problem from 

with geocoding from your custom fields, maybe my modified InputfieldLeafletMapMarker.js gist can help. I have a custom button in the form that triggers the geocoding, defined on line 48 and a fucntion from line 135 that takes values from custom fields, concats them and does the geocoding.

  • Like 3
Link to comment
Share on other sites

I tried this on localhost with a new project. I getting errors in the backend and the map space is white.

Propbably because I am running the backend in https:

http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css - Works

https://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css - Works not (Firefox security - Invalid certificate)

They advise a different CDN on their homepage, that's maybe why:

Quote

Using a Hosted Version of Leaflet

The latest stable Leaflet release is hosted on a CDN — to start using it straight away, place this in the head of your HTML code:


<link rel="stylesheet" href="https://npmcdn.com/leaflet@0.7.7/dist/leaflet.css" />
<script src="https://npmcdn.com/leaflet@0.7.7/dist/leaflet.js"></script>

or


<link rel="stylesheet" href="https://npmcdn.com/leaflet@1.0.0-rc.2/dist/leaflet.css" />
<script src="https://npmcdn.com/leaflet@1.0.0-rc.2/dist/leaflet.js"></script>

 

Link to comment
Share on other sites

@ceberlin Could you describe a little more about which version you are trying - Mats', gebeer's or the one I posted? I did have some trouble initially with getting the Leaflet related files in the right place. Having a script blocker running also broke things for me - once I enabled all JS on my local site things started working a lot better.

@Beluga I haven't tried that version - yet. Can't speak for Mats or gebeer. See below.

Link to comment
Share on other sites

Thanks for this awesome module!!!

Question: is it possible to remove loading the FontAwesome CSS from the LeafletMapHeaderLines (fe. at the options)? I use FontAwesome on a website and this will lead to that it will be loaded twice.

Best regards

Link to comment
Share on other sites

15 hours ago, netcarver said:

I've switched my master branch over to Leaflet 0.7.7 from the npmcdn links you posted above. Could you try out the files from the master branch?

@netcarver Now works well with the standard setup here. Does not work with the HERE map series (I think to remember the v100rc2 beta does).

  • Like 2
Link to comment
Share on other sites

On 1.8.2016 at 6:05 PM, gebeer said:

I have a custom button in the form that triggers the geocoding, defined on line 48 and a fucntion from line 135 that takes values from custom fields, concats them and does the geocoding.

It would be great to add this to the module with the opportunity to select if you want to use it or not (in the field settings).

Link to comment
Share on other sites

  • 3 weeks later...

This may seem simplistic, but how do I make a map where existing fields on the pages define the marker settings? In other words, rather than creating separate new fields on the page template for marker_icon and marker_color (and then laboriously having to fill them in each time), how I can use an existing field, and then merely provide some code denoting the corresponding changes I would like to the marker options. 

For example, for a travel site, each page has a "category" field (sleep, eat, see), and I would like that field to automatically determine the marker color and icon (anything with a category=sleep has marker_color = orange and marker_icon = bed, that sort of thing). 

I got this working on individual pages with "if" statements, but can't seem to get this working within the array needed to populate a map drawing from lots of pages.

Thanks!

Link to comment
Share on other sites

5 hours ago, Reid Bramblett said:

For example, for a travel site, each page has a "category" field (sleep, eat, see), and I would like that field to automatically determine the marker color and icon (anything with a category=sleep has marker_color = orange and marker_icon = bed, that sort of thing). 

Hi Reid,

Give this a shot. It's a template file that should do what you want if you are using my fork of the Leaflet module.

<!DOCTYPE html><?php

// Create our Leaflet map object. We do it here, before the header output, so we can use it to generate includes in the
// header itself.
$map = $modules->get('MarkupLeafletMap');

?>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title><?php echo $page->title; ?></title>
        <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/main.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <?php echo $map->getLeafletMapHeaderLines(); ?>
    </head>
    <body>
        <h1><?php echo $page->title; ?></h1>
<?php

            // Extract the pages that will be turned into markers on the map
            $items = $pages->find("<YOUR SELECTOR HERE>"); // Update as needed


            // Setup the options for our map
            $map_options = array(
                // This routine formats the marker icon that gets used on the map.
                'markerFormatter' => function ($page, $marker_options) {
                    switch ($page->category) {   // Update with the fieldname you wish to check as needed
                        // For sleep category markers
                        case 'sleep' :
                            $marker_options['icon'] = 'bed';
                            $marker_options['markerColor'] = 'orange';
                            break;

                        // Add other cases as needed

                        // Here's the default marker setup
                        default :
                            $marker_options['icon'] = 'cutlery';
                            $marker_options['markerColor'] = 'blue';
                            break;
                    }

                    return $marker_options;
                }
            );

            // Generate the HTML and JS that will render the map with a marker for each page in the $items page array
            echo $map->render($items, '<YOUR MAP MARKER FIELDNAME HERE>', $map_options); // Update as needed
        ?>
    </body>
</html>

Please be aware that the icon colours you can choose from are pretty limited. Look at the 'markerColor' row in the table here for your options.

Hope that helps.

Link to comment
Share on other sites

Hey guys!
I have a problem with this. When I put the  <?php echo $map->getLeafletMapHeaderLines(); ?> in the header of my template a get a

Error: Call to a member function getLeafletMapHeaderLines() on a non-object (line 34 of /www/htdocs/w00dd152/projekte/fabricius/site/templates/_header.php) 

I have checkt the permissons on the module files, everything is on 777. I also pressed the reload button (as suggested) on the module page in PW but still no luck. Iam running PW 3.0.30 devns

Link to comment
Share on other sites

is there a trick, when using this with a repeater for multible markers in PW 3?
Here is my code, but thats not working:
 

<?php
$lage = wire('pages')->get("/lage/");
      $items = $lage->map_repeater; 
echo $map->render($items, 'map'); 
                 ?>

Also in the backend, the Address field is not clickable, when I use the Map Field in a Repeater 

Edit: It seems that the files for the module are not loading. I get an error in the console that the files are not loading.

Link to comment
Share on other sites

@jploch I've never used this in a repeater setup and I'm unsure of your field/template structure from that snippet. How have you actually structured things? What's the field called that holds the map markers?

Regarding the backend, the address is normally a read-only field that is set either by clicking on the magnifying glass in the top-right corner of the map and entering a description or by simply dragging the marker around. Have you tried moving the marker or using the search feature? If they don't work, it is possible there is a problem with some of the JS not loading properly. Please could you launch you browser dev tools and see if any of the JS assets are not loading.

Link to comment
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
×
×
  • Create New...