用ArcGIS API for JavaScript在地图上绘制圆多边形

问题描述:

    借助Arcgis的Api在地图上绘制圆与多边形,查看Api的两个类Circle和Polygon

     Api地址:https://developers.arcgis.com/javascript/jsapi/


解决代码:

//画圆画多边形 ArcGIS API for JavaScript
require([
         "esri/geometry/Circle",
	 "esri/geometry/Polygon",
	 "esri/Map",
	 "esri/layers/GraphicsLayer",
	 "esri/Graphic"

	],function(Circle,Polygon,GraphicsLayer,Map){
	
	var map = new Map("map",{
		center:[-81.3765, 28.54175)],
		slider:false,
		maxZoom: 6,
		fadeOnZoom: true
	});
	var graLayer = new GraphicsLayer();
	
	//画圆  Circle类
	//定义要画的图形的线条颜色
	var symbol = new SimpleFillSymbol().setColor(null).outline.setColor("red");
	
	// lon 经度 lat纬度(圆的中心点) radius 半径
	function setCircle(lon,lat,radius){
		var pt = new Point(lon,lat,map.spatialReference);
		var radius = radius;
		var circle = new Circle({
			crenter: pt,
			geodesic: true,
			radius: radius
		});
		
		var graphic = new Graphic(circle,symbol);
		graLayer.add(graphic);
	}
	
	//画多边形  Polygon
	function setPolygon(){
		var polygon = new Polygon(new SpatialReference({wkid:4326}));
		//添加多边形的各个角的顶点坐标,注意:首尾要链接,也就是说,第一个点和最后一个点要一致
		polygon.addRing([[-180,-90],[-180,90],[180,90],[180,-90],[-180,-90]]);
		var graphic = new Graphic(circle,symbol);
		graLayer.add(graphic);
	}
	//创建地图服务图层
	var tiledMapServiceLayer = new ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer");
	map.addLayer(tiledMapServiceLayer);
	map.addLayer(graLayer);
	//打开地图
	map.centerAndZoom(new Point(-81.3765, 28.54175)),6);
});

遇到一个问题:就是地图上画出的圆不是一个圆,是一个椭圆,没找到原因,遇到的朋友交流一个解决办法,谢谢。(猜想是我图层的问题)
展开阅读全文

没有更多推荐了,返回首页