Jump to content
ryan

Map Marker Map

Recommended Posts

1 hour ago, bernhard said:

yes, it is: https://www.google.com/search?q=change google map colours

should be very easy using their readymade styles: https://snazzymaps.com/

Yeah I know it's possible. I've already did on a map without using this module. I should be more specific.

On a map without using this module I used this js to change the colors:

var styles = [
  {
    "stylers": [
      { "hue": "#c1d72e" }
    ]
  }
];

So the proper question is how can I apply the above code on a map using this module? 

Share this post


Link to post
Share on other sites

just don't use the modules render() method and write the code on your own. you should know how to do that as you say you already did it without the module ;)

you have all the necessary field data in these variables:

echo $page->map->address;   // outputs the address you entered
echo $page->map->lat;       // outputs the latitude
echo $page->map->lng;       // outputs the longitude
echo $page->map->zoom;      // outputs the zoom level

you can also just copy the generated markup of your render method and then adjust the necessary (parts of your) scripts.

Share this post


Link to post
Share on other sites
2 hours ago, bernhard said:

just don't use the modules render() method and write the code on your own. you should know how to do that as you say you already did it without the module ;)

you have all the necessary field data in these variables:


echo $page->map->address;   // outputs the address you entered
echo $page->map->lat;       // outputs the latitude
echo $page->map->lng;       // outputs the longitude
echo $page->map->zoom;      // outputs the zoom level

you can also just copy the generated markup of your render method and then adjust the necessary (parts of your) scripts.

I've copied my code from an older website I've created a map with changed colors without using the module and it doesn't even load the map on the website I'm currently developing. It's driving me crazy...

window.onload = function () {

			var latlng = new google.maps.LatLng(12.3456789, 12.3456789);

			var styles = [
  {
    "stylers": [
      { "hue": "#c1d72e" }
    ]
  }
];

			var myOptions = {
				zoom: 17,
				center: latlng,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				disableDefaultUI: true,
				styles: styles
			};

			map = new google.maps.Map(document.getElementById('map'), myOptions);
			
			var myCenter = new google.maps.LatLng(12.3456789, 12.3456789);
    var myIcon = new google.maps.MarkerImage(
    "https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|c1d72e",
    new google.maps.Size(24,30),
    new google.maps.Point(0,0),
    new google.maps.Point(12,23)
    );
 
 
    var marker = new google.maps.Marker({position: myCenter, icon: myIcon, map: map});

On the 2nd method you proposed I don't know how to apply the code to change the color.

If anyone managed to change the colors with this module PLEASE let me know how you dit it. Thanks.

Share this post


Link to post
Share on other sites

i would suggest doing the following:

  • create a new template file for your page that holds the map data with exactly the code from the google example (javascript + html): https://developers.google.com/maps/documentation/javascript/examples/map-simple?hl=de
  • change nothing but your api-key.
  • when you view this page you should see the same map as on the google docs page.
  • replace the fixed values for lat/lng/zoom by those saved in your processwire site. see my example above ($page->map->lat...)
  • view your page, it should show the map at the position that you specified in your backend
  • change your style by adding the styles options (see code below)
  • view your page, you should see the new style
  • if everything works, try to implement your map in your original template file
var map;
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 8, // add comma here
    styles: [
  {
    "stylers": [
      { "hue": "#c1d72e" }
    ]
  }
]
  });
}

 

  • Like 3

Share this post


Link to post
Share on other sites
14 hours ago, bernhard said:

i would suggest doing the following:

  • create a new template file for your page that holds the map data with exactly the code from the google example (javascript + html): https://developers.google.com/maps/documentation/javascript/examples/map-simple?hl=de
  • change nothing but your api-key.
  • when you view this page you should see the same map as on the google docs page.
  • replace the fixed values for lat/lng/zoom by those saved in your processwire site. see my example above ($page->map->lat...)
  • view your page, it should show the map at the position that you specified in your backend
  • change your style by adding the styles options (see code below)
  • view your page, you should see the new style
  • if everything works, try to implement your map in your original template file

var map;
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 8, // add comma here
    styles: [
  {
    "stylers": [
      { "hue": "#c1d72e" }
    ]
  }
]
  });
}

 

Thanks to your suggestions I finally figured out the problem. I had to replace the % on map's css to px.

Share this post


Link to post
Share on other sites

I have the big map working with this code (quite basic)

$items = $page->children;
$map = $modules->get('MarkupGoogleMap');

$content .= $map->render($items, 'map');

 

For the page with turtles I want to have the current turtle on that page to be visible on the map. I have made the following code:

if($page->hasChildren) {
    $results = $page->children("limit=9, sort=-created");

    $pagination = $results->renderPager();

    $content .= $pagination;
   $content .= renderSchildpadden($results);
    $content .= $pagination;
}


foreach ($results as $result){
    foreach ($result->verspreidingen as $verspreiding) {
    $out .= $verspreiding . "|";
    }
    }
//$item = $out;
$sidebar_bottom = $out;

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

$sidebar_bottom .= $map->render($out, 'map');

The part for the sidebar_bottom gives the following error:

Error: Uncaught Error: Call to a member function first() on string in /home/deb26781n3/domains/chrysemys.nl/public_html/site/modules/FieldtypeMapMarker/MarkupGoogleMap.module:209
Stack trace:
#0 /home/deb26781n3/domains/chrysemys.nl/public_html/site/templates/schildpadden.php(32): MarkupGoogleMap->render('1213|1198|1199|...', 'map')
#1 /home/deb26781n3/domains/chrysemys.nl/public_html/wire/core/TemplateFile.php(268): require('/home/deb26781n...')
#2 [internal function]: ProcessWire\TemplateFile->___render()
#3 /home/deb26781n3/domains/chrysemys.nl/public_html/wire/core/Wire.php(374): call_user_func_array(Array, Array)
#4 /home/deb26781n3/domains/chrysemys.nl/public_html/wire/core/WireHooks.php(549): ProcessWire\Wire->_callMethod('___render', Array)
#5 /home/deb26781n3/domains/chrysemys.nl/public_html/wire/core/Wire.php(399): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array)
#6 /home/deb26781n3/domains/chrysemys.nl/public_html/wire/modules/PageRender.mod (line 209 of /home/deb26781n3/domains/chrysemys.nl/public_html/site/modules/FieldtypeMapMarker/MarkupGoogleMap.module) 

This error message was shown because: you are logged in as a Superuser. Error has been logged.

 

The input for the big map are the pages that contain the field 'map'.

foreach ($results as $result)

{ foreach ($result->verspreidingen as $verspreiding) {

$out .= $verspreiding . "|";

}

}

The code above produces also an array of pages that contain the field 'map'. But this time the same function strugles on this part of the code in the module:

if($options['useMarkerSettings'] && (count($pageArray) == 1 || !$lat)) {
   // single marker overrides lat, lng and zoom settings
   $marker = $pageArray->first()->get($fieldName); << this line and on first() returns the error
          $lat = $marker->lat;
   $lng = $marker->lng; 
   if($marker->zoom > 0) $zoom = (int) $marker->zoom;
}

What am I doing wrong here?

 

Sanne

Share this post


Link to post
Share on other sites

Not sure if this is the cause of the problem, but this line...

if($options['useMarkerSettings'] && (count($pageArray) == 1 || !$lat)) {

...does not ensure that $pageArray exists. The if() condition is passed if $options['useMarkerSettings'] and !$lat, regardless of what $pageArray is.

  • Like 1

Share this post


Link to post
Share on other sites

I understand, but why does it work on page where I select children (array) but not on a page where I select certain pages as array that are the pages that have the 'map' field.

An array is made on both occasions.

The second array has duplicate items, could that be an issue?

 

Sanne

Share this post


Link to post
Share on other sites
3 minutes ago, webhoes said:

I understand, but why does it work on page where I select children (array) but not on a page where I select certain pages as array that are the pages that have the 'map' field.

An array is made on both occasions.

Not sure - nowhere in the code you posted do you show where $pageArray is defined.

Quote

Uncaught Error: Call to a member function first() on string

What this error means is that $pageArray is a string and not an actual PageArray. Use Tracy to dump $pageArray and find out what is going on with it.

Share this post


Link to post
Share on other sites

@Robin S, yes it is a string. Also it is build upon repeating pagearray which doesn't lead to an correct new array.

1 | 2 | 3 | 4 2 | 5 | 8 5 | 4 | 5...

The 2 in 4 2 is the start of an new array, so is the 5 in 8 5.

It can't find something with 42 or 85.

It seems the output has to be made a new array explicitly and also with the correct setup. Tried that yesterday, could not get it figured out.

Edited by webhoes

Share this post


Link to post
Share on other sites
3 hours ago, webhoes said:

yes it is a string. Also it is build upon repeating pagearray which doesn't lead to an correct new array.

Strings and arrays are different types of data, and a PageArray is a actually an object but you can think of it as a special kind of array. Long story short, you can't use PageArray methods on a string.

It's difficult to help without seeing the code where you set the $pageArray variable.

Share this post


Link to post
Share on other sites

I've been using Map Marker field with great success. 

I may have come across a strange bug, I'm not sure how to debug it...

When using the value Elgin, IL in the Address field, the geocode fetches correctly, BUT after saving the page, the Address field is BLANK.

I can do Elgin, Il (lowercase "L"), or Elgin, Illinois or South Elgin, IL or pretty much anything else I can think of, and everything WORKS.

WHY is the Address field not getting saved with just Elgin, IL? Or how can I debug this (where to look?) Thanks

Share this post


Link to post
Share on other sites
43 minutes ago, rastographics said:

When using the value Elgin, IL in the Address field, the geocode fetches correctly, BUT after saving the page, the Address field is BLANK.

Not sure why that is happening, but just to let you know that address works fine for me. Could some browser extension be interfering perhaps?

2017-02-25_101130.png.875b2cc9c231d9a9b46c73ffb5a04c9a.png

Share this post


Link to post
Share on other sites

Good idea, but unfortunately I just tried incognito mode with all extensions off and still not working.

No JS errors in console. Is there some other thing I can do to trace this down?

Share this post


Link to post
Share on other sites
On 10/7/2016 at 11:51 PM, bee8bit said:

@adrian Thank you, that was not the right solution. But it made me investigate in the right place:

InputfieldMapMarker's init function is never called. At the bottom, InputfieldMapMarker.js says:


$(document).ready(function() {
    $(".InputfieldMapMarkerMap").each(function() {
        var $t = $(this);
        InputfieldMapMarker.init($t.attr('id'), $t.attr('data-lat'), $t.attr('data-lng'), $t.attr('data-zoom'), $t.attr('data-type')); 
    }); 
}); 

When the $(document) is ready() there are no $(".InputfieldMapMarkerMap")s yet, as they will be AJAX-loaded later.

So I guess we need an event that is fired after each successful AJAX call, so we can InputfieldMapMarker.init() all those Maps which haven't been initialized before. Is there a way to register a listener for such events?

Hi @bee8bit. Did you find a solution or work around for this ?

I have a similar issue. "Days, Location, Description" in a Repeater. Where Location was going to be a inputFieldMapMarker. But, obviously not working. Did you figure a work around based on event listener or something ? 

Regards,

Share this post


Link to post
Share on other sites

I'm having an issue in PW 3.0.62 where the module will only geocode an address when I manually click the checkmark between address and lat/lng off/on when editing the page within the admin. Based on what I've read here, it seems only the client-side geocoder is working?

Additional details:

  • I have both Google Maps and Google Places APIs working without issue on the front-end and have added my Maps key to the module's configuration
  • My MapMarker-based field, "map", has a MapMarker: Error geocoding address notification and I can't find any elaboration
  • Neither API has any issues with my address formatting/default address, with an example being 5 Bloor Street, Toronto, ON M4W 3T3
  • My addresses are mapping properly when I play with the checkbox (status goes from UNKNOWN to OK)
  • I can't trigger the geocoding via the API

Any ideas?

 

 

Share this post


Link to post
Share on other sites
On 1/6/2017 at 10:45 PM, Arcturus said:

MapMarker: Error geocoding address

The same issue. Running PW 3.0.61 and Map Marker 2.0.6 worked just fine. After upgrading to 2.0.9 and entering my API key I get the above error to any address I try.

Share this post


Link to post
Share on other sites

On a map I setup, I had the trouble of encoded (ampersend made me notice) characters not getting output decoded correctly, so I had to add htmlspecialchars_decode on this this line

$title = $options['markerTitleField'] ? htmlspecialchars_decode($page->get($options['markerTitleField'])) : ''; 

Shouldn't this be the expected behaviour? And why is the page title getting output without decoded entities? Is this expected inside modules for security reasons? 

Just trying to learn some PW here :)

 

Share this post


Link to post
Share on other sites

Hi

I'm trying to display a map with a marker on frontend with this :

	$map = $modules->get('MarkupGoogleMap'); 
	$content.= $map->render($page->children, 'map');
	

The map appear, correctly zoomed at the good location. However there is no marker. The marker appear correctly in backend.

Do I miss something?

Thanks

Mélanie
PW 3.0.69 - MapMarker 2.0.9

Share this post


Link to post
Share on other sites

The basic functionality of the module is great, but I wanted the capacity to add paths, and potentially geometric areas, and the easiest way I found to generate them was using something like Google Earth, or various mobile GPS apps which export KML files.
KML files can contain map markers as well, but the module already handles these fine.
The Google Maps API allows adding KML layers, and of course Processwire already has a files fieldtype, so it's easy to create a files field that only allows files of type kml.

I had to make a few modifications to the FieldTypeMapMarker as well.

MarkupGoogleMap.js

    //Add support for KML overlays, eg exported from Google Earth, or various GPS apps.
    this.addKml = function (url) {
        var zIndex = 99999 + this.numMarkers + 1;
        var layerOptions = {
            url: url,
            map: this.map,
            zIndex: zIndex
        }
        var kml = new google.maps.KmlLayer(layerOptions);

    }

MarkupGoogleMap.module

I added a 'postinit' property that is output after the map has been rendered. I found that the overlays can only be added after the map has been initialised, so the existing 'init' property didn't work.

Here's how I used it in a template:

$map = $modules->get('MarkupGoogleMap');
foreach ($page->kml as $kmlFile) {
    $overlays .= "mgmap1.addKml('$kmlFile->httpUrl'); ";
}
$content .= $map->render($page, 'location', array('type' => 'ROADMAP', 'postinit' => $overlays));

The code could probably be improved to have the foreach loop inside MarkupGoogleMap.module, and just pass the name of the overlay field if any, but it needs to be optional, as not all maps will have an associated field with kml files.

  • Like 2

Share this post


Link to post
Share on other sites

To always display the map at the center even if the browser resized or the full screen button pressed just use the below function:

google.maps.event.addDomListener(window, 'resize', function() {
		var center = map.getCenter()
		google.maps.event.trigger(map, "resize")
		map.setCenter(center)
	});

 

Share this post


Link to post
Share on other sites

Edit: I just realized there are 18 Pages in this thread and I am pretty sure someone else mentioned it, I will have a look :-[

 

I have just added the module to a new site I am creating and it seems like there are some issues.

1. The API key is not recognized when using the <script>-tag from module page (<script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?sensor=false'></script>) – I had to add <script src="https://maps.googleapis.com/maps/api/js?libraries=places&key={{my API key}}"></script> in order to display the map.

2. The map in frontend does not look like the one in the backend. Instead of green areas for parks I get an all grey version, as you can see on the screenshots below. Mapsproblem.jpg.748edc310899b61b36078502d4dc0d92.jpg

Has anyone else noticed this?

PW Version is ProcessWire 3.0.62 from stable channel.

Edited by thmsnhl
  • Like 1

Share this post


Link to post
Share on other sites
On 10/20/2017 at 4:42 AM, thmsnhl said:

Edit: I just realized there are 18 Pages in this thread and I am pretty sure someone else mentioned it, I will have a look :-[

 

I have just added the module to a new site I am creating and it seems like there are some issues.

1. The API key is not recognized when using the <script>-tag from module page (<script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?sensor=false'></script>) – I had to add <script src="https://maps.googleapis.com/maps/api/js?libraries=places&key={{my API key}}"></script> in order to display the map.

2. The map in frontend does not look like the one in the backend. Instead of green areas for parks I get an all grey version, as you can see on the screenshots below. Mapsproblem.jpg.748edc310899b61b36078502d4dc0d92.jpg

Has anyone else noticed this?

PW Version is ProcessWire 3.0.62 from stable channel.

 

 

I had to do this as well!

Share this post


Link to post
Share on other sites

so I am using this module and it is working great, I figured out that it doesn't render properly in collapse.

But now I want to disable or reset what happens when you click on an map marker or icon. I don't want to pass it a url, I want it to href to an id on the same page and I just don't seem to get it, where do I set the url or replace it.

Thank you

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 bernhard
      --- Please use RockFinder3 ---
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By Craig
      I've been using Fathom Analytics for a while now and on a growing number of sites, so thought it was about time there was a PW module for it.
      WayFathomAnalytics
      WayFathomAnalytics is a group of modules which will allow you to view your Fathom Analytics dashboard in the PW admin panel and (optionally) automatically add and configure the tracking code on front-end pages.
      Links
      GitHub Readme & documentation Download Zip Modules directory Module settings screenshot What is Fathom Analytics?
      Fathom Analytics is a simple, privacy-focused website analytics tool for bloggers and businesses.

      Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don't need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
      Privacy focused Fast-loading dashboards, all data is on a single screen Easy to get what you need, no training required Unlimited email reports Private or public dashboard sharing Cookie notices not required (it doesn't use cookies or collect personal data) Displays: top content, top referrers, top goals and more
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      Since 0.0.4, instructions and changelog can be found in the README only. You can find it here  🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github, thanks!
    • By MoritzLost
      Sorry for the convoluted title. I have a problem with Process modules that define a custom page using the page key through getModuleInfo (as demonstrated in this excellent tutorial by @bernhard). Those pages are created automatically when the module is installed. The problem is that the title of the page only gets set in the current language. That's not a problem if the current language (language of the superuser who is installing the module) is the default language; if it isn't, the Process page is missing a title in the default language. This has the very awkward effect that a user using the backend in the default language (or any other language) will see an empty entry in the setup menu:

      This screenshot comes from my Cache Control module which includes a Process page. Now I realize the description sounds obscure, but for us it's a common setup: We a multiple bilingual sites where the default language is German and the second language is English. While the clients use the CMS in German, as a developer I prefer the English interface, so whenever I install a Process module I get this problem.
      As a module author, is there a way to handle this situation? I guess it would be possible to use post-installation hooks or create the pages manually, but I very much prefer the declarative approach. The page title is already translatable (through the __ function), but of course at the time of installation there is no translation, and as far as I'm aware it's not possible to ship translations with a module so they are used automatically. Could this situation be handled better in the core? I would prefer if the module installation process would always set the title of the Process page in the default language, instead of the language of the current user.
×
×
  • Create New...