Java Code Examples for org.osmdroid.bonuspack.overlays.Polygon

The following are top voted examples for showing how to use org.osmdroid.bonuspack.overlays.Polygon. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: OPFMaps   File: ConvertUtils.java View source code 6 votes vote down vote up
@NonNull
public static OsmdroidCircleDelegate convertCircleOptions(@NonNull final MapView mapView,
                                                          @NonNull final OPFCircleOptions options) {
    final OPFLatLng opfCenter = options.getCenter();
    if (opfCenter == null) {
        throw new IllegalArgumentException("no center in circle options");
    }

    final OsmdroidCircleDelegate circleDelegate = new OsmdroidCircleDelegate(
            mapView,
            new Polygon(mapView.getContext()),
            new GeoPoint(opfCenter.getLat(), opfCenter.getLng()),
            options.getRadius()
    );

    circleDelegate.setFillColor(options.getFillColor());
    circleDelegate.setStrokeColor(options.getStrokeColor());
    circleDelegate.setStrokeWidth(options.getStrokeWidth());
    circleDelegate.setVisible(options.isVisible());

    return circleDelegate;
}
 
Example 2
Project: OPFMaps   File: ConvertUtils.java View source code 6 votes vote down vote up
@NonNull
public static Polygon convertPolygonOptions(@NonNull final Context context, @NonNull final OPFPolygonOptions options) {
    final Polygon polygon = new Polygon(context);
    polygon.setFillColor(options.getFillColor());
    polygon.setStrokeColor(options.getStrokeColor());
    polygon.setStrokeWidth(options.getStrokeWidth());
    polygon.setVisible(options.isVisible());

    final List<List<OPFLatLng>> opfHoles = options.getHoles();
    if (!opfHoles.isEmpty()) {
        final List<List<GeoPoint>> osmdroidHoles = new ArrayList<>(opfHoles.size());
        for (List<OPFLatLng> hole : opfHoles) {
            final List<GeoPoint> osmdroidHole = new ArrayList<>(hole.size());
            for (OPFLatLng point : hole) {
                osmdroidHole.add(new GeoPoint(point.getLat(), point.getLng()));
            }
            osmdroidHoles.add(osmdroidHole);
        }
        polygon.setHoles(osmdroidHoles);
    }

    final List<OPFLatLng> opfPoints = options.getPoints();
    if (!opfPoints.isEmpty()) {
        final List<GeoPoint> osmdroidPoints = new ArrayList<>(opfPoints.size());
        for (OPFLatLng point : opfPoints) {
            osmdroidPoints.add(new GeoPoint(point.getLat(), point.getLng()));
        }
        polygon.setPoints(osmdroidPoints);
    }

    return polygon;
}
 
Example 3
Project: OPFMaps   File: OsmdroidCircleDelegate.java View source code 6 votes vote down vote up
public OsmdroidCircleDelegate(@SuppressWarnings("NullableProblems") @NonNull final MapView mapView,
                              @NonNull final Polygon polygon,
                              @NonNull final GeoPoint center,
                              final double radius) {
    this.mapView = mapView;
    this.polygon = polygon;
    this.polygon.setPoints(Polygon.pointsAsCircle(center, radius));
    this.center = center;
    this.radius = radius;
    this.id = Integer.toString(this.polygon.hashCode());
}
 
Example 4
Project: OPFMaps   File: OsmdroidCircleDelegate.java View source code 6 votes vote down vote up
@Override
public void setCenter(@NonNull final OPFLatLng center) {
    if (mapView != null) {
        this.center = new GeoPoint(center.getLat(), center.getLng());
        polygon.setPoints(Polygon.pointsAsCircle(this.center, radius));
        mapView.invalidate();
    }
}
 
Example 5
Project: OPFMaps   File: OsmdroidCircleDelegate.java View source code 6 votes vote down vote up
@Override
public void setRadius(final double radius) {
    if (mapView != null) {
        this.radius = radius;
        polygon.setPoints(Polygon.pointsAsCircle(center, this.radius));
        mapView.invalidate();
    }
}
 
Example 6
Project: OPFMaps   File: OsmdroidMapDelegate.java View source code 6 votes vote down vote up
@NonNull
@Override
public OPFPolygon addPolygon(@NonNull final OPFPolygonOptions options) {
    final Polygon polygon = ConvertUtils.convertPolygonOptions(map.getContext(), options);
    map.getOverlays().add(polygon);
    map.invalidate();
    return new OPFPolygon(new OsmdroidPolygonDelegate(map, polygon));
}
 
Example 7
Project: OPFMaps   File: OsmdroidMapDelegate.java View source code 6 votes vote down vote up
@Override
public void clear() {
    final List<Overlay> overlays = map.getOverlays();

    for (Iterator<Overlay> it = overlays.iterator(); it.hasNext();) {
        final Overlay overlay = it.next();
        if (overlay instanceof Marker
                || overlay instanceof Polygon
                || overlay instanceof GroundOverlay
                || overlay instanceof Polyline) {
            it.remove();
        }
    }
    map.invalidate();
}
 
Example 8
Project: SmartNavi   File: KmlFolder.java View source code 6 votes vote down vote up
/** 
 * Converts the overlay to a KmlFeature and add it inside this. 
 * Conversion from Overlay subclasses to KML Features is as follow: <br>
 *   FolderOverlay, MarkerClusterer => Folder<br>
 *   Marker => Point<br>
 *   Polygon => Polygon<br>
 *   Polyline => LineString<br>
 *   GroundOverlay => GroundOverlay<br>
 *   Else, add nothing. 
 * @param overlay to convert and add
 * @param kmlDoc for style handling. 
 * @return true if OK, false if the overlay has not been added. 
 */
public boolean addOverlay(Overlay overlay, KmlDocument kmlDoc){
	if (overlay == null)
		return false;
	KmlFeature kmlItem;
	if (overlay instanceof GroundOverlay){
		kmlItem = new KmlGroundOverlay((GroundOverlay)overlay);
	} else if (overlay instanceof FolderOverlay){
		kmlItem = new KmlFolder((FolderOverlay)overlay, kmlDoc);
	} else if (overlay instanceof MarkerClusterer){
		kmlItem = new KmlFolder((MarkerClusterer)overlay, kmlDoc);
	} else if (overlay instanceof Marker){
		Marker marker = (Marker)overlay;
		kmlItem = new KmlPlacemark(marker);
	} else if (overlay instanceof Polygon){
		Polygon polygon = (Polygon)overlay;
		kmlItem = new KmlPlacemark(polygon, kmlDoc);
	} else if (overlay instanceof Polyline){
		Polyline polyline = (Polyline)overlay;
		kmlItem = new KmlPlacemark(polyline, kmlDoc);
	} else {
		return false;
	}
	mItems.add(kmlItem);
	return true;
}
 
Example 9
Project: SmartNavi   File: KmlPolygon.java View source code 6 votes vote down vote up
public void applyDefaultStyling(Polygon polygonOverlay, Style defaultStyle, KmlPlacemark kmlPlacemark,
		KmlDocument kmlDocument, MapView map){
	Context context = map.getContext();
	Style style = kmlDocument.getStyle(kmlPlacemark.mStyle);
	if (style != null){
		Paint outlinePaint = style.getOutlinePaint();
		polygonOverlay.setStrokeColor(outlinePaint.getColor());
		polygonOverlay.setStrokeWidth(outlinePaint.getStrokeWidth());
		int fillColor = style.mPolyStyle.getFinalColor();
		polygonOverlay.setFillColor(fillColor);
	} else if (defaultStyle!=null){
		Paint outlinePaint = defaultStyle.getOutlinePaint();
		polygonOverlay.setStrokeColor(outlinePaint.getColor());
		polygonOverlay.setStrokeWidth(outlinePaint.getStrokeWidth());
		int fillColor = defaultStyle.mPolyStyle.getFinalColor();
		polygonOverlay.setFillColor(fillColor);
	}
	if ((kmlPlacemark.mName!=null && !"".equals(kmlPlacemark.mName)) 
			|| (kmlPlacemark.mDescription!=null && !"".equals(kmlPlacemark.mDescription))){
		if (mDefaultLayoutResId == BonusPackHelper.UNDEFINED_RES_ID){
			String packageName = context.getPackageName();
			mDefaultLayoutResId = context.getResources().getIdentifier("layout/bonuspack_bubble", null, packageName);
		}
		polygonOverlay.setInfoWindow(new DefaultInfoWindow(mDefaultLayoutResId, map));
	}
	polygonOverlay.setEnabled(kmlPlacemark.mVisibility);
}
 
Example 10
Project: SmartNavi   File: KmlPolygon.java View source code 6 votes vote down vote up
/** Build the corresponding Polygon overlay */
@Override public Overlay buildOverlay(MapView map, Style defaultStyle, Styler styler, KmlPlacemark kmlPlacemark, 
		KmlDocument kmlDocument){
	Context context = map.getContext();
	Polygon polygonOverlay = new Polygon(context);
	polygonOverlay.setPoints(mCoordinates);
	if (mHoles != null)
		polygonOverlay.setHoles(mHoles);
	polygonOverlay.setTitle(kmlPlacemark.mName);
	polygonOverlay.setSnippet(kmlPlacemark.mDescription);
	if (styler == null)
		applyDefaultStyling(polygonOverlay, defaultStyle, kmlPlacemark, kmlDocument, map);
	else
		styler.onPolygon(polygonOverlay, kmlPlacemark, this);
	return polygonOverlay;
}
 
Example 11
Project: SmartNavi   File: KmlPlacemark.java View source code 6 votes vote down vote up
/** constructs a Placemark from a Polygon overlay, as a KML Polygon */
public KmlPlacemark(Polygon polygon, KmlDocument kmlDoc){
	this();
	mName = polygon.getTitle();
	mDescription = polygon.getSnippet();
	mGeometry = new KmlPolygon();
	mGeometry.mCoordinates = (ArrayList<GeoPoint>)polygon.getPoints();
	((KmlPolygon)mGeometry).mHoles = (ArrayList<ArrayList<GeoPoint>>)polygon.getHoles();
	mVisibility = polygon.isEnabled();
	//Style:
	Style style = new Style();
	style.mPolyStyle = new ColorStyle(polygon.getFillColor());
	style.mLineStyle = new LineStyle(polygon.getStrokeColor(), polygon.getStrokeWidth());
	mStyle = kmlDoc.addStyle(style);
}
 
Example 12
Project: osmbonuspack   File: MapActivity.java View source code 6 votes vote down vote up
public void updateUIWithPolygon(ArrayList<GeoPoint> polygon, String name){
	List<Overlay> mapOverlays = map.getOverlays();
	int location = -1;
	if (mDestinationPolygon != null)
		location = mapOverlays.indexOf(mDestinationPolygon);
	mDestinationPolygon = new Polygon(this);
	mDestinationPolygon.setFillColor(0x15FF0080);
	mDestinationPolygon.setStrokeColor(0x800000FF);
	mDestinationPolygon.setStrokeWidth(5.0f);
	mDestinationPolygon.setTitle(name);
	BoundingBoxE6 bb = null;
	if (polygon != null){
		mDestinationPolygon.setPoints(polygon);
		bb = BoundingBoxE6.fromGeoPoints(polygon);
	}
	if (location != -1)
		mapOverlays.set(location, mDestinationPolygon);
	else
		mapOverlays.add(1, mDestinationPolygon); //insert just above the MapEventsOverlay. 
	setViewOn(bb);
	map.invalidate();
}
 
Example 13
Project: osmbonuspack   File: KmlFolder.java View source code 6 votes vote down vote up
/** 
 * Converts the overlay to a KmlFeature and add it inside this. 
 * Conversion from Overlay subclasses to KML Features is as follow: <br>
 *   FolderOverlay, MarkerClusterer => Folder<br>
 *   Marker => Point<br>
 *   Polygon => Polygon<br>
 *   Polyline => LineString<br>
 *   GroundOverlay => GroundOverlay<br>
 *   Else, add nothing. 
 * @param overlay to convert and add
 * @param kmlDoc for style handling. 
 * @return true if OK, false if the overlay has not been added. 
 */
public boolean addOverlay(Overlay overlay, KmlDocument kmlDoc){
	if (overlay == null)
		return false;
	KmlFeature kmlItem;
	if (overlay instanceof GroundOverlay){
		kmlItem = new KmlGroundOverlay((GroundOverlay)overlay);
	} else if (overlay instanceof FolderOverlay){
		kmlItem = new KmlFolder((FolderOverlay)overlay, kmlDoc);
	} else if (overlay instanceof MarkerClusterer){
		kmlItem = new KmlFolder((MarkerClusterer)overlay, kmlDoc);
	} else if (overlay instanceof Marker){
		Marker marker = (Marker)overlay;
		kmlItem = new KmlPlacemark(marker);
	} else if (overlay instanceof Polygon){
		Polygon polygon = (Polygon)overlay;
		kmlItem = new KmlPlacemark(polygon, kmlDoc);
	} else if (overlay instanceof Polyline){
		Polyline polyline = (Polyline)overlay;
		kmlItem = new KmlPlacemark(polyline, kmlDoc);
	} else {
		return false;
	}
	mItems.add(kmlItem);
	return true;
}
 
Example 14
Project: osmbonuspack   File: KmlPolygon.java View source code 6 votes vote down vote up
public void applyDefaultStyling(Polygon polygonOverlay, Style defaultStyle, KmlPlacemark kmlPlacemark,
		KmlDocument kmlDocument, MapView map){
	Context context = map.getContext();
	Style style = kmlDocument.getStyle(kmlPlacemark.mStyle);
	if (style != null){
		Paint outlinePaint = style.getOutlinePaint();
		polygonOverlay.setStrokeColor(outlinePaint.getColor());
		polygonOverlay.setStrokeWidth(outlinePaint.getStrokeWidth());
		if (style.mPolyStyle != null){
			int fillColor = style.mPolyStyle.getFinalColor();
			polygonOverlay.setFillColor(fillColor);
		}
	} else if (defaultStyle!=null){
		Paint outlinePaint = defaultStyle.getOutlinePaint();
		polygonOverlay.setStrokeColor(outlinePaint.getColor());
		polygonOverlay.setStrokeWidth(outlinePaint.getStrokeWidth());
		int fillColor = defaultStyle.mPolyStyle.getFinalColor();
		polygonOverlay.setFillColor(fillColor);
	}
	if ((kmlPlacemark.mName!=null && !"".equals(kmlPlacemark.mName)) 
			|| (kmlPlacemark.mDescription!=null && !"".equals(kmlPlacemark.mDescription))
			|| (polygonOverlay.getSubDescription()!=null && !"".equals(polygonOverlay.getSubDescription()))
			){
		if (mDefaultLayoutResId == BonusPackHelper.UNDEFINED_RES_ID){
			String packageName = context.getPackageName();
			mDefaultLayoutResId = context.getResources().getIdentifier("layout/bonuspack_bubble", null, packageName);
		}
		polygonOverlay.setInfoWindow(new BasicInfoWindow(mDefaultLayoutResId, map));
	}
	polygonOverlay.setEnabled(kmlPlacemark.mVisibility);
}
 
Example 15
Project: osmbonuspack   File: KmlPolygon.java View source code 6 votes vote down vote up
/** Build the corresponding Polygon overlay */
@Override public Overlay buildOverlay(MapView map, Style defaultStyle, Styler styler, KmlPlacemark kmlPlacemark, 
		KmlDocument kmlDocument){
	Context context = map.getContext();
	Polygon polygonOverlay = new Polygon(context);
	polygonOverlay.setPoints(mCoordinates);
	if (mHoles != null)
		polygonOverlay.setHoles(mHoles);
	polygonOverlay.setTitle(kmlPlacemark.mName);
	polygonOverlay.setSnippet(kmlPlacemark.mDescription);
	polygonOverlay.setSubDescription(kmlPlacemark.getExtendedDataAsText());
	if (styler == null)
		applyDefaultStyling(polygonOverlay, defaultStyle, kmlPlacemark, kmlDocument, map);
	else
		styler.onPolygon(polygonOverlay, kmlPlacemark, this);
	return polygonOverlay;
}
 
Example 16
Project: osmbonuspack   File: KmlPlacemark.java View source code 6 votes vote down vote up
/** constructs a Placemark from a Polygon overlay, as a KML Polygon */
public KmlPlacemark(Polygon polygon, KmlDocument kmlDoc){
	this();
	mName = polygon.getTitle();
	mDescription = polygon.getSnippet();
	mGeometry = new KmlPolygon();
	mGeometry.mCoordinates = (ArrayList<GeoPoint>)polygon.getPoints();
	((KmlPolygon)mGeometry).mHoles = (ArrayList<ArrayList<GeoPoint>>)polygon.getHoles();
	mVisibility = polygon.isEnabled();
	//Style:
	Style style = new Style();
	style.mPolyStyle = new ColorStyle(polygon.getFillColor());
	style.mLineStyle = new LineStyle(polygon.getStrokeColor(), polygon.getStrokeWidth());
	mStyle = kmlDoc.addStyle(style);
}
 
Example 17
Project: osmbonuspack   File: MainActivity.java View source code 6 votes vote down vote up
@Override public boolean longPressHelper(GeoPoint p) {
	//Toast.makeText(this, "Long press", Toast.LENGTH_SHORT).show();
	//17. Using Polygon, defined as a circle:
	Polygon circle = new Polygon(this);
	circle.setPoints(Polygon.pointsAsCircle(p, 2000.0));
	circle.setFillColor(0x12121212);
	circle.setStrokeColor(Color.RED);
	circle.setStrokeWidth(2);
	map.getOverlays().add(circle);
	circle.setInfoWindow(new BasicInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, map));
	circle.setTitle("Centered on "+p.getLatitude()+","+p.getLongitude());
	
	//18. Using GroundOverlay
	GroundOverlay myGroundOverlay = new GroundOverlay(this);
	myGroundOverlay.setPosition(p);
	myGroundOverlay.setImage(getResources().getDrawable(R.drawable.ic_launcher).mutate());
	myGroundOverlay.setDimensions(2000.0f);
	//myGroundOverlay.setTransparency(0.25f);
	myGroundOverlay.setBearing(mGroundOverlayBearing);
	mGroundOverlayBearing += 20.0f;
	map.getOverlays().add(myGroundOverlay);
	
	map.invalidate();
	return true;
}
 
Example 18
Project: Data4All   File: D4AMapView.java View source code 6 votes vote down vote up
/**
 * Adds an area as an Overlay to the Map.
 *
 * @param ctx
 *            The invoking Activity
 * @param polyElement
 *            the area which should be added to the map
 * @param edit
 *            is the Element editable
 **/
private void addAreaToMap(AbstractActivity ctx, PolyElement polyElement,
        boolean edit) {
    final Polygon area = new MapPolygon(ctx, this, polyElement);

    Log.i(TAG, "Set Area Points to " + polyElement.toString());
    area.setPoints(polyElement.getGeoPoints());

    if (edit) {
        // set the polygon to editable
        ((MapPolygon) area).setEditable(true);
        // set the original points to calculate the offset of all points
        ((MapPolygon) area).setOriginalPoints();
        Log.i(TAG, "Set Area Fill Color to " + MARKED_FILL_COLOR);
        area.setFillColor(MARKED_FILL_COLOR);

        Log.i(TAG, "Set Stroke Color to " + MARKED_STROKE_COLOR);
        area.setStrokeColor(MARKED_STROKE_COLOR);
    } else {
        Log.i(TAG, "Set Area Fill Color to " + DEFAULT_FILL_COLOR);
        area.setFillColor(DEFAULT_FILL_COLOR);

        Log.i(TAG, "Set Stroke Color to " + DEFAULT_STROKE_COLOR);
        area.setStrokeColor(DEFAULT_STROKE_COLOR);
    }
    Log.i(TAG, "Set Stroke Width to " + DEFAULT_STROKE_WIDTH);
    area.setStrokeWidth(DEFAULT_STROKE_WIDTH);

    this.getOverlays().add(area);
    this.postInvalidate();
}