开发者

Draw a polygon on mapview + android

开发者 https://www.devze.com 2023-02-23 06:41 出处:网络
I want to draw a polygon on the map view. It is like, i have a n number of GeoPoints and then using those geopoints, i want to draw a polygon with n vertices.

I want to draw a polygon on the map view. It is like, i have a n number of GeoPoints and then using those geopoints, i want to draw a polygon with n vertices.

thanks!!

Update:

thanks to freza, now i know how to draw a overlay.

There is an another function under overlay class : public boolean onTap(GeoPoint p, MapView mapView). Now what i want is when user tap on any overlay, i want to change the image of the overlay.

For example, initially i have drawn a simple green circle for displaying overlay. So now when user taps on that green overlay: i wan开发者_如何转开发t to change the color to red or draw a new bitmap in place if green circle. How can i do this?


This can help you. code follows:

          private void changeMarkers(int noteIndex) {
    for (int i = 0; i < noteOverlays.size(); i++) {
        if (i == noteIndex || noteIndex == -1) {
            Drawable selectedMarker = getResources().getDrawable(
                    R.drawable.note_in_map);
            int selectedMarkerWidth = selectedMarker.getIntrinsicWidth();
            int selectedMarkerHeight = selectedMarker.getIntrinsicHeight();
            selectedMarker.setBounds(-selectedMarkerWidth / 2,
                    -selectedMarkerHeight, selectedMarkerWidth / 2, 0);         noteOverlays.getItem(i).setMarker(selectedMarker);
        } else {
            Drawable unselectedMarker = getResources().getDrawable(
                    R.drawable.note_in_map_notselected);
            int nonSelectedMarkerWidth = unselectedMarker
                    .getIntrinsicWidth();
            int nonSelectedMarkerHeight = unselectedMarker
                    .getIntrinsicHeight();
            unselectedMarker
                    .setBounds(-nonSelectedMarkerWidth / 2,
                            -nonSelectedMarkerHeight,
                            nonSelectedMarkerWidth / 2, 0);
            noteOverlays.getItem(i).setMarker(unselectedMarker);
        }
    }
    mapView.invalidate();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号