androlax2 / acf-image-map
An ACF field to map shapes in image.
Installs: 106
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 2
Open Issues: 8
Language:JavaScript
Type:wordpress-plugin
Requires
- php: >=7.3
- illuminate/collections: ^8.58 || ~9.0
Requires (Dev)
- paulthewalton/acf-pro-stubs: 5.8.9.1
- paulthewalton/acf-stubs: ^5.8
- phpmd/phpmd: ^2.10
- slevomat/coding-standard: ^8.15
- squizlabs/php_codesniffer: ^3.6
- szepeviktor/phpstan-wordpress: ^1.3
- dev-master
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/composer/illuminate/collections-tw-11.26.0
- dev-dependabot/npm_and_yarn/webpack-5.95.0
- dev-dependabot/npm_and_yarn/sass-1.79.4
- dev-dependabot/npm_and_yarn/postcss-8.4.47
- dev-dependabot/npm_and_yarn/npm_and_yarn-19f3e7cf70
- dev-dependabot/npm_and_yarn/postcss-nested-6.2.0
- dev-dependabot/npm_and_yarn/multi-8f9f88cd17
- dev-dependabot/npm_and_yarn/gulp-5.0.0
This package is auto-updated.
Last update: 2024-11-07 02:41:42 UTC
README
Requirements
Installation
Bedrock
Install via Composer:
$ composer require androlax2/acf-image-map
Manual
Download the release .zip
and install into wp-content/plugins
.
Usage
First you need to define an image that will be used to add different shapes on it.
Shapes
You can use different shapes, for now you can use polygon and points. On the front end :
- It will return an array with your coords in an
area_coords
for the polygon, - It will return an array with the point coord in an
x
&y
for the point.
ACF Composer
If you are using ACF Builder :
Point
$field ->addImage('my_image') ->addField('my_point_coords', 'image_map', [ 'image_field_label' => 'my_image', 'shape' => 'point', 'percentage' => true, ]);
Polygon
$field ->addImage('my_image') ->addField('my_poly_coords', 'image_map', [ 'image_field_label' => 'my_image', 'shape' => 'poly', ]);
HTML
Point
For the point, you have the x
and y
coords.
Let's imagine that we have the fields defined above:
$field ->addImage('my_image') ->addField('my_point_coords', 'image_map', [ 'image_field_label' => 'my_image', 'shape' => 'point', 'percentage' => true, ]);
So we would have an HTML structure that would look like this to display our point on the image:
$image = get_field('my_image'); $point = get_field('my_point_coords'); <div style="position: relative;"> <img src="<?php echo $image['url']; ?>"> <span style=" position: absolute; top: <?php echo $point['y']; ?>; left: <?php echo $point['x']; ?>" ></span> </div>
Poly
You use poly to create a map on the image a priori, so here is an HTML code to achieve this:
Let's imagine that we have the fields defined above:
$field ->addImage('my_image') ->addField('my_poly_coords', 'image_map', [ 'image_field_label' => 'my_image', 'shape' => 'poly', ]);
So we would have an HTML structure that would look like this to display our area on the image:
$image = get_field('my_image'); $poly = get_field('my_point_coords'); <div style="position: relative;"> <img src="<?php echo $image['url']; ?>" usemap="#map"> <map name="map"> <area coords="<?php echo $poly['area_coord']; ?>" shape="poly"></area> </map> </div>
Be careful, the coordinates of the area are defined in relation to the maximum size of the image. In responsive, this will not work, you have to recalculate the coordinates.
To do this automatically and easily, I recommend this package
Bug Reports
If you discover a bug in ACF Image Map, please open an issue.
Contributing
Contributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated.
License
ACF Image Map is provided under the MIT License.