use of com.codename1.googlemaps.MapContainer.MarkerOptions in project codenameone-google-maps by codenameone.
the class MapContainer method addMarker.
/**
* Adds a marker to the map with the given attributes
* @param opts The marker options.
* @return marker reference object that should be used when removing the marker
*/
public MapObject addMarker(MarkerOptions opts) {
// public MapObject addMarker(EncodedImage icon, Coord location, String text, String longText, final ActionListener onClick) {
EncodedImage icon = opts.getIcon();
Coord location = opts.getLocation();
String text = opts.getText();
String longText = opts.getLongText();
ActionListener onClick = opts.getOnClick();
if (internalNative != null) {
byte[] iconData = null;
if (icon != null) {
iconData = icon.getImageData();
internalNative.setMarkerSize(icon.getWidth(), icon.getHeight());
}
long key = internalNative.addMarker(iconData, location.getLatitude(), location.getLongitude(), text, longText, onClick != null, opts.anchorU, opts.anchorV);
MapObject o = new MapObject();
o.mapKey = key;
o.callback = onClick;
markers.add(o);
return o;
} else {
if (internalLightweightCmp != null) {
PointLayer pl = new PointLayer(location, text, icon);
if (points == null) {
points = new PointsLayer();
internalLightweightCmp.addLayer(points);
}
points.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
PointLayer point = (PointLayer) evt.getSource();
for (MapObject o : markers) {
if (o.point == point) {
if (o.callback != null) {
o.callback.actionPerformed(new ActionEvent(o));
}
evt.consume();
return;
}
}
}
});
points.addPoint(pl);
MapObject o = new MapObject();
o.point = pl;
o.callback = onClick;
markers.add(o);
internalLightweightCmp.revalidate();
return o;
} else {
String uri = null;
int iconWidth = 0;
int iconHeight = 0;
int anchorU = 0;
int anchorV = 0;
if (icon != null) {
uri = WebBrowser.createDataURI(icon.getImageData(), "image/png");
iconWidth = icon.getWidth();
iconHeight = icon.getHeight();
anchorU = (int) (icon.getWidth() * opts.anchorU);
anchorV = (int) (icon.getHeight() * opts.anchorV);
}
// browserBridge.waitForReady();
MapObject o = new MapObject();
o.callback = onClick;
o.pending = true;
final String fUri = uri;
final int fIconWidth = iconWidth;
final int fIconHeight = iconHeight;
final float fAnchorU = anchorU;
final float fAnchorV = anchorV;
browserBridge.ready(() -> {
internalBrowser.execute("callback.onSuccess(" + BRIDGE + ".addMarker(${0}, ${1}, ${2}, ${3}, ${4}, ${5}, ${6}, ${7}, ${8}))", new Object[] { // long key = ((Double)browserBridge.bridge.call("addMarker", new Object[]{
fUri, location.getLatitude(), location.getLongitude(), text, longText, fIconWidth, fIconHeight, fAnchorU, fAnchorV }, jsres -> {
o.mapKey = jsres.getInt();
o.pending = false;
});
});
// MapObject o = new MapObject();
// o.mapKey = res.getInt();
// o.callback = onClick;
markers.add(o);
// System.out.println("MapKey added "+o.mapKey);
return o;
}
}
}
use of com.codename1.googlemaps.MapContainer.MarkerOptions in project codenameone-google-maps by codenameone.
the class MapLayout method installMarkerFor.
private void installMarkerFor(Component c) {
MapObject marker = (MapObject) c.getClientProperty(MARKER_KEY);
if (marker != null) {
map.removeMapObject(marker);
markers.remove(marker);
c.putClientProperty(MARKER_KEY, null);
}
Image im = generateMarkerImage(c);
if (im == null) {
return;
}
EncodedImage img = EncodedImage.createFromImage(generateMarkerImage(c), false);
Float h = (Float) c.getClientProperty(HORIZONTAL_ALIGNMENT);
if (h == null) {
h = 0f;
}
Float v = (Float) c.getClientProperty(VERTICAL_ALIGNMENT);
if (v == null) {
v = 0f;
}
MarkerOptions markerOpts = new MarkerOptions((Coord) c.getClientProperty(COORD_KEY), img).anchorU(h).anchorV(v);
marker = map.addMarker(markerOpts);
c.putClientProperty(MARKER_KEY, marker);
markers.add(marker);
}
Aggregations