Jump to content
ryan

Map Marker Map

Recommended Posts

OK, I need some help with this. This is my setup:

Dealers

-Australia

--Dealer 1

--Dealer 2

I would like a map on the Dealers page showing a marker for each dealer. Is there a way to have the marker link go to an anchor tag I have set for the country heading on the same page?

echo "<div id='map'></div>"; //div to show in template map

$js = "<script type='text/javascript'>";
$js .= "RCDMap.options.mapTypeId = google.maps.MapTypeId.ROADMAP;";
$js .= "\nRCDMap.init('map', 0, 0);";

$dealers = $pages->get("/dealers/")->find("template=dealer");
foreach($dealers as $marker) {
$js .= "\nRCDMap.addMarker('{$marker->title}', '{$marker->url}', {$marker->map_marker->lat}, {$marker->map_marker->lng});";
}
$js .= "\nRCDMap.fitToMarkers();";
$js .= "</script>";
echo $js;

Share this post


Link to post
Share on other sites

It should be that second argument to RCDMap.addMarker, where you could specify whatever URL (or anchor) you want:

RCDMap.addMarker('some title', '/some/url/', lat, lng);

RCDMap.addMarker('some title', '#some_anchor', lat, lng); 

Share this post


Link to post
Share on other sites

Ugh, thanks Ryan, it seems so obvious now....in my defence, it was late last night I posted that.

Although how would I grab the anchor link of the parent of each marker i.e. #australia rather than #dealer1?

Edit: Got it!

$js .= "\nRCDMap.addMarker('{$marker->title}', '#{$marker->parent->title}', {$marker->map_marker->lat}, {$marker->map_marker->lng});";

Share this post


Link to post
Share on other sites

In the admin the map doesn't load fully if the field is set to be collapsed on page load. I think it is because width is set as 100% rather than setting a size explicitly.

.InputfieldMapMarkerMap {
width: 100%;
height: 300px;
}

35343fq.png

Share this post


Link to post
Share on other sites

Another factor is that I don't think the MapMarker works when placed in other tabs. I think gmaps probably just needs to be visible when the editor is rendered in order for everything to work optimally.

Share this post


Link to post
Share on other sites

Yep, there is a problem when gmap is hidden. This happened to me on the frontend of a site where I was using jqueryUi to show the map, and apparently it's very common with lightboxes. The problem is that, if you are using display: none; to hide the map, it first gets rendered with 0px size, and this is what jquery's .hide() uses. The solution would be to use visibility:hidden; or position it absolutely outside of the screen instead. But I think this wouldn't be easy to do in the admin, since it's using jqueryUi...

  • Like 2

Share this post


Link to post
Share on other sites

I have recently also a problem with the plugin. The address will not be geocoded.

How can I set the value status from my own form?

$mitgliedPage->geocode->address = $form['strasse'].', '.$form['plz'].' '.$form['ort'];
$mitgliedPage->geocode->status = ...?

Thank you for your help and the great work here!

Share this post


Link to post
Share on other sites

To Geocode from the API side, you need to set the address field and save the page:

$page->map->address = '411 Holly Road, Hopkins, MN';
$page->save();

If that doesn't do it, you may sometimes need to give $page a hint:

$page->trackChange('map');
$page->save();

If it still doesn't work, you might want to double check that your PHP install supports allow_url_fopen.

The 'status' field is not meant to be set by you. It is set by Google Maps geocoder.

Share this post


Link to post
Share on other sites

ryan - this is an amazing module! I'm just using it on a website I'm building and it is spot on :)

Just a note to others: I originally had a separate Address field, but you don't need that with this module. I wasn't sure how much you could customise the address input, but you can do whatever you like within reason.

What I mean is Google is pretty forgiving - you can put things like "Somewhere over the rainbow, Rydal, Ambleside, LA22 9LX" then it will just take the parts of the address it understands and find the location from that which essentially allows you to begin the address however you like (useful if you want to put a specific brand name or other title in there at the beginning). What you can't then do of course is drag and drop the pin as the address changes again, but so far the pins have been spot on for me since they're using UK postcodes and I'm picking items in the wilderness for now.

I've also been putting commas in so that when I output the address on the page it can do a new line in the address based on the commas.

  • Like 1

Share this post


Link to post
Share on other sites

I've also been putting commas in so that when I output the address on the page it can do a new line in the address based on the commas.

Thanks, Pete. You just saved me a load of work. (Why didn't I think of that?)

Share this post


Link to post
Share on other sites
What you can't then do of course is drag and drop the pin as the address changes again, but so far the pins have been spot on for me since they're using UK postcodes and I'm picking items in the wilderness for now.

If you uncheck the checkbox separating the address and the lat/lng boxes, you can adjust the coordinates separately from the address, or vice versa.

  • Like 1

Share this post


Link to post
Share on other sites

Ah, didn't see that - that's even better :D

Share this post


Link to post
Share on other sites

The above uses my RCDMap class. Feel free to grab it if you find it helpful. You'll want to view the source on any of those URLs above to see how it works. http://www.di.net/al...ripts/RCDMap.js

An addition to the RCDMap.js to contol the zoom level if there's only one marker ( ryan script needs at least 2 markers to set the zoom level, wich is nice if you've more then one marker )

Just replace the fitToMarkers at the bottom of the script & it wil work for 1 marker with zoom level 10, or the zoom level depending on multiple markers.

fitToMarkers: function() {
   if(RCDMap.numMarkers == 1 ) {
       RCDMap.map.setZoom(10);
   } else {
       var bounds = new google.maps.LatLngBounds();
       for(var i = 0; i < RCDMap.numMarkers; i++) {
           var latLng = RCDMap.markers[i].position;
           bounds.extend(latLng);
       }
       RCDMap.map.fitBounds(bounds);
   }
}
  • Like 1

Share this post


Link to post
Share on other sites

Hi ryan

Just tried to integrate the MapMarker address field with search and it won't let me. Am I doing something wrong?

My selector is as follows:

$matches = $pages->find("map_marker.address%=$q, limit=50"); 

I think I might just be being thick :)

Share this post


Link to post
Share on other sites

FieldtypeMapMarker doesn't implement a getMatchQuery method, which is required in order to support any operators that don't exist in MySQL. For instance, MySQL knows what "=" and ">" are, but it doesn't know what "%=" is. So I'm guessing you are getting a "Operator '%=' is not implemented in FieldtypeMapMarker" error message.

The second issue is that there isn't actually a field named 'address' in the DB, as this fieldtype represents it with the default 'data' field. Meaning you would just refer to it as "map_marker" (or whatever you field name is) rather than "map_marker.address". But the truth is, since we're using 'address' as in this Fieldtype at runtime, we really should allow it for queries too. Try adding this to your FieldtypeMapMarker.module, which should solve both issues: 

public function getMatchQuery($query, $table, $subfield, $operator, $value) {
  if(!$subfield || $subfield == 'address') $subfield = 'data';
  if($operator != '%=') return parent::getMatchQuery($query, $table, $subfield, $operator, $value); 
  $ft = new DatabaseQuerySelectFulltext($query);
  $ft->match($table, $subfield, $operator, $value);
  return $query;
}
Let me know if that works out for you, and I'll add it to mine too. I'm also going to add a fulltext index to the 'data' field so that we can use other partial match operators. 
 

Share this post


Link to post
Share on other sites

Perfect - works for me :)

So is that function basically useful for any module that implements its own tables if you want such a field to be searchable?

Share this post


Link to post
Share on other sites

Ah, except I have two issues that I suspect are more general Selector issues.

If I'm searching for the partial word "test" but the actual word is "testing" for example, it won't return a result. I thought it might be a length limitation, but I even tried "testin" without the G and it doesn't work no matter which selector I try. :(

The other issue is postcodes. I have a post code (zip code) in the map marker field that goes something like "LA22 X99". Typing in either LA22 or X99 returns nothing :( Is it possible they're too short? I seem to remember something about mySQL defaults limiting short word searches so this one might not be a bug :)

Share this post


Link to post
Share on other sites

I think you hit here some full text mysql stopwords or number get filtered out and it's too short :)

Share this post


Link to post
Share on other sites

I think Soma's right. The %= selector works for postcodes and part postcodes cos it doesn't use the fulltext index. It's a bit less versatile than a fulltext search and it is a bit slower but I have it searching about 7000 pages with no noticeable speed issues. (Even 'slow' mySQL is still fast.)

Share this post


Link to post
Share on other sites

What I mean though is that %= doesn't work for me, so it's likely a length issue I need to change in my mySQL config like Soma said.

Share this post


Link to post
Share on other sites

Hmmm, %= doesn't use fulltext indexes (indices?), so word length shouldn't matter.

Share this post


Link to post
Share on other sites
If I'm searching for the partial word "test" but the actual word is "testing" for example, it won't return a result. I thought it might be a length limitation, but I even tried "testin" without the G and it doesn't work no matter which selector I try.

Since it's using LIKE in this case (rather than fulltext) it won't matter. 

I just tested it out here on the skyscrapers profile. These queries worked for me:

$pages->find("map.address%=peachtree"); // returned all skyscrapers on peachtree road
$pages->find("map.address%=pea"); // returned the same thing
$pages->find("map.address%=191"); // Returned "191 peachtree road" skyscraper

Try grabbing the latest version of FieldtypeMapMarker. I updated it to have the new getMatchQuery method. I also modified it a bit so that it supports ^= and $=, and all the fulltext searching operators. Though the fulltext operators will only work on newly created fields, since existing installs won't have a fulltext index. But like DaveP said, you'd have to have a very large quantity of items before you'd see the speed difference. 

Share this post


Link to post
Share on other sites

Hi!

I just came across a strange problem and I hope you can help me. It's something that worked before, but suddenly stopped working. As far as I know I did not change the code in any way,

Ok, here we go:

I use an older version of this module and the module itself works perfectly fine. I use it together with Ryan's RCDMap class (for Google Maps) and the source code generated using the module is:

<script type='text/javascript'>
RCDMap.options.zoom = 4;
RCDMap.options.mapTypeId = google.maps.MapTypeId.HYBRID;
RCDMap.init('map', 60.128162,18.643501);

RCDMap.addMarker('Fotografiska Museet', '/bezienswaardigheden-en-attracties/fotografiska-museet/', 59.319450, 18.077618, 'FFFF00','A');
RCDMap.addMarker('Koninklijk paleis', '/bezienswaardigheden-en-attracties/koninklijk-paleis/', 59.326756, 18.071651, 'FFFF00','B');
RCDMap.addMarker('Skälby', '/bezienswaardigheden-en-attracties/skalby/', 56.682201, 16.336901, 'FF0000','C');
RCDMap.addMarker('Finspångs Slott', '/bezienswaardigheden-en-attracties/finsp-ngs-slott/', 58.709824, 15.770853, 'FF0000','D');
RCDMap.addMarker('Brudfjällsvägen', '/bezienswaardigheden-en-attracties/brudfjallsvagen/', 58.860771, 12.401965, 'FF0000','E');
RCDMap.fitToMarkers();</script>
 

So far no problems...

The RCDMap.addMarker function is:

	addMarker: function(title, url, lat, lng, poicolor, poi_id) {

		var latLng = new google.maps.LatLng(lat, lng);
		
		var marker = new StyledMarker({ 
			styleIcon:new StyledIcon(StyledIconTypes.MARKER,{color:poicolor,text:poi_id}),
			position: latLng, 
			map: RCDMap.map,
		});

		RCDMap.markers[RCDMap.numMarkers] = marker;
		RCDMap.numMarkers++;

		google.maps.event.addListener(marker, 'mouseover', function(e) { 
			RCDMap.currentUrl = url; 
			RCDMap.mapNote.html("<span>" + title + "</span>").show()
				.css('top', '0px')
				.css('left', '0px')
				.css('display', 'block')
				.css('width', 'auto')
				.css('color', '#ffffff')
				.css('background', '#000000')
				.css('padding', '2px 5px 2px 5px');

			$(document).mousemove(function(e) {
				$("#map_note").css({
					'top': e.pageY-10, 	
					'left': e.pageX+15
					});
			}); 

		});

		google.maps.event.addListener(marker, 'mouseout', function(e) {
			RCDMap.mapNote.hide();
			$(document).unbind("mousemove"); 
		}); 

		google.maps.event.addListener(marker, 'click', function(e) {
			window.location.href = RCDMap.currentUrl; 
		}); 
	},
 

The goal is that every marker has its own letter (poi_id) and color (poicolor). This used to work fine, but suddenly something happened and now is every marker getting the same letter and color as the last marker.

The titles, links etc. working fine and are unique for every marker. Any suggestions about what I am missing?

You can see the problem live at: http://www.zwedenweb.com/bezienswaardigheden-en-attracties/

Thanks in advance!

/Jasper

Share this post


Link to post
Share on other sites

I'm not up-to-speed enough on Google Maps to be able to troubleshoot very well. But if it stopped working on its own without there being some change somewhere, then it's got to be related to a change at Google Maps? Still, you might want to put a console.log(poi_id) and console.log(poicolor) in there to monitor and isolate what's going on. It would be nice to know specifically where the info is getting lost. 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...