Java Code Examples for com.amap.api.maps.model.PolylineOptions#add()

The following examples show how to use com.amap.api.maps.model.PolylineOptions#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColourfulPolylineActivity.java    From TraceByAmap with MIT License 6 votes vote down vote up
/**
	 * 多段颜色(非渐变色)
	 */
	private void addPolylinesWithColors() {
		//四个点
		LatLng A = new LatLng(Lat_A + 0.0001, Lon_A + 0.0001);
		LatLng B = new LatLng(Lat_B + 0.0001, Lon_B + 0.0001);
		LatLng C = new LatLng(Lat_C + 0.0001, Lon_C + 0.0001);
		LatLng D = new LatLng(Lat_D + 0.0001, Lon_D + 0.0001);
		
		//用一个数组来存放颜色,四个点对应三段颜色
		List<Integer> colorList = new ArrayList<Integer>();
		colorList.add(Color.RED);
		colorList.add(Color.YELLOW);
		colorList.add(Color.GREEN);
//		colorList.add(Color.BLACK);
		
		PolylineOptions options = new PolylineOptions();
		options.width(20);//设置宽度
		
		//加入四个点
		options.add(A,B,C,D);
		
		//加入对应的颜色,使用colorValues 即表示使用多颜色,使用color表示使用单色线
		options.colorValues(colorList);
		
		aMap.addPolyline(options);
	}
 
Example 2
Source File: CircleActivity.java    From TraceByAmap with MIT License 6 votes vote down vote up
/**
 *
 * @param centerpoint 中心点坐标
 * @param radius      半径 米
 */
public void addPolylinescircle(LatLng centerpoint, int radius) {
    double r = 6371000.79;
    PolylineOptions options = new PolylineOptions();
    int numpoints = 360;
    double phase = 2 * Math.PI / numpoints;

    //画图
    for (int i = 0; i < numpoints; i++) {
        double dx = (radius * Math.cos(i * phase));
        double dy = (radius * Math.sin(i * phase));//乘以1.6 椭圆比例

        double dlng = dx / (r * Math.cos(centerpoint.latitude * Math.PI / 180) * Math.PI / 180);
        double dlat = dy / (r * Math.PI / 180);
        double newlng = centerpoint.longitude + dlng;
        options.add(new LatLng(centerpoint.latitude + dlat, newlng));
    }

    aMap.addPolyline(options.width(10).useGradient(true).setDottedLine(true));

}
 
Example 3
Source File: PolylineActivitybase.java    From TraceByAmap with MIT License 6 votes vote down vote up
/**
	 * 多段颜色(非渐变色)
	 */
	private void addPolylinesWithColors() {
		//四个点
		LatLng A = new LatLng(Lat_A + 1, Lon_A + 1);
		LatLng B = new LatLng(Lat_B + 1, Lon_B + 1);
		LatLng C = new LatLng(Lat_C + 1, Lon_C + 1);
		LatLng D = new LatLng(Lat_D + 1, Lon_D + 1);
		
		//用一个数组来存放颜色,四个点对应三段颜色
		List<Integer> colorList = new ArrayList<Integer>();
		colorList.add(Color.RED);
		colorList.add(Color.YELLOW);
		colorList.add(Color.GREEN);
//		colorList.add(Color.BLACK);
		
		PolylineOptions options = new PolylineOptions();
		options.width(20);//设置宽度
		
		//加入四个点
		options.add(A,B,C,D);
		
		//加入对应的颜色,使用colorValues 即表示使用多颜色,使用color表示使用单色线
		options.colorValues(colorList);
		
		aMap.addPolyline(options);
	}
 
Example 4
Source File: GaoDeMapAiSurroundManager.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void addPolylinescircle(LatLng centerpoint, float radius) {
    PolylineOptions options = new PolylineOptions();
    double phase = 6.283185307179586d / ((double) 360);
    for (int i = 0; i < 360; i++) {
        double newlng = centerpoint.longitude + ((((double) radius) * Math.cos(((double) i) * phase)) / (((Math.cos((centerpoint.latitude * 3.141592653589793d) / 180.0d) * 6371000.79d) * 3.141592653589793d) / 180.0d));
        options.add(new LatLng(centerpoint.latitude + ((((double) radius) * Math.sin(((double) i) * phase)) / ((3.141592653589793d * 6371000.79d) / 180.0d)), newlng));
    }
    options.color(this.context.getResources().getColor(R.color.x8_drone_inface_line));
    this.polyline = this.aMap.addPolyline(options.width(10.0f).useGradient(true).setDottedLine(true));
}
 
Example 5
Source File: ColourfulPolylineActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * 多段颜色(渐变色)
 */
private void addPolylinesWithGradientColors() {
	//四个点
	LatLng A = new LatLng(Lat_A + 0.0004, Lon_A + 0.0004);
	LatLng B = new LatLng(Lat_B + 0.0004, Lon_B + 0.0004);
	LatLng C = new LatLng(Lat_C + 0.0004, Lon_C + 0.0004);
	LatLng D = new LatLng(Lat_D + 0.0004, Lon_D + 0.0004);
	
	//用一个数组来存放颜色,渐变色,四个点需要设置四个颜色
	List<Integer> colorList = new ArrayList<Integer>();
	colorList.add(Color.RED);
	colorList.add(Color.YELLOW);
	colorList.add(Color.GREEN);
	colorList.add(Color.BLACK);//如果第四个颜色不添加,那么最后一段将显示上一段的颜色
	
	PolylineOptions options = new PolylineOptions();
	options.width(20);//设置宽度
	
	//加入四个点
	options.add(A,B,C,D);
	
	//加入对应的颜色,使用colorValues 即表示使用多颜色,使用color表示使用单色线
	options.colorValues(colorList);
	
	//加上这个属性,表示使用渐变线
	options.useGradient(true);
	
	aMap.addPolyline(options);
}
 
Example 6
Source File: PolylineActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
private void addPolylinesWithTexture() {
	//四个点
	LatLng A = new LatLng(Lat_A+1, Lon_A+1);
	LatLng B = new LatLng(Lat_B+1, Lon_B+1);
	LatLng C = new LatLng(Lat_C+1, Lon_C+1);
	LatLng D = new LatLng(Lat_D+1, Lon_D+1);
	
	//用一个数组来存放纹理
	List<BitmapDescriptor> texTuresList = new ArrayList<BitmapDescriptor>();
	texTuresList.add(BitmapDescriptorFactory.fromResource(R.drawable.map_alr));
	texTuresList.add(BitmapDescriptorFactory.fromResource(R.drawable.custtexture));
	texTuresList.add(BitmapDescriptorFactory.fromResource(R.drawable.map_alr_night));
	
	//指定某一段用某个纹理,对应texTuresList的index即可, 四个点对应三段颜色
	List<Integer> texIndexList = new ArrayList<Integer>();
	texIndexList.add(0);//对应上面的第0个纹理
	texIndexList.add(2);
	texIndexList.add(1);
	
	
	PolylineOptions options = new PolylineOptions();
	options.width(20);//设置宽度
	
	//加入四个点
	options.add(A,B,C,D);
	
	//加入对应的颜色,使用setCustomTextureList 即表示使用多纹理;
	options.setCustomTextureList(texTuresList);
	
	//设置纹理对应的Index
	options.setCustomTextureIndex(texIndexList);
	
	aMap.addPolyline(options);
}
 
Example 7
Source File: PolylineActivitybase.java    From TraceByAmap with MIT License 5 votes vote down vote up
private void addPolylinesWithTexture() {
	//四个点
	LatLng A = new LatLng(Lat_A, Lon_A);
	LatLng B = new LatLng(Lat_B, Lon_B);
	LatLng C = new LatLng(Lat_C, Lon_C);
	LatLng D = new LatLng(Lat_D, Lon_D);
	
	//用一个数组来存放纹理
	List<BitmapDescriptor> texTuresList = new ArrayList<BitmapDescriptor>();
	texTuresList.add(BitmapDescriptorFactory.fromResource(R.drawable.map_alr));
	texTuresList.add(BitmapDescriptorFactory.fromResource(R.drawable.custtexture));
	texTuresList.add(BitmapDescriptorFactory.fromResource(R.drawable.map_alr_night));
	
	//指定某一段用某个纹理,对应texTuresList的index即可, 四个点对应三段颜色
	List<Integer> texIndexList = new ArrayList<Integer>();
	texIndexList.add(0);//对应上面的第0个纹理
	texIndexList.add(2);
	texIndexList.add(1);
	
	
	PolylineOptions options = new PolylineOptions();
	options.width(20);//设置宽度
	
	//加入四个点
	options.add(A,B,C,D);
	
	//加入对应的颜色,使用setCustomTextureList 即表示使用多纹理;
	options.setCustomTextureList(texTuresList);
	
	//设置纹理对应的Index
	options.setCustomTextureIndex(texIndexList);
	
	aMap.addPolyline(options);
}
 
Example 8
Source File: PolylineActivitybase.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * 多段颜色(渐变色)
 */
private void addPolylinesWithGradientColors() {
	//四个点
	LatLng A = new LatLng(Lat_A + 2, Lon_A + 2);
	LatLng B = new LatLng(Lat_B + 2, Lon_B + 2);
	LatLng C = new LatLng(Lat_C + 2, Lon_C + 2);
	LatLng D = new LatLng(Lat_D + 2, Lon_D + 2);
	
	//用一个数组来存放颜色,渐变色,四个点需要设置四个颜色
	List<Integer> colorList = new ArrayList<Integer>();
	colorList.add(Color.RED);
	colorList.add(Color.YELLOW);
	colorList.add(Color.GREEN);
	colorList.add(Color.BLACK);//如果第四个颜色不添加,那么最后一段将显示上一段的颜色
	
	PolylineOptions options = new PolylineOptions();
	options.width(20);//设置宽度
	
	//加入四个点
	options.add(A,B,C,D);
	
	//加入对应的颜色,使用colorValues 即表示使用多颜色,使用color表示使用单色线
	options.colorValues(colorList);
	
	//加上这个属性,表示使用渐变线
	options.useGradient(true);
	
	aMap.addPolyline(options);
}
 
Example 9
Source File: ColourfulPolylineActivity.java    From TraceByAmap with MIT License 4 votes vote down vote up
public void addPolylineInPlayGround(LatLng centerpoint) {
  	double r = 6371000.79;
  	int r1 = 50;
  	PolylineOptions options = new PolylineOptions();
  	int numpoints =36;
  	double phase = 2 * Math.PI / numpoints;
  	//颜色数组
  	List<Integer> colorList = new ArrayList<Integer>();
int[] colors = new int[]{Color.argb(255, 0, 255, 0),Color.argb(255, 255, 255, 0),Color.argb(255, 255, 0, 0)};
Random random = new Random();
  	//画图
  	for (int i = 0; i <numpoints; i++) {
	double dx = (r1 * Math.cos(i*phase));
	double dy = (r1*Math.sin(i*phase))*1.6;//乘以1.6 椭圆比例
	
	double dlng = dx/(r*Math.cos(centerpoint.latitude*Math.PI/180)*Math.PI/180);
	double dlat = dy/(r*Math.PI/180);
	double newlng = centerpoint.longitude+dlng;
	
	//跑道两边为直线
	if (newlng<centerpoint.longitude - 0.00046) {
		newlng = centerpoint.longitude - 0.00046;
	}else if (newlng > centerpoint.longitude + 0.00046) {
		newlng = centerpoint.longitude + 0.00046;
	}
	options.add(new LatLng(centerpoint.latitude+dlat,newlng));	
}
  	
  	//随机颜色赋值
  	for (int i = 0; i < numpoints; i = i+2) {
  		int color = colors[random.nextInt(3)];
  		colorList.add(color);//添加颜色
  		colorList.add(color);
}

  	//确保首位相接,添加后一个点及颜色与第一点相同
  	options.add(options.getPoints().get(0));
  	colorList.add(colorList.get(0));

  	
  	
  	
  	List<Integer> colorListnew = new ArrayList<Integer>();
  	colorListnew.add(Color.RED);
  	colorListnew.add(Color.YELLOW);
  	colorListnew.add(Color.GREEN);
  	aMap.addPolyline(options.width(15)
  			.colorValues(colorList).useGradient(true));

  	aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(centerpoint, 17));  
}