zoom in location map block

hedac - November 11, 2007 - 12:26
Project:GMap Module
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:patch (code needs review)
Description

I installed last update 2007-Nov-08 , and now in the location map block.. the maps are with maximum zoom. If i change the configuration of the block, it changes everything.. but not the zoom...

also it seems that the markers per user un the users map.. don't work either now.. only drupal marker is shown. and before was different markers per role.

#1

Michael Hofmockel - November 29, 2007 - 03:37

The auto zoom function is great when you have more than one location to map. But when there is only on point, the auto zoom drills down too far.

The auto zoom is hard coded to "true" in gmap_location.
I set to false but then the map did not have a center.
So I added the lat/long values as the center.

I've patched my file so line numbers may be off but close.
around line 630

gmap_location.module,v 1.26.2.45 2007/11/08 22:22:11 bdragon

attached is my version.

or you can see my changes of the tail of the "function gmap_location_block_view" below.

//turned auto zoom off.  With just one point the map drills down too far.  mhofmockel
      $map['behavior']['autozoom'] = false;
      $map['behavior']['notype'] = true;
      $map['controltype'] = 'None';
//added 2 lines Lat/long to center map properly.  With autozoom off the map has no center.  mhofmockel
$map['latitude'] = $loc['latitude'];
$map['longitude'] = $loc['longitude'];
      $block['subject'] = t('Location');
      $block['content'] = theme('gmap', array('#settings' => $map));
    }
  }
  return $block;
}

AttachmentSize
gmap_location.module28.72 KB

#2

hedac - November 29, 2007 - 21:41
Status:active» fixed

thank you mhofmockel !
That solved the problem. I didn't realize that it started to happen when I turned on the autozoom
it's very nice now

#3

mgmeskill - December 12, 2007 - 03:22

This helped me a ton - I wonder if this will be adjustable through the admin interface at some point?

#4

Zoologie.de - December 13, 2007 - 04:37

While the autozoom worked fine out of the box in Firefox, it didn't in IE.. that solved it. thanks

#5

sopia - December 19, 2007 - 02:42
Status:fixed» active

I uploaded this new file, cleared views cache, and ran update.php. Still having the same problem. No zoom, no control, and zoomed way in on location block. I also turned off autozoom. map/node comes out fine.

Did I miss something? Could someone share the map code you use for the location block? Maybe that's it?

#6

hedac - December 19, 2007 - 08:17

try setting autozoom off... or use mhofmockel code above

#7

sopia - December 19, 2007 - 23:19

Thanks, I did both, and still no luck :( I'll let you guys know if I ever figure it out, you do the same, please.

Happy coding everybody!

#8

Summit - December 24, 2007 - 13:29

Hi,

I still also have the problem that the gmap_location module sooms out in too much detail. To maximum level.
I changed code like stated on: http://drupal.org/node/191223#comment-642765
So autozoom is still on I pressume?

When I edit a node I see the right MAP:

<script type="text/javascript">
/* <![CDATA[ */
Drupal.extend({ settings: { "gmap": { "loc1": { "width": "300px", "height": "200px", "zoom": 3, "controltype": "Small", "align": "None", "maptype": "Map", "line_colors": [ "#00cc00", "#ff0000", "#0000ff" ], "behavior": { "locpick": true }, "markermode": "0", "macro": "[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]", "header": "This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.", "footer": "", "id": "loc1", "querypath": "http://../map/query", "longitude": "82.6171875", "latitude": "28.149503211544566" } } } });
/* ]]> */
</script>

But when I view the node I see the following script. Notice the Zoom: 15!!

<script type="text/javascript">
/* <![CDATA[ */
Drupal.extend({ settings: { "gmap": { "loc1": { "width": "100%", "height": "400px", "zoom": 15, "controltype": "Small", "align": "None", "maptype": "Map", "line_colors": [ "#00cc00", "#ff0000", "#0000ff" ], "behavior": { "locpick": false, "nodrag": 0, "nokeyboard": 1, "nomousezoom": 0, "autozoom": 0, "dynmarkers": 0, "overview": 1, "notype": 0, "collapsehack": 0, "scale": 0, "fatmarkers": false }, "markermode": "0", "longitude": "85.341797", "latitude": "27.839076", "markers": [ { "options": [  ], "text": "Test node", "longitude": "85.341797", "latitude": "27.839076", "markername": "blue", "offset": 1 } ], "id": "loc1", "querypath": "http://../map/query" } } } });
/* ]]> */
</script>

This is driving me nuts.. Does anybody have a solution please?

Thanks in advance!
greetings,
Martijn

#9

Summit - December 24, 2007 - 15:21
Status:active» closed

Hi,

I found my problem!
It was an other module which did this the Gmap macro calling. And in that module the zoom level was set to 15.

Sorry to bother you.

Greetings,
Martijn

#10

hedac - January 5, 2008 - 22:57
Status:closed» patch (code needs work)

in gmap_location.module,v 1.26.2.52 2007/12/29
is in line 673

just change to false and add the latitude and longitude:

$map['behavior']['autozoom'] = false;
$map['latitude'] = $loc['latitude'];
$map['longitude'] = $loc['longitude'];

#11

sopia - January 9, 2008 - 00:06

This isn't working for me. Anybody have any luck?

Still can't zoom it out.

#12

sopia - January 15, 2008 - 18:14
Priority:normal» critical
Status:patch (code needs work)» active

Still can't get it to work :( Anybody having any luck?

#13

Bill.Roehl - January 16, 2008 - 21:30
Priority:critical» minor

I had to do this:

      $map['behavior']['autozoom'] = false;
      $map['behavior']['notype'] = true;
      $map['latitude'] = $loc['latitude'];
      $map['longitude'] = $loc['longitude'];
      $map['controltype'] = 'Small';

Because there was not even a control on the map regardless of what GMap setting I chose. This made it work sorta like the way it used to at least.

#14

chaloalvarezj - January 17, 2008 - 08:14

Gmap version = "5.x-1.0-alpha1"
/* $Id: gmap_location.module,v 1.26.2.52 2007/12/29 01:02:55 bdragon Exp $ */
Function: gmap_location_block_view($nid)

To get Control to display, had to comment lines 674 and 675:

Before

      $map['behavior']['notype'] = true;
      $map['controltype'] = 'None';

After:

      //$map['behavior']['notype'] = true;
      //$map['controltype'] = 'None';

This lines were overriding the macro settings.

Hope this has been solve on the next versions...

#15

caprenter - January 17, 2008 - 13:56

Just a thank you. This worked for me.

#16

Bill.Roehl - January 17, 2008 - 19:14

chaloalvarezj,

Sweet, that's a much better solution. Thanks!

#17

smitty - February 3, 2008 - 18:30

While deliberating on the question, why the code in the function gmap_location_block_view is like it is, I found two reasons:

  • get default values.
  • fit several markers into the block (if the node has several locations).

Default values are a very good thing, but here they are set after the macros are interpreted. So if in a macro a value is provided, it will be overwritten. The solution could be to check, if the macro has provided a value and only to set the default values if it hasn’t.

On the other hand the “autozoom” is only needed to fit several markers into the block, if the node has several locations (well, perhaps there may be a better solution to fit the markers in, but I am not experienced with this). If it hasn’t, it is not necessary to overwrite the value provided by the macro.

So I came to the following code:

    if (!empty($markers)) {
      if (strlen(variable_get('gmap_location_block_macro_'. $node->type, '')) > 0) {
        $macro = variable_get('gmap_location_block_macro_'. $node->type, '');
      }
      else {
        $macro = variable_get('gmap_location_block_macro', '[gmap |id=block0 |zoom=10 |width=100% |height=200px |control=Small |type=Map |behavior=+autozoom,+notype] ');
      }
      $map = gmap_parse_macro($macro);
      $map['markers'] = $markers;
      if (!isset($map['autozoom']) || count($markers)>1) {
        $map['autozoom'] = true;
      }
      if (!isset($map['behavior']['notype'])) {
        $map['behavior']['notype'] = true;
      }     
      if (!isset($map['controltype'])) {
        $map['controltype'] = 'None';
      }     
      if (count($markers)==1) {
        $map['latitude'] = $loc['latitude'];
        $map['longitude'] = $loc['longitude'];
      }
      $block['subject'] = t('Location');
      $block['content'] = theme('gmap', array('#settings' => $map));
    }

Note: I didn’t put the “autozoom” in the $map['behavior']['autozoom'] as in the original code but in the $map['autozoom'] because I saw, that the function gmap_parse_macro($macro) provides this value in $map['autozoom']. I can’t figure out, if this is a bug in the original code or in the function gmap_parse_macro().

Would this be a common solution we could put into the head?

#18

sopia - February 7, 2008 - 21:07

OK, I'll give it a shot. Where exactly did you place this code?

Thanks!

#19

sethcohn - February 8, 2008 - 16:35

Ideally, there should be a setting to allow autozoom, BUT to also set a maximum zoom level. In other words, autozoom but do not zoom past this level, even if only one item (or even 2 or 3 items) is present.

Perhaps the solution is to tweak gmap_marker.js and adjust this:

if (obj.vars.behavior.autozoom) {
      // Init bounds if needed.
      // @@@ Unify bounds between markers and shapes? I really don't think this belongs here.
      if (!obj.bounds) {
        obj.bounds = new GLatLngBounds(marker.marker.getPoint(), marker.marker.getPoint());
      }
      else {
        obj.bounds.extend(marker.marker.getPoint());
      }
      obj.map.setCenter(obj.bounds.getCenter(),obj.map.getBoundsZoomLevel(obj.bounds));
    }

If we set the BoundZoomLevel there, won't that fix it?

#20

sethcohn - February 8, 2008 - 16:49
Priority:minor» normal

After playing with this, the answer is yes, we need to adjust that last line:

obj.map.setCenter(obj.bounds.getCenter(),obj.map.getBoundsZoomLevel(obj.bounds));

Try this (as example):

obj.map.setCenter(obj.bounds.getCenter(),obj.map.getBoundsZoomLevel(obj.bounds)-5);

That will set the zoom to 5 clicks higher up than the 'normal' results. So ideally, we break it out into this [pseudocode]:

ZoomVariable = obj.map.getBoundsZoomLevel(obj.bounds);
If ZoomVariable > MaxZoom we have set, then ZoomVariable=MaxZoom
obj.map.setCenter(obj.bounds.getCenter(),ZoomVariable);

Someone want to write a patch? My javascript is too rusty, and ideally, the MaxZoom should be a new gmap setting.

#21

smitty - February 13, 2008 - 18:55

@sopia: Sorry, I forgot to mention: This snippet replaces the lines 663 - 678 in the gmap_location.module of 5.x-1.0-alpha1.

#22

cglusky - February 18, 2008 - 19:13
Status:active» patch (code needs work)

OK, so I had the same problem but may have found a simpler solution to getting the block macro to work like node and user map macros. I left the comments in but this is how the issue of defaults is handled in the other functions in the module.

/* $Id: gmap_location.module,v 1.26.2.54 2007/12/30 16:21:45 bdragon Exp $ */

lines 682-702

if (!empty($markers)) {
      if (strlen(variable_get('gmap_location_block_macro_'. $node->type, '')) > 0) {
        $macro = variable_get('gmap_location_block_macro_'. $node->type, '');
      }
      /* not required if you do a merge with gmap defaults
      else {
        $macro = variable_get('gmap_location_block_macro', '[gmap |id=block0 |zoom=10 |width=100% |height=200px |control=Small |type=Map |behavior=+autozoom,+notype] ');
      }
      */
      $map = array_merge(gmap_defaults(), gmap_parse_macro($macro));
      //$map = gmap_parse_macro($macro);
      $map['markers'] = $markers;
      // @@@
      //$map['behavior']['autozoom'] = true;
      //$map['behavior']['notype'] = true;
      //$map['controltype'] = 'None';
      $block['subject'] = t('Location');
      $block['content'] = theme('gmap', array('#settings' => $map));
    }
  }
  return $block;

I deleted all macro info in the block configuration and it seems to pick up the gmap defaults just fine. If this tests well I would also suggest that the help text in the block configuration be changed so that users know if nothing is input the gmap defaults will be used.

No idea how to roll a patch - sorry.

#23

cglusky - February 18, 2008 - 19:33
Status:patch (code needs work)» patch (code needs review)

and of course i am assuming that by properly picking up the gmap global defaults and or the macro info in the block config we fix this issue. also changing to CNR and including a patch file.

AttachmentSize
gmap_location_block_view.patch950 bytes

#24

cglusky - February 18, 2008 - 20:53

looks like the defualt values are also set when the form array is configured. starting around lines 568. new to this so not sure id setting default is required. may be another place where we can use the gmap_defaults() to get more consistent results?

#25

akahn - February 19, 2008 - 14:43

Just curious, bdragon, is this functionality (the location map block respecting the macro entered on its configure page) going to make it into the next dev release of gmap.module? Thanks!

#26

cglusky - February 19, 2008 - 15:55

I'll have a new patch up shortly that will be over here:

http://drupal.org/node/223588

it does respect your macro settings but my solution of merging the arrays with defaults may not be how bdragon et al want to handle it.

and my patch is only working if you are not using google's marker manager. have not tested it with cluster.js but it works fine if you select "None" for marker manager in the GMap admin. I'll submit this last as a separate bug.

#27

akahn - February 19, 2008 - 15:58

cglusky, thanks for taking this up. What, exactly, is a marker manager? Each of my location nodes will only have one location, but they will be viewed all on one map via a view occasionally. Do I need to worry about marker managers?
Cheers,
Alex

#28

cglusky - February 19, 2008 - 16:46

alex,
alas, not an expert in marker managers. i do know they help with the display of multiple markers on a map. you can help declutter at certain zooms and cluster nodes when it makes sense. overalll helps with performance and UI.

But I think it's a valid question: When do I need to start using a Marker Manager? Is there a rule of thumb number of nodes/markers per map? Don't know and have not searched around here for the answer. I bet it's been asked before so if you find out let me know. Sorry no time today.

I just uploaded my latest patch here:
http://drupal.org/node/223588

r,
Coby

#29

edg - April 16, 2008 - 07:58

subscribing

#30

bdragon - April 30, 2008 - 21:26

The next snapshot will have a "maximum initial zoom" setting, which autozoom will honor.

 
 

Drupal is a registered trademark of Dries Buytaert.