您的位置:首页 > Web前端 > JavaScript

Arcgis api for JavaScript学习笔记之Graphic

2018-05-12 13:35 99 查看

1、Class: Graphic

A Graphic can contain geometry, a symbol, attributes, or an infoTemplate. A Graphic is displayed in the GraphicsLayer. The GraphicsLayer allows you to listen for events on Graphics.//Graphic是一个超类,是geometry、symbol、attribute类的集合类。是常用的,便捷的。

构造器:new Graphic(geometry?, symbol?, attributes?, infoTemplate?)/new Graphic(json)

2、Class: GraphicsLayer

A layer that contains one or more Graphic features//用于承接Graphic要素的图层,总是位于动态图层和切片栅格图层之上,地图容器默认带一个,通过Map.graphics调用,也可以自定义创建new GraphicsLayer(),是FeatureLayer的父类。

PS:GraphicsLayer和普通的图层一样,如果要在地图上显示的话,需要map.addLayer(graphicLayer);

3、Class: Geometry

The base class for geometry objects. This class has no constructor.default spatial reference of 4326 if one is not explicitly provided in the constructor.//几何对象基类,默认空间参考4326,geometry只是几何图形的对象,不包含属性信息,属性信息包含在graphic中

子类:ExtentMultipointPointPolygonPolyline

4、Class: FeatureSet

A collection of features//是要素的数组,可以用来承接生成的多个g 267c5 raphic对象。  var graphic = new Graphic( ... );
  var features= [];
  features.push(graphic);
  var featureSet = new FeatureSet();
  featureSet.features = features;

实例应用:

1.获取GraphicLayer的Graphic对象数组

var point1 = new Point(111.1, 29.8, new SpatialReference({ wkid: 4326 }));//创建点对象,是geometry对象
var point2 = new Point(112.1, 29.8, new SpatialReference({ wkid: 4326 }));
var graphic1 = new Graphic(point1, new SimpleMarkerSymbol());//创建包含point1的graphic对象
var graphic2 = new Graphic(point2, new SimpleMarkerSymbol());
var graphicLayer = new GraphicsLayer();//创建graphicLayer对象,用来承接展示创建的graphic对象
graphicLayer.add(graphic1);//将grapic对象添加到graphiclayer图层中
graphicLayer.add(graphic2);
map.addLayer(graphicLayer);//将graphiclayer图层加载到map(地图)容器内显示
//创建featureSet对象,该对象用来可以简单理解为graphic对象的数组对象
var featureSet = new FeatureSet();
//调用graphicLayer的graphics属性(Properties),该属性的类型是Graphic[],返回的是改graphicLayer图层所包含的Graphic对象数组
var g=graphicLayer.graphics;
//再将这个Graphic[]赋予FeatureSet对象,featureSet的features属性同样是Graphic[]类型,可以用于承接GraphicLayer上返回的Graphic[]
featureSet.features=g;
//现在featureSet中就包含了graphic1,和graphic2了
2.从FeatureSet对象调用Graphic对象或直接从GraphicLayer图层(对象)调用Graphic对象        //1)g1即是featureSet中包含的第一个Graphic对象
var g1=featureSet.features[0];
//featureLyer是特殊的GraphicLayer,是其子类
var g2=featureLayer.graphics[0];
var g3=graphicLayer.graphics[0];
//2)通过遍历调用
dojo.forEach(featureSet.features, function (feature) {
...
});[/code]
PS:调用时应注意要现实例化图层对象之后,才能对使用图层对象的方法(如使用FeatureLayer的graphics属性,featureLayer.graphics)。也就是最好不要同时实例化图层对象和使用图层对象的方法/属性,否则会出现如“graphics undefinded”之类的错误,错误的原因就是调用对象方法/属性时,由于图层对象实例化并没有反馈出来,导致不能获取实例化的图层对象,从而使调用方法/属性出错。

以上便是关于Arcgis API for JavaScript的此四个类的介绍及实例。

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐