Skip to content

Adding Static Maps API#413

Merged
domesticmouse merged 21 commits intogooglemaps:masterfrom
domesticmouse:master
Apr 9, 2018
Merged

Adding Static Maps API#413
domesticmouse merged 21 commits intogooglemaps:masterfrom
domesticmouse:master

Conversation

@domesticmouse
Copy link
Copy Markdown
Contributor

Fixes #233.

Also contains random clean ups and fixes, e.g. #412

@domesticmouse domesticmouse requested a review from samthor April 8, 2018 06:02
private static final long serialVersionUID = 1L;

/** The image data from the Photos API call. */
public final byte[] imageData;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is really what you want, in that byte[] is still mutable. But I can't think of a better approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ImageResult is an output value object. If a client of this library alters the image data, it has no impact on the library.

* brown, green, purple, yellow, blue, gray, orange, red, white}.
*/
public void color(String color) {
if (!colorPattern.matcher(color).matches()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth enforcing this locally? We might allow more colors in future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair call, ripped out regex

private String label;
private String customIconURL;
private CustomIconAnchor anchorPoint;
private List<String> locations = new ArrayList<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private final, you don't ever change this ref

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

private String color;
private String fillcolor;
private boolean geodesic;
private List<String> points = new ArrayList<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private final

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* appear in its default thickness (5 pixels).
*/
public void weight(int weight) {
this.weight = weight;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should setting this to zero clear the Integer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Implemented in toUrlValue()

this.height = height;
}

/** Serialisation constructor. */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

american spelling, s => z

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import com.google.maps.model.Size;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import javax.imageio.ImageIO;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this library only pulled in for testing? Do we have it for the regular lib?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only use it in the test library to make sure we can round trip an image. I'm not decoding the image in the main library to keep up throughput.

protected A param(String key, int val) {
params.put(key, Integer.toString(val));

@SuppressWarnings("unchecked") // safe by specification - A is the actual class of this instance
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: could you replace these three returns with

private A getInstance() {
  @SuppressWarnings("unchecked");
  return (A) this;
}

// later
return this.getInstance();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, done. Ish.

Copy link
Copy Markdown
Contributor

@samthor samthor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just let me know your thoughts on the 'set' vs 'add' problem you have now.


protected A param(String key, String val) {
params.put(key, val);
if(params.get(key) == null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing space if (

protected A param(String key, String val) {
params.put(key, val);
if(params.get(key) == null) {
params.put(key, new ArrayList<String>());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks naïvely fine but I wonder if anyone is using this class to overwrite previous values being set via .param().

Would it be worth having an explicit 'add' flag somehow? I know you already have the three param methods, so a matrix of those would be awkward. Let me know.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, yes I was being naive. There was logic in optimise waypoints that implicitly relied on that underlying hashmap behavior of the parameters.

New implementation now enforces singleton parameters (as implicitly required by non Static Maps API surfaces), and just uses the multiple parameters for Static Maps paths and markers.

Now the tests pass...

paramsFound++;
}
}
assertTrue(paramsFound == expectedValues.size());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not assertEquals?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed.

Copy link
Copy Markdown
Contributor

@samthor samthor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🎉

@domesticmouse domesticmouse merged commit 9b54a6f into googlemaps:master Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google Static Maps API support

2 participants