簡體   English   中英

具有動態生成數字的自定義地圖標記圖標

[英]Custom Map Marker Icons with Dynamically Generated Numbers

我想為我的Google地圖添加編號的地圖標記,目前我正在使用Google Charts API方法動態創建編號的標記。 但是,我無法通過該方法使用自己的圖標。

有沒有一種方法可以使用我自己的自定義地圖標記圖標,然后在其上面覆蓋/有一個數字?

另外,有沒有一種快速的方法來創建從11000個.PNG標記? 就像在Photoshop中進行批處理一樣

我從我寫的文章中借用了此代碼,並對其進行了一些調整。 您應該下載此圖像 ,在Photoshop中對其進行一些編輯,並將其放置在與PHP腳本相同的目錄中。 調整腳本中的數字,直到獲得體面的東西。

<?php
define("FONT_SIZE", 6);                            // font size in points
define("FONT_PATH", "c:/windows/fonts/arial.ttf"); // path to a ttf font file
define("FONT_COLOR", 0x00000000);                  // 4 byte color
                                                   // alpha  -- 0x00 thru 0x7F; solid thru transparent
                                                   // red    -- 0x00 thru 0xFF
                                                   // greeen -- 0x00 thru 0xFF
                                                   // blue -- 0x00 thru 0xFF
$text = $_GET["text"];
$gdimage = imagecreatefrompng("marker.png");
imagesavealpha($gdimage, true);
list($x0, $y0, , , $x1, $y1) = imagettfbbox(FONT_SIZE, 0, FONT_PATH, $text);
$imwide = imagesx($gdimage);
$imtall = imagesy($gdimage) - 14;                  // adjusted to exclude the "tail" of the marker
$bbwide = abs($x1 - $x0);
$bbtall = abs($y1 - $y0);
$tlx = ($imwide - $bbwide) >> 1; $tlx -= 1;        // top-left x of the box
$tly = ($imtall - $bbtall) >> 1; $tly -= 1;        // top-left y of the box
$bbx = $tlx - $x0;                                 // top-left x to bottom left x + adjust base point
$bby = $tly + $bbtall - $y0;                       // top-left y to bottom left y + adjust base point
imagettftext($gdimage, FONT_SIZE, 0, $bbx, $bby, FONT_COLOR, FONT_PATH, $text);
header("Content-Type: image/png");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 24 * 180) . " GMT");
imagepng($gdimage);
?>

我的系統上的示例輸出:

/marker.php?text=9/marker.php?text=99/marker.php?text=999/marker.php?text=AA

現在,您可以使用Google圖表進行此操作。 這是一個示例語法:

(scale|rotation|color|fontsize|bold(b) or normal(_)|text[|line2]
https://chart.googleapis.com/chart?chst=d_map_spin&chld=1.0|0|FF8844|12|_|221B

這是文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM