Jump to content

Map Marker Map


ryan

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? 

Link to comment
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.

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
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

Link to comment
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
Link to comment
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

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
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

Link to comment
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,

Link to comment
Share on other sites

  • 2 months later...

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?

 

 

Link to comment
Share on other sites

  • 3 weeks later...
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.

Link to comment
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 :)

 

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
Share on other sites

  • 2 weeks later...

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

 

Link to comment
Share on other sites

  • 4 weeks later...

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
Link to comment
Share on other sites

  • 3 weeks later...
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!

Link to comment
Share on other sites

  • 3 weeks later...

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

       
×
×
  • Create New...