[WordPress] 外掛分享: Advanced Custom Fields: Multiple Coordinates

首頁外掛目錄 › Advanced Custom Fields: Multiple Coordinates
WordPress 外掛 Advanced Custom Fields: Multiple Coordinates 的封面圖片
10+
安裝啟用
★★☆☆☆
2.3/5 分(4 則評價)
34 天前
最後更新
問題解決
WordPress 5.0+ PHP 7.0+ v1.4.0 上架:2013-10-23

內容簡介

Advanced Custom Fields: Multiple Coordinates 是一款為 Advanced Custom Fields 提供多點 Google 地圖功能的外掛。使用者可以在地圖上點擊以新增標記,並可隨意拖動標記位置,方便管理多個地理坐標。

【主要功能】
• 支援多個地圖標記的新增與編輯
• 點擊地圖即可新增標記,並可拖動調整位置
• 搜尋地點並自動在地圖上新增標記
• 每個標記可顯示編號、經緯度及名稱
• 透過 ACF 全域設定自動讀取 Google Maps API 金鑰

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.4.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Advanced Custom Fields: Multiple Coordinates」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

A multi-point Google Maps field for Advanced Custom Fields. Click the map to drop a point and drag it to move it. “Edit points” opens the list of points, where a point can be dragged to a new position or removed. Every point is numbered so the stored order is visible — it is the order the value is stored in and the order the line or area is drawn in — and the last change can always be undone.
The plugin reads your existing Google Maps API key from ACF’s global setting (google_api_key), so no extra configuration is needed if you already use ACF Map fields. If you don’t have one set, you can also provide a key via the acfmc_gmaps_key filter.
Originally inspired by the single-point ACF: Coordinates field by Stupid Studio; this plugin extends the idea to multiple points per field.
Licensed under the GNU General Public License v3. See license.txt for details.
Usage
When you create a new custom field with ACF, set the field type to Coordinates map (under Content). The coordinates chooser will then show up when you edit a post with your custom fields.
Adding points. Click anywhere on the map to drop a point. “Add point” drops one in the middle of the map, which is also the way to add points from the keyboard. Drag a point to move it.
Searching for a place. Type a place in the search field and press Enter: the map pans there and a point is dropped on the spot, carrying the name you searched for. Search for “Kalmar slott” and the point is called Kalmar slott, not the street address Google resolves it to. The name is stored with the point and shown in its popup. Points you click straight onto the map have no name — only searched points get one.
Seeing what a point is. Click a marker and a popup shows its number, its latitude and longitude, and its name when it has one. Nothing is looked up when you click; the popup only shows what is already stored.
Editing the points. “Edit points (N)” opens the list of points, and that is where a point is changed:

Drag a row by its handle to move the point to another position. The order is not decoration — it is the order the value is stored in, the order get_field() returns and the order the line or area is drawn in, so the map is renumbered and redrawn as soon as you drop the row.
The same handle works from the keyboard: tab to it and press the up or down arrow key.
Press Remove on a row to delete that point.

Undo. The undo icon takes back the last change — an accidental point, a removed point, a reordered list, or a marker dragged to the wrong place. It goes back up to 30 steps, until the page is reloaded.
Drawing a shape. The first menu says what is drawn through the points: nothing, a Line or an Area. Pick either one and a second menu says how it is drawn:

Sharp — straight segments from point to point, in stored order.
Smoothed — a Catmull-Rom curve through every point. Google Maps has no curves of its own, so it is drawn as a dense polyline; an area closes the curve back to the first point.
Bounding box — the rectangle the points span, ignoring the path between them.

A line is the outline only; an area is filled. So a bounding box drawn as a line is an empty rectangle around the points, and the same box drawn as an area is a filled one. Choosing a shape also reveals a colour picker and a Markers switch, and the map redraws as soon as you change any of them.
The Markers switch. It controls the front end: turn it off and your theme should draw only the line or the area, without the markers — which is the point of it, since a clean route or outline is often what you want. In the editor the markers stay visible, dimmed, because points you cannot see are points you cannot drag, click or reorder. The switch only appears once a shape is chosen; with no shape the markers are all there is to draw.
The rest. The <> icon reveals and selects the raw stored value so it can be pasted into another Coordinates map field, and the i icon lists what the field can do.
Saving works the way it always has: the value is stored as JSON in postmeta, so field groups and values created with earlier versions keep working unchanged.
This plugin does not render anything on the front end. It stores points; drawing them is the theme’s job. ACF’s own [acf field="..."] shortcode returns an empty string for this field type, so the examples below are the starting point — copy one into your theme and adjust it.
Reading the value. get_field() gives you the points in the order they are stored, plus the zoom level and, when a shape was chosen, the shape, how it is drawn, its colour and whether the markers should be drawn with it:
Array
(
[0] => Array
(
[lat] => 57.156363766336
[lng] => 16.364327427978
)
[1] => Array
(
[lat] => 57.159612809986
[lng] => 16.370315551758
[label] => Kalmar slott
)
)
[zoom] => 13
[shape] => line
[style] => smoothed
[color] => #c84812
[markers] =>
)
*/
?>

label, `shape`, `style`, `color` and `markers` are all optional. A point that was clicked onto the map has no `label`. A value with no `shape` — which is every value saved before version 1.4.0 — draws no line and no area at all, only the points. `style` is `sharp`, `smoothed` or `bbox` and defaults to `sharp`; `color` defaults to `#999999`; `markers` is only written when it is *off*, so a missing `markers` means the markers should be drawn.

Rendering a map. A complete example that draws the markers, unless they are switched off, and whichever shape was chosen, in the chosen colour. It needs your own Google Maps API key:
$coords,
'zoom' => isset($value['zoom']) ? (int) $value['zoom'] : 11,
'shape' => isset($value['shape']) ? $value['shape'] : 'none',
'style' => isset($value['style']) ? $value['style'] : 'sharp',
'color' => isset($value['color']) ? $value['color'] : '#999999',
// markers are drawn unless the value explicitly says otherwise
'markers' => ! isset($value['markers']) || $value['markers'],
);
?>



Rendering without a map. If you only want the coordinates as text, no API key and no JavaScript are needed:
';
foreach ( $value['coords'] as $i => $point ) {
$label = isset($point['label']) ? $point['label'] : '';
printf(
'

  • %s`%s, %s`
  • ',
    $label ? '' . esc_html($label) . ' ' : esc_html( ( $i + 1 ) . '. ' ),
    esc_html($point['lat']),
    esc_html($point['lng'])
    );
    }
    echo '

    ';
    }
    ?>

    Both examples work unchanged on values saved by version 1.0: a missing label prints only the coordinates, and a missing shape draws the markers on their own.

    延伸相關外掛

    文章
    Filter
    Mastodon