2009年11月19日星期四

How to add a custom marker icon in Gmap module (添加自定义marker图标的方法)

Principle:go Administer -> site configuration -> Gmap -> Regenerate marker cache, click button Regenerate. The model will auto seach all the .ini files in the folder gmap/marker, and generate sites/default/js/files/gmap_markers.js, which contain all the info of marker icons.
(原理:在Administer -> site configuration -> Gmap 页面上,有一个 Regenerate marker cache ,点击Regenerate按钮,模块会自动搜索gmap/marker文件夹下的.ini的文件,利用文件的信息生成sites/default/js /files/gmap_markers.js文件。gmap模块就是利用这个js文件来生成marker的图标路径的。)

Method One (Easy and quick)
方法一(简单方法,快速):

1, Copy your .png image file to gmap/marker (将要添加的.png 的图像文件copy到gmap/marker文件夹下。)

2, Find an appropriate .ini file in gmap/marker(在gmap/marker文件夹下,寻找一个合适的.ini文件。)
Note: the markers in the same .ini, share the same shadow image.(注:不同的.ini文件的不同主要是在shadow icon上,记录在同一个.ini文件下的图标,共用一个shadow icon。)

Example:open colors.ini

Add the followings after “; Marker sets”(在 “; Marker sets” 的下一行添加如下内容)
===========================
[school icon]
name = "School Icon"
sequence = "schoolicon.png"
===========================

[school icon] is the index(应该可以这样理解吧?
Exampel: If you want to use this icon, the code will be like $marker_icon = 'school icon';
(如果你要使用这个图标,那么 $marker_icon = 'school icon';)

name = "School Icon" is just the name (就是一个名称,目前没发现它的作用。)

sequence = "schoolicon.png" is the file name of the image you just added(这里的schoolicon.png就是你刚刚添加的marker icon的文件名。)

3,Save the .ini file

4,Open Administer -> site configuration -> Gmap, click Regenerate
Note:This step may cause a failure, could not read schoolicon.png (这时候可能会报错,说不能读取 schoolicon.png。原因是copy到marker文件夹下的图标,读的权限受限制。)
You need to change the permission
$ chmod a+r schoolicon.png


5,Now you can try your new adding marker icon

Method Two: (build your own icon folder)
方法二:(自己建一个文件夹,存放用户自定义的图标)

1,Create a new folder in gamp/marker, such as user ( 在gmap/marker文件夹下,创建一个文件夹。)
2,Create a new ini file with the same name of folder, such as user.ini (在user文件夹下创建一个同名的ini文件,user.ini。注意:一定要同名才行。)
3,Open user.ini
Add like following:
==================
; Defaults
[defaults]
shadow = ""
anchorX = 10
anchorY = 29
infoX = 17
infoY = 3

; Marker sets


; Files
==================

[defaults] is the define for shadow icon
shadow = "" is the file name of shadow

4,Add new marker icon info after ; Marker sets

5, Repeat the steps on method one

没有评论:

发表评论