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

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 flydev
      PulsewayPush
      Send "push" from ProcessWire to Pulseway.
       
      Description
      PulsewayPush simply send a push to a Pulseway instance. If you are using this module, you probably installed Pulseway on your mobile device: you will receive notification on your mobile.
      To get more information about Pulseway, please visit their website.
      Note
      They have a free plan which include 10 notifications (push) each day.
       
      Usage
      Install the PulsewayPush module.
      Then call the module where you like in your module/template code :
      <?php $modules->get("PulsewayPush")->push("The title", "The notification message.", "elevated"); ?>  
      Hookable function
      ___push() ___notify() (the two function do the same thing)
       
      Download
      Github:  https://github.com/flydev-fr/PulsewayPush Modules Directory: https://modules.processwire.com/modules/pulseway-push/  
      Examples of use case
      I needed for our work a system which send notification to mobile device in case of a client request immediate support. Pulseway was choosen because it is already used to monitor our infrastructure.
      An idea, you could use the free plan to monitor your blog or website regarding the number of failed logins attempts (hooking Login/Register?), the automated tool then block the attacker's IP with firewall rules and send you a notification.
       

       
      - - - - - - - - - - - - - -
      11-22-2017: added the module to the modules directory
       
    • By netcarver
      Part 1 of a 2 part Module & Service Reveal.
      I'm currently working on a new module: ModuleReleaseNotes that was inspired by the work I originally did on making Ryan's ProcessWireUpgrades module "release" aware. In the end, I decided to ditch the approach I was originally taking and instead work on a module that hooked in to the UpgradeConfirmation dialog and the module edit page.
      Aims
      My aims for this module are as follows...
      Make discovery of a module's changes prior to an upgrade a trivial task. Make breaking changes very obvious. Make reading of a module's support documentation post-install a trivial task. Make module authors start to think about how they can improve the change discovery process for their modules. Make sure the display of information from the module support files/commit messages doesn't introduce a vulnerability. Looking at these in turn...
      Making discovery of a module's changes prior to upgrade a trivial task.
      This is done by adding a "What's changed section" to the upgrade confirmation dialog.  This section takes a best-effort approach to showing what's changed between the installed version and the updated version that's available via the module repository.
      At present, it is only able to talk to github-hosted repositories in order to ask them for the release notes, the changelog file (if present) and a list of commits between the git tag that matches the installed version and the tag matching the latest version.
      It will display the Release Notes (if the author is using the feature), else it will display the commits between the tags (if tagging is used by the module author) else it will show the changelog file (if present) else it will show the latest N commits on the master branch (N, of course, being configurable to your liking.)
      An example of the Github Release Notes pulled in for you, taken from Mike Rockett's TextformatterTypographer Module...

      An example of a tag-to-tag commit list from the same module...

      An example of a changelog - formatted to show just the changes (formatting styles will change)...

      Finally, an example of a fallback list of commits - sorry Adrian ...

       
      Making breaking changes obvious.
      This is currently done by searching for a set of configurable search strings. Later versions may be able to support breaking change detection via use of Semantic Versioning - but this may require some way of signalling the use of this versioning standard on a module-by-module basis.
      For now, then, you can customise the default set of change markers. Here I have added my own alias to the list of breaking change markers and the changes section of the changelog is styled accordingly (these will be improved)...

       
      Make reading of a module's support documentation, post-install, a trivial task.
      This is done by making some of the support files (like the README, CHANGELOG and LICENSE files) readable from the module's information/settings screen. There is an option to control the initial open/closed state of this section...

      Here is Tracy's README file from within the module settings page... 

       
      Make module authors start to think about how they can improve the change discovery process for their modules.
      There are notes in each of the sections displayed on the upgrade confirmation page that help authors use each of the features...

       
      Make sure display of external information doesn't introduce a vulnerability.
      This is an ongoing concern, and is the thing that is most likely to delay or prevent this module's release lead to this module's withdrawl should a vulnerability be found. Currently, output is formatted either via Markdown + HTML Purifier (if it was originally a Markdown file) or via htmlspecialchars() if it has come from a plaintext file.
      If you discover a vulnerability, please get in contact with me via the forum PM system.
       
      Ongoing...
      For now, I've concentrated on integration with GitHub, as most people use that platform to host their code. I know a few people are hosting their repositories with BitBucket (PWFoo comes to mind) and some with GitLab (Mike Rockett?) and I would eventually like to have adaptor implementations for these providers (and perhaps GitKraken) - but for now, GitHub rules and the other hosts are unsupported.
       
      Links
      Github: ModuleReleaseNotes
      PW Module Repository: Here
    • By FrancisChung
      Hi,
      I was wondering if anyone knew what this did? 

      If so, do you know what modules it actually impacts? Is there another log that lists the action it took?

      I'm having some weird problems with PHP duplicate declaration per link below, since this module was run.
       
       
    • By tpr
      AdminOnSteroids
      Various admin tweaks to enhance ProcessWire admin.
      http://modules.processwire.com/modules/admin-on-steroids/
      https://github.com/rolandtoth/AdminOnSteroids