graphThemeLayer Class

graphThemeLayer(name, chartsType, options)

统计专题图图层。

Fx构造函数

# new graphThemeLayer(name, chartsType, options)

统计专题图通过为每个要素绘制统计图表来反映其对应的专题值的大小。它可同时表示多个字段属性信息,在区域本身与各区域之间形成横向和纵向的对比。
统计专题图多用于具有相关数量特征的地图上,比如表示不同地区多年的粮食产量、GDP、人口等,不同时段客运量、地铁流量等。目前提供的统计图类型有:柱状图(Bar),折线图(Line),饼图(Pie),三维柱状图(Bar3D),点状图(Point),环状图(Ring)。

参数:
名称 类型 属性 默认值 描述
name string

专题图表名称。

chartsType string

图表类型。目前可用:"Bar","Bar3D","Line","Point","Pie","Ring"。

options Object

待设置的参数。

isOverLay boolean <optional>
true

是否进行压盖处理,如果设为 true,图表绘制过程中将隐藏对已在图层中绘制的图表产生压盖的图表。

themeFields string

指定创建专题图字段。

cache Object <optional>

缓存。

charts Object <optional>

图表。

id string <optional>

专题图层 ID。默认使用 CommonUtil.createUniqueID("themeLayer_") 创建专题图层 ID。

opacity number <optional>
1

图层透明度。

chartsSetting Object

各类型图表的 chartsSetting 对象可设属性请参考具体图表模型类的注释中对 chartsSetting 对象可设属性的描述。chartsSetting 对象通常都具有以下 5 个基础可设属性:

chartsSetting.width number

专题要素(图表)宽度。

chartsSetting.height number

专题要素(图表)高度。

chartsSetting.codomain Array.<number>

值域,长度为 2 的一维数组,第一个元素表示值域下限,第二个元素表示值域上限。

chartsSetting.XOffset number <optional>

专题要素(图表)在 X 方向上的偏移值,单位像素。

chartsSetting.YOffset number <optional>

专题要素(图表)在 Y 方向上的偏移值,单位像素。

chartsSetting.dataViewBoxParameter Array.<number> <optional>

数据视图框 dataViewBox 参数,它是指图表框 chartBox (由图表位置、图表宽度、图表高度构成的图表范围框)在左、下,右,上四个方向上的内偏距值,长度为 4 的一维数组。

chartsSetting.decimalNumber number <optional>

数据值数组 dataValues 元素值小数位数,数据的小数位处理参数,取值范围:[0, 16]。如果不设置此参数,在取数据值时不对数据做小数位处理。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 9

继承关系

  • Zondy.map.ThemeLayer

方法

# addFeatures(features)

向专题图图层中添加数据。

参数:
名称 类型 描述
features L.features

待添加的要素。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 68

# clear()

清除图层。清除的内容包括数据(features) 、专题要素、缓存。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 471

# clearCache(mapPxBounds, chartPxBounds)

判断图表是否大小合适,超过地图范围的1/4的不绘制。

参数:
名称 类型 描述
mapPxBounds Zondy.Bounds

地图像素范围。

chartPxBounds Array.<Object>

图表范围的四边形节点数组。
例如:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y":1}]。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 416

# clearCache()

清除缓存数据。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 431

# createThematicFeature(feature)

创建专题要素(图表)。

参数:
名称 类型 描述
feature Zondy.Feature

待创建的要素。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 160

# drawCharts()

绘制图表。包含压盖处理。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 182

# getShapesByFeatureID(featureID)

通过 FeatureID 获取 feature 关联的所有图形。如果不传入此参数,函数将返回所有图形。

参数:
名称 类型 描述
featureID number

要素 ID。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 208

# getWeightFieldValue(feature, weightField, defaultValue)

获取权重字段的值。

参数:
名称 类型 描述
feature Zondy.Feature.Vector

矢量要素。

weightField Array.<string>

字段名数组。

defaultValue number

当通过 weightField 获取不到权重值时,使用 defaultValue 作为权重值。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 485

# isChartInMap(mapPxBounds, chartPxBounds)

判断图表是否在地图里。

参数:
名称 类型 描述
mapPxBounds Zondy.Bounds

地图像素范围。

chartPxBounds Array.<Object>

图表范围的四边形节点数组。 例如:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y":1}]。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 373

# isPointInPoly(pt, poly)

判断一个点是否在多边形里面。(射线法)

参数:
名称 类型 描述
pt Object

需要判定的点对象,该对象含有属性x(横坐标),属性y(纵坐标)。

poly Array.<Object>

多边形节点数组。
例如一个四边形:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y":1}]

查看源代码 leaflet/theme/GraphThemeLayer.js, line 357

# isQuadrilateralOverLap(rect1, rect2)

判断两个四边形是否有压盖。

参数:
名称 类型 描述
rect1 Array.<Object>

四边形节点数组。

rect2 Array.<Object>

第二个四边形节点数组。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 231

Example
[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y":1}];

# lineIntersection(a1, a2, b1, b2) → {Object}

判断两条线段是不是有交点。

参数:
名称 类型 描述
a1 Zondy.Geometry.Point

第一条线段的起始节点。

a2 Zondy.Geometry.Point

第一条线段的结束节点。

b1 Zondy.Geometry.Point

第二条线段的起始节点。

b2 Zondy.Geometry.Point

第二条线段的结束节点。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 311

如果相交返回交点,如果不相交返回两条线段的位置关系。

Object

# redraw()

重绘该图层,成功则返回 true,否则返回 false。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 461

# redrawThematicFeatures(bounds)

重绘所有专题要素 此方法包含绘制专题要素的所有步骤,包含用户数据到专题要素的转换,压盖处理,缓存等步骤。地图漫游时调用此方法进行图层刷新。

参数:
名称 类型 描述
bounds L.bounds

重绘的范围。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 114

# removeAllFeatures()

清除当前图层所有的矢量要素。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 451

# removeFeatures(features)

从专题图中删除 feature。这个函数删除所有传递进来的矢量要素(数据)。

参数:
名称 类型 描述
features Object

待删除的要素。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 440

# setChartsType(chartsType)

设置图表类型,此函数可动态改变图表类型。在调用此函数前请通过 chartsSetting 为新类型的图表做相关配置。图表类型,目前支持:"Bar", "Bar3D", "Line","Point","Pie","Ring"。

参数:
名称 类型 描述
chartsType string

图表类型。目前可用:"Bar", "Bar3D", "Line","Point","Pie","Ring"。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 58

事件

# beforefeaturesadded

向专题图图层中添加数据之前触发。

属性:
Name Type Description
features L.features

待添加的要素。

查看源代码 leaflet/theme/GraphThemeLayer.js, line 75