ArcGIS api for javascript——渲染-使用分级渲染

描述

本例使用一个分级渲染通过人口密度用符号表示Kansas。代码明确地增加类并为每一个定义颜色。使用ClassBreaksRenderer.addBreak()方法定义类,参数是在类中包含的最大值和最小值以及类使用的符号。

注意"Infinity"用于表示最后的中断没有上限。

  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"> <html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>Class Breaks Renderer</title> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.5/js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript">var djConfig = {parseOnLoad: true }</script>
<script type="text/javascript" src= "http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.5"></script> <script type="text/javascript" charset="utf-8">
dojo.require("esri.map");
dojo.require("esri.tasks.query"); var map; function init() {
map = new esri.Map("map", {
extent: new esri.geometry.Extent(-102.61, 36.2, -93.82, 40.5, new esri.SpatialReference({wkid: 4326})),
slider: false
});
dojo.connect(map, "onLoad", doQuery);
map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"));
} //查询所有国家 in Kansas
function doQuery(map) {
var queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3");
var query = new esri.tasks.Query();
query.outFields = ["*"];
query.returnGeometry = true;
query.outSpatialReference = map.spatialReference;
query.where = "STATE_NAME = 'Kansas'";
queryTask.execute(query, addFeatureSetToMap);
} //添加国家到地图并且应用渲染
function addFeatureSetToMap(featureSet) {
var symbol = new esri.symbol.SimpleFillSymbol();
symbol.setColor(new dojo.Color([150,150,150,0.5])); //Add five breaks to the renderer.
//If you have ESRI's ArcMap available, this can be a good way to determine break values.
//You can also copy the RGB values from the color schemes ArcMap applies, or use colors
//from a site like www.colorbrewer.org
var renderer = new esri.renderer.ClassBreaksRenderer(symbol, "POP07_SQMI");
renderer.addBreak(0,25,new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([56, 168, 0,0.5])));
renderer.addBreak(25,75,new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([139, 209, 0,0.5])));
renderer.addBreak(75,175,new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255,255,0,0.5])));
renderer.addBreak(175,400,new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255,128,0,0.5])));
renderer.addBreak(400,Infinity,new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255,0,0,0.5]))); map.graphics.setRenderer(renderer); var infoTemplate = new esri.InfoTemplate("${NAME}","${'*'}"); // 添加 features 到地图
dojo.forEach(featureSet.features, function(feature) {
map.graphics.add(feature.setInfoTemplate(infoTemplate));
});
} dojo.addOnLoad(init);
</script> </head>
<body>
<div id="map" class="tundra" style="width:800px; height:400px; border:1px solid #000;"></div>
</body>
</html>
上一篇:基于OpenGL编写一个简易的2D渲染框架-08 重构渲染器-整体架构


下一篇:ArcGIS api for javascript——渲染-使用唯一值渲染