Thanks for this great gmap replacement. The best module I found this week using version 3 of Google maps (if you know a bit of programming in PHP). I use it now on two sites with about 30 to follow.
The feature request I have is the possibility to use a specific icon for each marker. I couldn't find out how to do this. I tried to extend function gmap3_tools_create_marker() with an extra parameter, but this didn't work (because I don't know js that well nor the Google interface code).

function gmap3_tools_create_marker($lat, $lng, $title = NULL, $content = NULL, $icon = NULL) {
  $marker = array('lat' => $lat, 'lng' => $lng);
  if (isset($title)) {
    $marker['title'] = $title;
  }
  if (isset($content)) {
    $marker['content'] = $content;
  }
  if (isset($icon)) {
    $marker['icon'] = $icon;
  }
  return $marker;
}

Comments

pivica’s picture

Just a quick update I wanted to create patch for this last week, but too much regular Drupal works... so I am on half a way. Will release patch this week - I need just one more hour of work I think.

@promes just to check, you are using only 6.x version or 7.x? -Anyway I will post patches for both versions here so anybody can test first before we push to dev branch.

promes’s picture

Thanks pivica for your help. I also have a pile of drupal work to do, so I know making precious time available...

Currently I installed it only on two D6 sites. But more to come in D5, D6 and D7. And I go to use it in some very old non-drupal sites.
I will patch it back for myself to D5. If you / someone needs the D5 version I am willing to publish this one (after I got it ready).

pivica’s picture

Status: Active » Needs review
StatusFileSize
new7.03 KB

Hey promes, finally here is a patch I was talking about.

First note, patch is created against D7 module version. But I applied patch successfully to D6 version of module, but I did not test it in browser - so you should be able to apply and test this patch with your D6 sites.

Second I have added full example 'Map example 03' in main module file that shows how you can use custom marker options per each marker. Note that example with not work because patch do not contains custom icons that I am using - i will add them when I push this solution to dev branches.

So basically this is what you need to do when you are calling gmap3_tools_create_marker() function:

  gmap3_tools_add_map(array(
    // ...
    'markers' => array(
      gmap3_tools_create_marker(-35, 149.5, 'Marker with default icon but custom default shadow.'),
      // Last parameter array will be used for marker options for this marker.
      // See below also for global markerOptions parameter.
      gmap3_tools_create_marker(-35, 150, 'Marker with blue druplicon icon.', NULL, array(
        'icon' => file_create_url(drupal_get_path('module', 'gmap3_tools') . '/images/druplicon-blue.png'),
      )),
    ),
    // MarkerOptions object for all markers in this map.
    'markerOptions' => array(
      // Set custom shadow for all icons.
      'shadow' => file_create_url(drupal_get_path('module', 'gmap3_tools') . '/images/druplicon-shadow.png'),
    ),
   // ...
  ));

So you have two marker options arrays - one global that will be used for all markers on your map, and then you can have one marker options array per each marker which will override global marker options.
Also this example use only custom shadow and icon for markers, but you should be able to use other primitive parameters also from https://developers.google.com/maps/documentation/javascript/reference#Ma... - note that I tested only shadow and icon params.

Please test and tell me if this implementation is OK with you or you think that something can be done better.

I will patch it back for myself to D5. If you / someone needs the D5 version I am willing to publish this one (after I got it ready).

You can always create a new issue and upload there patched D5 version so others can download it easily. If there are more people interested we can always create D5 branch and commit your version there.

promes’s picture

I am going to test it as soon as possible.
Thanks pivica.

promes’s picture

Hello pivica,
I am sorry, but it doesn't work in D6.
Step 1
The first problem I got with "file_create_url(drupal_get_path('module', 'gmap3_tools') . '/images/dgreen.png')".
Since no own icon was shown I displayed the resulting name.
Since I have several sites on the same hosting this resulted in:
http://example.com/sites/example.com/files/sites/all/modules/gmap3_tools...
where the real path is:
http://example.com/sites/all/modules/gmap3_tools/images/dgreen.png
So it seems file_create_url() has a problem.

Second problem: the requested icon is not shown, the default icon does show.

Step 2
I installed the module without patches in a D7 site and asked for the "gmap3_tools/example" page. Result OK.
Then I patched this version, added some icons and changed the iconnames in the module file. Then I asked for the "gmap3_tools/example" page again. Result example 3 with the default red icons.

Step 3
Next I commented out this line in markerOptions:
'shadow' => file_create_url(drupal_get_path('module', 'gmap3_tools') . '/images/druplicon-shadow.png'),
Then the the "gmap3_tools/example" page resulted in displaying my icons. ==> OK

Step 4
I went back to the D6 site and added to my own map the lines:
'markerOptions' => array(
// Set custom shadow for all icons.
// 'shadow' => file_create_url(drupal_get_path('module', 'gmap3_tools') . '/images/druplicon-shadow.png'),
),
with no success: the markers kept showing the default icons.

Step 5
I commented out in the module file (like in step 3 but now in D6):
'shadow' => file_create_url(drupal_get_path('module', 'gmap3_tools') . '/images/druplicon-shadow.png'),
The "gmap3_tools/example" page still only presents the default icons.

promes’s picture

The D6 problem definitely is in the file_create_url() function. I removed the call to file_create_url() and now the icon is showing in one of two sites in my own map.
I used exactly the same map definition en module files in both sites. I have to think why the result is different on both D6 sites: site 1: the default red icon, site 2: an orange icon.

The example 3 of the module shows another result:
site 1: 3 red icons, site 2: only 1 red icon, no more icons.

These are todays results.

promes’s picture

When I look in the HTML I see in the D7 jQuery.extend part:
"markerOptions":{"icon":"http:\/\/example.com\/sites\/all\/modules\/gmap3_tools\/images\/dgreen.png"}
where in the D6 no backslashes appear.
Can this be the problem?

pivica’s picture

Hey promes, many thanks for your testing.

I will check this into details this night and create separate patch for D6 - probably there is some problem with
file_create_url() implementation in D6 - it does not work the same like in D7. I will also upload in attach prepared D6 and D7 versions of module so you can test more easily.

So if you are not in a big hurry I would suggest you wait me finish all this and then check again.

promes’s picture

Hello pivica,

Google's deadline to move over to maps v3 is in May.
The first site in which I use your module is not that important and a good learning case. I use a solution which can last for some time.

Great you do put such a big effort in this module. I really appreciate it.

pivica’s picture

Hey promes,

Ah its not that big effort, just finding time to do it is a problem ;)

Anyway I attached a new patch for D6 version and packed for you patched D6 module version with new images so you can test more easily. And yes I was right problem is in that file_create_url() it is not working the same in D6, here is how icon path code for D6 should look for example:

'icon' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'gmap3_tools') . '/images/druplicon-green.png',

So icon and shadow properties - they are just plain URLs to your image you wanna use, for example on my local test install in browsers JS they look like this

shadow: "http://localhost/drupal-6.28/sites/all/modules/gmap3_tools/images/druplicon-shadow.png"

So nothing special there, just check that you are generating correct URLs to your images and that is it.

promes’s picture

Hello pivica,
Thanks for your attachments.
After installing this version the site 2 worked correctly. See: http://www.vriendenvanbeeckestijn.nl/plattegrond.
But site 1 refused to show the correct icons.
I checked the difference in installed modules between site 1 and 2. After disabling module PHPIDS your module worked as promised. After enabling PHPIDS again it still is working. Maybe your module must always be enabled before PHPIDS??
Great! See my result for site 1: http://www.golfenopstraat.nl/plattegrond-route-1-en-2.

I created a new function in gmap3_tools.inc to hide the implementation differences between Drupal version 6 and 7 and to ease the implementation in maps. My proposal for D6 is:

/**
 * Create an image URL
 * This is the URL of an image, mostly an icon, in the tools image map
 * 
 * @param string $image
 */
function gmap3_tools_get_image_url($image) {
  return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'gmap3_tools') . '/images/' . $image;
}

I found out, the $GLOBALS['base_url'] . '/' . is not neccesary.

There is a small typo in gmap3_tools.inc is: stirng.

As you can see in http://www.golfenopstraat.nl/plattegrond-route-1-en-2: the shadow is not correctly aligned. The shadow comes from the gmap implementation and is equal to: http://labs.google.com/ridefinder/images/mm_20_shadow.png. I still have to manipulate the shadow.png to get it aligned.

Is it possible to define in the new array in gmap3_tools_create_marker() a shadow as well, since the large pin gets the default small shadow as well?

Since the Drupal code grows and grows the trend is to keep as much as possible code out of the modules and place this in a separated .inc. I propose to do this as well with the example in the module and place it in a admin.inc with a switch to enable/disable the display. The example is very usefulle to test whether te module is working, but after that it is not that interesting.

I am sorry I put unrelated issues in this issue.

Thanks for your help. I will implement it in my other sites in coming months. When I have a D5 version, I will upload it.

pivica’s picture

> Maybe your module must always be enabled before PHPIDS??

Never user phpids module and I think they should not be related in any case... Sorry can not give you more info on this.

> I created a new function in gmap3_tools.inc to hide the implementation

Well code in gmap3_tools.module file is just an example code, also that

$GLOBALS['base_url'] . '/' . drupal_get_path('module', 'gmap3_tools') . '/images/druplicon-green.png'

Is only for showing example code so there is really no need for some helper wrapper function or anything else. In your code you just need to pass proper URL to your icons and that is it - this icons should not be in gmap3_tools module.

> There is a small typo in gmap3_tools.inc is: stirng.

thx

> I still have to manipulate the shadow.png to get it aligned.

Yes this is currently not supported - so you need to change shadow.png which is little ugly. I created new feature request for this on http://drupal.org/node/1918180.

> Is it possible to define in the new array in gmap3_tools_create_marker() a shadow as well, since the large pin gets the default small shadow as well?

Yes sure you can. This two arrays (default) and per marker will be merged and values for marker should override values from default markerOptions array.

> Since the Drupal code grows and grows the trend is to keep as much as possible code out of the modules and place this in a separated .inc.

Yeah, but currently in gmap3_module file there is really no real code at all, just example code - and you can completely disable module and still include and use gmap3_tools.inc file where you need. That is why that example code is still in module - if some other code land in module file (and by design it should not) then we can refactore it and move example to separate file.

> I am sorry I put unrelated issues in this issue.

No problem, it is good when you have a feedback :)

pivica’s picture

Status: Needs review » Fixed

Commited to D6 and D7 dev branches.

promes’s picture

> I created a new function in gmap3_tools.inc to hide the implementation

Well code in gmap3_tools.module file is just an example code, also that

$GLOBALS['base_url'] . '/' . drupal_get_path('module', 'gmap3_tools') . '/images/druplicon-green.png'

Is only for showing example code so there is really no need for some helper wrapper function or anything else. In your code you just need to pass proper URL to your icons and that is it - this icons should not be in gmap3_tools module.

I didn't create the helper function for your example code, but for all users of the module. Why? When the helper function is present and I use your module in D6 and go to upgrade the site to D7 I don't have to update my own implementation, I just can use the helper function to get the correct image URL.
Otherwise I have to update from D6:
icon = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'gmap3_tools') . '/images/my_icon.png';
to D7:
icon = file_create_url(drupal_get_path('module', 'gmap3_tools') . '/images/my_icon.png';

With the helper function, I can, in my map, use both in D6, D7 and future versions:
icon = helper_function('my_icon.png');
See: no conversion needed! The Drupal version differences are hidden.

I still are very happy with your help and effort in this module.

pivica’s picture

But your proposition

function gmap3_tools_get_image_url($image) {
  return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'gmap3_tools') . '/images/' . $image;
}

is hard coded to use only images inside of gmap3_tools module. What is a purpose of this then? You should put your custom icons in your own custom module or your theme implementation, or pull it somewhere from the web - in either case this gmap3_tools_get_image_url() wrapper will not help you because it can only load icons from gmap3_tools/images folder.

promes’s picture

Hello pivica,

You are right.
I am using your module without writing a module. I just create a new node and create the map using php code. This is faster then to create a specific module for each site.
And up till now I put the images in the image map of your module to keep everything together. But this isn't a common way how to work.

pivica’s picture

No need to write a module for your simple use case. Just put your icons in sites/default/files (or any other place you like) and that is it. If you put icons in gmap3_tools or change gmpa3_tools code because of that you will have problems with upgrading.

promes’s picture

You are right. I did this allready today and installed the tool in several sites.
I think we can close this issue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.