OK、Google を使用しましたが、問題を解決するものは何も見つかりませんでした。複数のポリゴンがありMapView
、すべてがマップ上に正しく表示されます。私がやろうとしているのはonTap
、タップされたときにポリゴンに関する情報を表示するために追加することですが、ポリゴンのタップを認識させることはできません。以下は私が現在持っているものです。このセクションで私が間違っていることを教えてもらえますonTap
か?
public class Polygon extends Overlay {
ArrayList<GeoPoint> geoPoints;
static ArrayList<String> custCount;
static ArrayList<String> hexCode;
static ArrayList<String> custMin;
static ArrayList<String> custMax;
static String tester;
Point firstPoint;
static List<HashMap<String, String>> colorRanges;
private Path path;
public Polygon(ArrayList<GeoPoint> points){
geoPoints = points;
}
public class setColorRanges{
public setColorRanges(List<HashMap<String, String>> colorData) {
colorRanges = colorData;
}
}
public class CustCount{
public CustCount(ArrayList<String> str) {
custCount = str;
}
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow){
//Set the color and style
Paint paint = new Paint();
Paint paint1 = new Paint();
//Create path and add points
int origin = 0;
for(int i = 0; i < geoPoints.size()/5;i++){
path = new Path();
firstPoint = new Point();
mapView.getProjection().toPixels(geoPoints.get(origin), firstPoint);
path.moveTo(firstPoint.x, firstPoint.y);
for(int j=0; j<5; j++) {
Point nextPoint = new Point();
mapView.getProjection().toPixels(geoPoints.get(origin+j), nextPoint);
path.lineTo(nextPoint.x, nextPoint.y);
}
//loop thru array of color ranges
int curCustCount = Integer.valueOf(custCount.get(i));
String curColor = "";
for(int z=0; z<colorRanges.size(); z++) {
int custmin = Integer.valueOf( colorRanges.get(z).get("custmin") );
int custmax = Integer.valueOf( colorRanges.get(z).get("custmax") );
if( curCustCount >= custmin && curCustCount <= custmax) {
curColor = colorRanges.get(z).get("hexcode");
break;
}
}
paint.setColor(Color.parseColor(curColor));
paint.setAlpha(70);
paint.setStyle(Paint.Style.FILL);
paint1.setColor(Color.parseColor(curColor));
paint1.setAlpha(100);
paint1.setStyle(Paint.Style.STROKE);
path.lineTo(firstPoint.x, firstPoint.y);
path.setLastPoint(firstPoint.x, firstPoint.y);
canvas.drawPath(path, paint);
canvas.drawPath(path,paint1);
origin += 5;
}
super.draw(canvas, mapView, shadow);
}
@Override
public boolean onTap(GeoPoint geoPoint, MapView mapView) {
RectF rectF = new RectF();
path.computeBounds(rectF, true);
Region region = new Region();
region.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
Point point = new Point();
mapView.getProjection().toPixels(geoPoint, point);
if (region.contains(point.x, point.y)) {
Log.d("onTap", point.x+" "+point.y);
}
return super.onTap(geoPoint, mapView);
}
}