1

I have built a website for car tours. There are multiple tours throughout the year, and new ones are added regularly. Here is a quick outline of the website...

Content type: "Tour Page", Fields: Field collection item, allows multiple tour steps to be added. Each field collection item has a Gmap find address on map location field.

On each tour page, I have a view Gmap using a contextual filter to get a default value of Content ID from URL. This displays the tour steps as single icons. This view is in a block, and set to display on all "Tour pages".

I would like to draw a line on the map from point to point. It can be a straight line, going from point to point.

Now, I can edit the view, go to gmap settings, and enter my own lines using the macro for the view, like this...

[gmap line=#0000ff/5/45:51.512099,-0.15169000000003052 + 51.20086,3.2629389999999603 + 50.654685,4.833983999999987 + 50.403266,6.240233999999987 + 49.966239,8.18481399999996 + 49.067118,8.10241700000006]

...but this will output the same lines for this view on every tour page. But of course, the route is different for every tour. Here is where I am so far...

http://www.dev.ducktoursinternational.com/tour/maranello-monaco-monza-grand-prix-tour-2009

...The line is on the map, following the points. But this same line is in the same place on every tour.

I have all of the latitude and longitude values for all of the points collection in the field collection location fields, is there a way to create a unique macro for every map using these values?

I can probably use a "master" view to assemble all of the lat and long values into the right format for a gmap macro, but how do I get that macro to apply to the different route on each page?

Some more information... 1. Here is the tour page with the current macro on it... http://www.dev.ducktoursinternational.com/tour/maranello-monaco-monza-grand-prix-tour-2009

  1. Here is a screenshot of the gmap view... enter image description here

  2. Here is a screenshot of the views GMap Settings enter image description here

So I have a block with a map, and a block with the correct macro for that page. How do I use that macro for that map?

0

off the top of my head a custom module using hook_views_pre_build or 1 of the views hooks functions should let you "alter" the Macro value from something you load and compose from the database.

To be of more help we'd need to see your full content type admin page with field collection admin page, and the master layout of the view for example if you wanted coding help ...

  • Thanks, I have added 2 screen shots, and you can see the website on a temporary domain. – Collins Mar 10 '15 at 19:48
  • The idea of altering the macro value before the map loads is perfect, but I can't find the hook to load it. I cant actually see where the macro is loaded into the map. – Collins Mar 11 '15 at 10:00
  • Is there a way to control the macro field for the view? It could either allow php, or allow replacement tokens? – Collins Mar 16 '15 at 9:13
  • If the view form has a macro field it should be an item you can set in hook_views_pre_view and examining the array structure for the saved View. – tenken Mar 16 '15 at 15:00
0

1) Make a view which result only the needed points based on contextuel references. So you do not use the gmap extension here. Only plain text output.

2) Put php code in the block which should contain the gmap syntax. You can get the result of the view by using syntax's as mention in : Get a views result using PHP code, and iterate the proper way. Then use this in your block like: gmap line= php views_get_view($view_name);?> The syntax is not good as I do not understand how to put this correctly in this editor.

  • I dont think Macro in his Views configuration is designed to take raw php code ... – tenken Mar 10 '15 at 22:03
  • That is correct. Use the php code in a basic page with php code and gmap filtered enabled. After that you can publish this node to a block with the module nodeblock. – Justme Mar 11 '15 at 6:39
  • I can compile the macro using a view, no problem. So now I have the exact macro text for each tour page (Filtered contextually by nid). So then how is that new macro data used for the views map block on the same page? Would you mind elaborating your answer a bit more? – Collins Mar 11 '15 at 9:57
  • So the result of the view is like : -0.15169000000003052 + 51.20086,3.2629389999999603 + 50.654685,4.833983999999987 + 50.403266,6.240233999999987 + 49.966239,8.18481399999996 + 49.067118,8.10241700000006 Then configure your a gmap php filter. admin/config/content/formats/add. Select at least the gmap en php filters. Save it. Then add content -> new basic page. Select the filter you just configured and enter the following pseudo code: [gmap line=#0000ff/5/45:51.512099,<?php requestqueryresult ?>] Your map will now be displayed into this node. Then apply the nodeblock configuration.. – Justme Mar 11 '15 at 10:40
  • That will draw the lines on a map, but will that keep the map markers and pop up bubbles on the current map view? – Collins Mar 11 '15 at 13:28
0

I haven't found a way to do this using gmap. Instead, I will create a view block using all of the fields I need. I will then override the default template, and custom code the map myself using https://developers.google.com/maps/documentation/javascript/overlays I can use the fields from the view along with the Google Map API to create different markers, pop up bubbles with fields, and most importantly draw the lines between the markers.

This is not the answer I was looking for, but in my case is the only option as the deadline for the project is coming to an end.

If I get a chance I will post my code once its done in-case anyone else stumbles into this issue.

0

Make use of openlayers in combination with views give you much more control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.