use of com.codename1.maps.layers.LinesLayer in project codenameone-google-maps by codenameone.
the class MapContainer method addPath.
/**
* Draws a path on the map
* @param path the path to draw on the map
* @return a map object instance that allows us to remove the drawn path
*/
public MapObject addPath(Coord... path) {
if (internalNative != null) {
long key = internalNative.beginPath();
for (Coord c : path) {
internalNative.addToPath(key, c.getLatitude(), c.getLongitude());
}
key = internalNative.finishPath(key);
MapObject o = new MapObject();
o.mapKey = key;
markers.add(o);
return o;
} else {
if (internalLightweightCmp != null) {
LinesLayer ll = new LinesLayer();
ll.addLineSegment(path);
internalLightweightCmp.addLayer(ll);
MapObject o = new MapObject();
o.lines = ll;
markers.add(o);
return o;
} else {
// browserBridge.waitForReady();
StringBuilder json = new StringBuilder();
json.append("[");
boolean first = true;
for (Coord c : path) {
if (first) {
first = false;
} else {
json.append(", ");
}
json.append("{\"lat\":").append(c.getLatitude()).append(", \"lon\": ").append(c.getLongitude()).append("}");
}
json.append("]");
// long key = ((Double)browserBridge.bridge.call("addPathAsJSON", new Object[]{json.toString()})).intValue();
MapObject o = new MapObject();
o.pending = true;
browserBridge.ready(() -> {
internalBrowser.execute("callback.onSuccess(" + BRIDGE + ".addPathAsJSON(${0}));", new Object[] { json.toString() }, jsres -> {
o.mapKey = jsres.getInt();
o.pending = false;
});
});
markers.add(o);
return o;
}
}
}
Aggregations