List of usage examples for com.google.gwt.maps.client.overlays Polyline getPath
public final native MVCArray<LatLng> getPath() ;
From source file:com.google.gwt.maps.testing.client.maps.DrawingMapWidget.java
License:Apache License
private void drawDrawing() { DrawingControlOptions drawingControlOptions = DrawingControlOptions.newInstance(); drawingControlOptions.setPosition(ControlPosition.TOP_CENTER); drawingControlOptions.setDrawingModes(OverlayType.values()); CircleOptions circleOptions = CircleOptions.newInstance(); // circleOptions.setFillColor("FF6633"); DrawingManagerOptions options = DrawingManagerOptions.newInstance(); options.setMap(mapWidget);// w w w . j av a2s . com options.setDrawingMode(OverlayType.CIRCLE); options.setCircleOptions(circleOptions); options.setDrawingControlOptions(drawingControlOptions); DrawingManager o = DrawingManager.newInstance(options); o.addCircleCompleteHandler(new CircleCompleteMapHandler() { @Override public void onEvent(CircleCompleteMapEvent event) { Circle circle = event.getCircle(); GWT.log("circle completed radius=" + circle.getRadius()); } }); o.addMarkerCompleteHandler(new MarkerCompleteMapHandler() { @Override public void onEvent(MarkerCompleteMapEvent event) { Marker marker = event.getMarker(); GWT.log("marker completed position=" + marker.getPosition()); } }); o.addOverlayCompleteHandler(new OverlayCompleteMapHandler() { @Override public void onEvent(OverlayCompleteMapEvent event) { OverlayType ot = event.getOverlayType(); GWT.log("marker completed OverlayType=" + ot.toString()); if (ot == OverlayType.CIRCLE) { Circle circle = event.getCircle(); GWT.log("radius=" + circle.getRadius()); GWT.log("center=" + circle.getBounds().getCenter()); } if (ot == OverlayType.MARKER) { Marker marker = event.getMarker(); GWT.log("position=" + marker.getPosition()); GWT.log("center=" + marker.getPosition()); } if (ot == OverlayType.POLYGON) { Polygon polygon = event.getPolygon(); GWT.log("paths=" + polygon.getPaths().toString()); // print path points MVCArray<LatLng> points = polygon.getPath(); for (int g = 0; g < points.getLength(); g++) { LatLng p = points.get(g); GWT.log("[" + p.getLatitude() + "," + p.getLongitude() + "]"); } GWT.log("center=" + polygon.getPath()); } if (ot == OverlayType.POLYLINE) { Polyline polyline = event.getPolyline(); GWT.log("paths=" + polyline.getPath().toString()); GWT.log("center=" + polyline.getPath()); } if (ot == OverlayType.RECTANGLE) { Rectangle rectangle = event.getRectangle(); GWT.log("bounds=" + rectangle.getBounds()); GWT.log("center=" + rectangle.getBounds().getCenter()); } GWT.log("marker completed OverlayType=" + ot.toString()); } }); o.addPolygonCompleteHandler(new PolygonCompleteMapHandler() { @Override public void onEvent(PolygonCompleteMapEvent event) { Polygon polygon = event.getPolygon(); GWT.log("Polygon completed paths=" + polygon.getPath().toString()); } }); o.addPolylineCompleteHandler(new PolylineCompleteMapHandler() { @Override public void onEvent(PolylineCompleteMapEvent event) { Polyline polyline = event.getPolyline(); GWT.log("Polyline completed paths=" + polyline.getPath().toString()); } }); o.addRectangleCompleteHandler(new RectangleCompleteMapHandler() { @Override public void onEvent(RectangleCompleteMapEvent event) { Rectangle rectangle = event.getRectangle(); GWT.log("Rectangle completed bounds=" + rectangle.getBounds().getToString()); } }); }
From source file:com.google.gwt.maps.testing.client.maps.PolylineMapWidget.java
License:Apache License
/** * Return the center of a given polyline - send from server if it is a ton of * points due to full path scan//from w ww .j a v a 2 s.com * * @param polyline * @return */ // TODO can be moved into a utility class if frequently used private LatLng getPolyLineCenter(Polyline polyline) { if (polyline == null) { return null; } // checks JsArray<LatLng> path = polyline.getPath().getArray(); if (path.length() == 0) { return null; } LatLng startPt = path.get(0); if (path.length() == 1) { return startPt; } double maxLat = startPt.getLatitude(), minLat = startPt.getLatitude(), maxLng = startPt.getLongitude(), minLng = startPt.getLongitude(); for (int n = 1; n < path.length(); n++) { LatLng p = path.get(n); if (p.getLatitude() > maxLat) { maxLat = p.getLatitude(); } if (p.getLongitude() > maxLng) { maxLng = p.getLongitude(); } if (p.getLatitude() < minLat) { minLat = p.getLatitude(); } if (p.getLongitude() < minLng) { minLng = p.getLongitude(); } } return LatLng.newInstance(minLat + 0.5 * (maxLat - minLat), minLng + 0.5 * (maxLng - minLng)); }