Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom data to marker #16

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client-side/googleMapAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ GoogleMap.prototype = {
marker = new google.maps.Marker({
position: position,
map: base.map,
title: (("title" in markers[i]) ? markers[i]['title'] : null)
title: (("title" in markers[i]) ? markers[i]['title'] : null),
customField: (("customField" in markers[i]) ? markers[i]['customField'] : null)
});

marker.setAnimation(base.doAdmination(item));
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "olicek/google-map-api",
"name": "argonisius/google-map-api",
"type": "library",
"description": "Tool for paste google map to the page with markers",
"keywords": ["google","maps", "nette"],
Expand All @@ -25,4 +25,4 @@
"Oli\\GoogleAPI\\": "src"
}
}
}
}
8 changes: 8 additions & 0 deletions docs/en/markers.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ Set [message](https://developers.google.com/maps/documentation/javascript/exampl

> Message can contains HTML tags

### setCustomField()

```
$markers->setCustomField($customField);
```

Set array of custom properties, which are accessible via JavaScript on `google.maps.Marker` object.

### isMarkerClusterer()

```
Expand Down
22 changes: 22 additions & 0 deletions src/Markers.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ public function setMessage($message, $autoOpen = false)
return $this;
}

/**
* @param array $customField
* @return $this
* @throws LogicException
* @throws InvalidArgumentException
*/
public function setCustomField($customField)
{
if (!count($this->markers))
{
throw new LogicException("setCustomField must be called after addMarker()");
}
if (!is_array($customField))
{
throw new InvalidArgumentException("customField must be array, $customField (".gettype($customField).") was given");
}
end($this->markers); // move the internal pointer to the end of the array
$key = key($this->markers);
$this->markers[$key]['customField'] = $customField;
return $this;
}


/**
* @param bool $cluster
Expand Down