/** * Create polyline * * @param args * @param callbackContext * @throws JSONException */ @SuppressWarnings("unused") private void createPolyline(final JSONArray args, final CallbackContext callbackContext) throws JSONException { final PolylineOptions polylineOptions = new PolylineOptions(); int color; LatLngBounds.Builder builder = new LatLngBounds.Builder(); JSONObject opts = args.getJSONObject(1); if (opts.has("points")) { JSONArray points = opts.getJSONArray("points"); List<LatLng> path = PluginUtil.JSONArray2LatLngList(points); int i = 0; for (i = 0; i < path.size(); i++) { polylineOptions.add(path.get(i)); builder.include(path.get(i)); } } if (opts.has("color")) { color = PluginUtil.parsePluginColor(opts.getJSONArray("color")); polylineOptions.color(color); } if (opts.has("width")) { polylineOptions.width(opts.getInt("width") * this.density); } if (opts.has("visible")) { polylineOptions.visible(opts.getBoolean("visible")); } if (opts.has("geodesic")) { polylineOptions.geodesic(opts.getBoolean("geodesic")); } if (opts.has("zIndex")) { polylineOptions.zIndex(opts.getInt("zIndex")); } Polyline polyline = map.addPolyline(polylineOptions); String id = "polyline_" + polyline.getId(); this.objects.put(id, polyline); String boundsId = "polyline_bounds_" + polyline.getId(); this.objects.put(boundsId, builder.build()); JSONObject result = new JSONObject(); result.put("hashCode", polyline.hashCode()); result.put("id", id); callbackContext.success(result); }
/** * Remove the polyline * * @param args * @param callbackContext * @throws JSONException */ @SuppressWarnings("unused") private void remove(final JSONArray args, final CallbackContext callbackContext) throws JSONException { String id = args.getString(1); Polyline polyline = this.getPolyline(id); if (polyline == null) { this.sendNoResult(callbackContext); return; } this.objects.remove(id); id = "polyline_bounds_" + polyline.getId(); this.objects.remove(id); polyline.remove(); this.sendNoResult(callbackContext); }
/** * Set points * * @param args * @param callbackContext * @throws JSONException */ @SuppressWarnings("unused") private void setPoints(final JSONArray args, final CallbackContext callbackContext) throws JSONException { String id = args.getString(1); Polyline polyline = this.getPolyline(id); JSONArray points = args.getJSONArray(2); List<LatLng> path = PluginUtil.JSONArray2LatLngList(points); polyline.setPoints(path); LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (int i = 0; i < path.size(); i++) { builder.include(path.get(i)); } this.objects.put("polyline_bounds_" + polyline.getId(), builder.build()); this.sendNoResult(callbackContext); }