Jump to content

Module: Leaflet Map


Mats

Recommended Posts

On 10/6/2019 at 6:07 PM, sujag said:

I'm trying to automatically add pages containing a field with this fieldtype. while all other fields are populated as expected the lat/lng part of my geolocation field keeps its default values. Is there a special syntax to address these

I don't really understand why, but it works, if I change lat lng values in a second step.

$newPoi = $pages->add("tmbPoi", "$parentPage->url", [
                    'name' => $thisPoiId,
                    'title' => $poi['name'],
					...
					]

$newPoi->geolocation->lat = $lat;
$newPoi->geolocation->lng = $lng;
$newPoi->of(false);
$newPoi->save('geolocation');

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

This is a really nice module, but why is the fully working version only in the 'dev' release?

EDIT: Having said that, I now find I have the same problem as the previous poster. It all works fine on my Dev machine. But in the live environment it is blank.

EDIT 2: In my case, the problem was simple - just forgot to upload the additional lines in the <head> - i.e.

    <?php $map = wire('modules')->get('MarkupLeafletMap'); ?>
    <?php echo $map->getLeafletMapHeaderLines(); ?>

Is that your problem @Leftfield?

  • Like 1
Link to comment
Share on other sites

@MarkE thank you for your answer but it doesn't help since I load files manually (except main js). Anyway, I will remove module for two reasons (both not fault of the module):
First: Lon and Lat are not compatible with Google Maps for my country. There is some wild offset.
Second: Will test for SEO, doubt is that Google doesn't rank website with Open street map.

Link to comment
Share on other sites

On 11/24/2019 at 6:40 PM, ank said:

i installed the module, but i'm not able to get it working, i get the error "Error geocoding address" in the backend and a blank map ?

What is missing/wrong ?

I have the same issue. Installed it as per the guidelines, but it throwing me the same issue. 

Link to comment
Share on other sites

18 hours ago, DL7 said:

I have the same issue. Installed it as per the guidelines, but it throwing me the same issue. 

So using the dev version, the geo coding is working. (also when you add a key to the google geo call). But I now run into an issue where the map is grey out in the "edit page" set-up. I cant fill in an address either as the input field is disabled. @hellomoto mentioned this issue before. Did you got a chance to fix it? @Mats ay pointers?

Link to comment
Share on other sites

  • 1 month later...

Hello,

After spending hours trying to find a solution, I ask the community for help... I have a map showing up on page load. It works fine but it takes quite a while. You can see it in action there : https://planetalert.tuxfamily.org/world/6ef (be patient, loading is terrible)

I have already tried caching parts of my page (the different lists) and it's ok, but I can't manage to cache the map. So I would like to load the 2nd tab (when clicking on the faces icon at the top-left corner) by default to get a fast loading page and have my map loading on an ajax call. But all my tests are complete failures ?

Here's my ajax part of code :

	[...] // Setting $allElements (for markers) and $options there
	$map = $modules->get('MarkupLeafletMap');
$out .= $map->getLeafletMapHeaderLines();
$out .= $map->render($allElements, 'map', $options);
	

Eventually, I get my map box, but it stays empty ? 

Any advice, please ?

Link to comment
Share on other sites

@celfred: This has nothing to do with the map itself. It takes 15 seconds four your server to generate a response, after that the map and all of its content loads fast. So I assume your process of building the list of markers is somewhat ineffective. Can you show the code with which you generate the $allElements Array?

 

Link to comment
Share on other sites

On 1/22/2020 at 4:49 PM, MadeMyDay said:

@celfred: This has nothing to do with the map itself. It takes 15 seconds four your server to generate a response, after that the map and all of its content loads fast. So I assume your process of building the list of markers is somewhat ineffective. Can you show the code with which you generate the $allElements Array?

 

@MadeMyDay Thanks for your reply. From your comment, I have tried testing my $allEments function (it takes 0.415s on localhost). You can see the code there : https://framagit.org/celfred/planetAlert/blob/master/site/templates/my-functions.inc (function teamFreeWorld() line 1468) BUT I have also tried this :

	$out .= $map->render($allElements->eq(0), 'map', $options);

And the page now loads a lot faster (I can tell the difference even on localhost) ! So maybe it's because I have 56 (or even 96) markers, with a photo... ? What could I do, then ?

I hope you (or anybody else) will have other pieces of advice for me ? My site has improved so much over the years thansk to the help of this community (and I have learned so much - you can tell I'm not a pro dev ? - I'm a teacher and the website is for motivating my middle-school pupils)

EDIT : Well, for the moment, I've just removed the images in my map markers tooltips and it loads faster... 

Link to comment
Share on other sites

  • 3 months later...
  • 2 months later...

I have this module implemented on a website and all works well. It currently outputs popups as per the attached image – the first line is generated by the module/options but I can't seem to override it in any way. The map pull sin information from it's child pages, and the title in the pop up links to the child page, but I want to change this so it links to the company's website instead (as per the url further down the pop-up). I've tried changing the 'markerLinkField' / 'markerTitleField' options, leaving them blank, etc but that either displays as per the attached or stops the pop up working.

Any thoughts much appreciated.

Screenshot 2020-08-03 at 15.15.02.png

Link to comment
Share on other sites

  • 2 weeks later...

Issue 1:

Why do I get lots of random Russian (?) text when I try to look up addresses? And the location search results are awful; the system suggests random street addresses (with lots of Russian) when you type in something basic like 'London, England'. Full addresses seem to work better, but only without postal codes - 'nothing found' when you try to search with postal codes included.

Issue 2:

Maps show up in the admin area, but not on the front-end. I have another version of the same site where they do show up on the front-end without problems, so am a bit puzzled where the problem could be. What are typical causes I could check?

Edit:

The problem with the map not showing up on the front end (Issue 2) had something to do with this error showing up in Chrome Inspect/DevTools:

Uncaught TypeError: $ is not a function at (index):529

Something with jQuery. The error disappeared when I copied module files from another site where Leaflet Map did work. Not sure where the cause of the error is exactly.

 

Link to comment
Share on other sites

  • 4 weeks later...

Hello,

is it possible to render the input field on a frontend template (for loggedin users only).

I tried this:

<?php 
$m = $modules->get('InputfieldLeafletMapMarker');
$m->render();
?>

This generates errors for empty variables.

PHP Notice: Trying to get property 'lat' of non-object in ...\InputfieldLeafletMapMarker.module:102
PHP Warning: Creating default object from empty value in ...\InputfieldLeafletMapMarker.module:102
PHP Notice: Undefined property: stdClass::$lng in ...\InputfieldLeafletMapMarker.module:103
PHP Notice: Undefined property: stdClass::$zoom in ...\InputfieldLeafletMapMarker.module:104
PHP Notice: Undefined property: stdClass::$address in ...\InputfieldLeafletMapMarker.module:105
PHP Notice: Undefined property: stdClass::$status in ...\InputfieldLeafletMapMarker.module:106
PHP Notice: Undefined property: stdClass::$status in ...\InputfieldLeafletMapMarker.module:107
PHP Notice: Undefined property: stdClass::$raw in ...\InputfieldLeafletMapMarker.module:130
Link to comment
Share on other sites

  • 1 month later...

Hi there,

thanks for providing the Leaflet Map Marker module - very useful!

One thing I couldn't figure though is: how can I set NO default address to a field? I need to have the map as an optional field for a given template.

Thanks for any advice.

jor

Link to comment
Share on other sites

@jor

Not sure if this is the correct way, but on my map template I wrap my code with:

if($page->marker->address) {

}

e.g.

if($page->marker->address) {

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

    'markerFormatter' => function($page, $marker_options) {
        			if ($page->marker_icon->title) {
                        $marker_options['icon'] = $page->marker_icon->title;
                    }

                    if ($page->marker_colour->title) {
                        $marker_options['markerColor'] = $page->marker_colour->title;
                    }

                    // And the icon colour. This is another text field. Colour values like White, Black or an RGB value are ok here.
                    if ($page->marker_icon_colour->title) {
                        $marker_options['iconColor'] = $page->marker_icon_colour->title;
                    }    
        return $marker_options;
    },

    'popupFormatter' => function($page) {
        $out[] = "<strong>$page->headline</strong>";
        return implode('<br/>', $out);
    }

);
       

$content.= $map->render($page, 'marker', $options);

}

If no address is entered, no map is shown.

Link to comment
Share on other sites

  • 3 months later...

Hey there,

I don't know if this might help smeone (and if I did it the right way), but I had an issue as follow : all maps worked on my site except 2 monuments which didn't show any map. I noticed they had a single quote in their name and if I got rid of it the map appeared.

I then ended up doing this (in my '$opitions' array) and it worked :

	'popupFormatter' => function($page) {
 $page->title = str_replace('\'', '\\\'', $page->title); // Dirty hack (no map if single quote in title)
 $out[] = '<strong>'.sprintf(__('In %1$s, in %2$s'), $page->city->title, $page->country->title).'</strong>';
 $out[] = "<p class=\"text-center\"><img src=\"{$page->photo->eq(0)->getCrop('thumbnail')->url}\" /></p>"; // ** NB: Use escaped double quotes if HTML attributes needed **
 return implode('<br/>', $out);
},
	

Again, it might sound a bit hacky, but it works for me and maybe it can be useful to someone...

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