2009年12月7日星期一

How to fetch the path of marker icon from gmap_marker.js

Note: About how to add new marker icon for gmap, please see this
(关于如何在gmap module里添加新的marker icon的方法,请看 这里)

The path of file stores marker icon info (as json data): sites/default/files/js/gmap_marker.js
(marker icon 的图标地址,在sites/default/files/js/gmap_marker.js文件下。)

In this js file, there are two variables:
1), Drupal.gmap.iconpath the path of marker icon folder ( eg: gmap/marker )
2), Drupal.gmap.icondata it's a json data

eg: { "/small/": { "f": [ "shadow.png", …………

Example:
1), get the value "/small/"
=============================
for(var key in Drupal.gmap.icondata)
{
var file = Drupal.gmap.icondata[key];
// key value: /small
// file value: { "f": [ "shadow.png", …………
}
=============================
(要取出子目录"/small", for(var key in Drupal.gmap.icondata), 这里的key就能取到"/small"
而 Drupal.gmap.icondata[key]的值就是{ "f": [ "shadow.png", …………
以此类推,便能将其中的所有的值一一对应取出。)

The code we use:
(代码如下):
=============================
for (var key1 in Drupal.gmap.icondata) {
for (var key2 in Drupal.gmap.icondata[key1].i) {
for (var key3 in Drupal.gmap.icondata[key1].i[key2]){
for(var key4 in Drupal.gmap.icondata[key1].i[key2][key3][0]){
marker_icons[Drupal.gmap.icondata[key1].i[key2][key3][0][key4]] = key1 + Drupal.gmap.icondata[key1].f[Drupal.gmap.icondata[key1].i[key2][key3][2][key4]];
}
}
}
}
===============================
As what we need is just the path of marker icon ( not include the shadow icon and other parameters), so we just fetch two values.
(因为我们需要的只是marker icon 的文件地址(不包括起阴影和其他icon的参数设置)故只取两个值。)

marker_icons[key] is the path of marker icon
key is the category name we used in module function
Example: school
===============================
for(var key in marker_icons)
{
if(key=="school")
icon_path = Drupal.gmap.iconpath + marker_icon[key];
}
===============================





2009年12月5日星期六

How to adjust zoom automatically in gmap (自动调整zoom值的方法)

We just need to use the object GLatLngBounds in Google Map API.

Exmaple:
var bounds = new GLatLngBounds();

//Repeat the following lines,add all makers' latitude and longitude into bounds object
var point = new GLatLng(parseFloat(marker_latitude),parseFloat(marker_longitude));
bounds.extend(point);

//The gmap here is the GMap2 Object you have defined. (这里的gmap就是你的GMap2对象。)
//Of couse, you can use gmap.getBoundsZoomLevel(bounds) +/- n to modify the zoom you like.
gmap.setZoom(gmap.getBoundsZoomLevel(bounds));

PS: If the zoom>12, there will be same shades on the kililfi map.(http://pg03.anypg.com/plan)
(关于非洲地图上的阴影问题,把默认的最大zoom值改成12就行了。)
Example:
var zoom = gmap.getBoundsZoomLevel(bounds);
if(zoom>12)
zoom = 12

Note: the larger the zoom value is, the more detail will be showed on the map.
(注意:zoom值越大,地图被放大的倍数也越大)