ryan

Map Marker Map

443 posts in this topic

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" }
    ]
  }
]
  });
}

 

3 people like this

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.

1 person likes this

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

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
      Hi,
      just stumbled over a little module that i built for my last project. it helped me to test performance of my rockdatatables module to generate 3000 random json datasets and i want to share it with you. maybe it saves some time for someone.
      https://gitlab.com/baumrock/RockDummyData/
      easy example:
      $rdd = $modules->get('RockDummyData'); for($i=0; $i<15; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); echo date("d.m.Y H:i:s", $dummy->timestamp) . "<br>"; } more advanced:
      $json = new stdClass(); $json->data = array(); $rdd = $modules->get('RockDummyData'); for($i=0; $i<3000; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); $obj = new stdClass(); $obj->name = $dummy->forename . ' ' . $dummy->surname; $obj->position = $dummy->job; $obj->office = $dummy->city; $obj->color = $dummy->color; $obj->start_date = new stdClass(); $obj->start_date->display = date('d.m.Y',$dummy->timestamp); $obj->start_date->sort = $dummy->timestamp; $obj->salary = rand(0,10000); $json->data[] = $obj; } echo json_encode($json); you have to store your random datasets on your own into the /data folder. there are several services for creating all kinds of random data on the web - if you know one service that allows sharing those datasets let me know and i can include common needed data into the module
    • By AndySh
      Hello!
      I need your assistance please. I purchased the module FormBuilder. Unfortunately, the module discontinued delivering customer submissions to e-mail box specified in the module settings. Direct mailing to the e-mail box works OK. The module settings stays the same and are correct, like "Send e-mail to administrator(s) is checked. The last version of FormBuilder 3.0 has been installed. Please advise how to resolve the issue becase I cannot get orders from customers anymore (((
    • By kixe
      As described in this post (https://processwire.com/talk/topic/8551-custom-urls-for-pages/?p=82742) the option 'Name Format Children' under the tab 'Family' in template settings doesn't work properly and also not as expected. I had a look inside the code and made some changes which are working properly, which offers much more options, more consistency and less code too.

      The result is the following. You have 3 Options for generating name and title, which could be combined in endless variations.
      Name is always derived from title, same like creating pages manually.
      type date: if function detects # character anywhere in the string, conversion will be: deletion of # and string will be used as format parameter for PHP date() function type field: if string is a fieldname of the parent page the value of this field will be used type string: if string doesn't fit to the 2 preceeding it will be taken as it is All parts (separated by comma) will be composed in the order of setting. You can use unlimited numbers of parts

      I made a pull request on github: https://github.com/ryancramerdesign/ProcessWire/pull/831

      Example screenshots

      Setting ...


      will result in


       
    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
       
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend