Skip to content

Commit

Permalink
Add lat and lng atts to image-map shortcode (bozdoz#163)
Browse files Browse the repository at this point in the history
* Add lat and lng atts to image-map shortcode

* Add lat and lng atts to image map shortcode

* add lat and lng to image map shortcode if itn

* updates leaflet-image x,y to be backward compatible

Co-authored-by: bozdoz <[email protected]>
  • Loading branch information
AK-digital and bozdoz authored Dec 30, 2022
1 parent 858ca5a commit 7c23748
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ Then in the console, check the coordinates when you move the marker (should only
| `min_zoom` | 0 |
| `max_zoom` | 20 |
| `attribution` | ©Leaflet ©OpenStreetMap |
| `x` | 0 |
| `y` | 0 |

---

Expand Down
5 changes: 4 additions & 1 deletion shortcodes/class.image-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ protected function getHTML($atts='', $content=null)
{
extract($this->getAtts($atts));

$x = empty($x) ? 0 : $this->LM->filter_float($x);
$y = empty($y) ? 0 : $this->LM->filter_float($y);

/* only required field for image map (src/source) */
$src = empty($src) ? '' : $src;
$source = empty($source) ? 'https://picsum.photos/1000/1000/' : $source;
Expand All @@ -48,7 +51,7 @@ protected function getHTML($atts='', $content=null)
var image_src = '<?php echo htmlspecialchars($source, ENT_QUOTES); ?>';
var img = new Image();
var zoom = <?php echo $zoom; ?>;
var map = window.WPLeafletMapPlugin.createImageMap(options).setView([0, 0], zoom);
var map = window.WPLeafletMapPlugin.createImageMap(options).setView([<?php echo $x; ?>, <?php echo $y; ?>], zoom);
img.onload = function() {
var h = img.height,
w = img.width,
Expand Down

0 comments on commit 7c23748

Please sign in to comment.