Arcgis for Javascript实现图
首先,截个图给大家看结果:
初始化状态
放大后的状态
点击选中后的状态
如上图所看到的,一般的涉及到的地图的统计涉及到上述所展示的三个状态:1、初始化状态。2、缩放后的状态;3、点击选中显示详情状态。第一种状态下,载入统计图。一般来说,在地图上显示的统计图仅仅是一个趋势或者示意,具体的还得去点击显示。另外一种状态。随着地图的缩放,地图统计图随着地图的大小变化。第三种状态,点击选中,在信息框显示具体的统计图的信息。
首先,跟大家谈谈地图统计图几种实现方式。眼下情况下,在Arcgis for Javascript以下,实现统计图有三种方式。
1、示意图方式
示意图方式是最简单的一种方式。什么意思呢。就是用一个静态的png图片的方式,示意图的数据不代表真实的数据,示意在该状态时是地图统计图,具体的统计信息在点击示意图的时候才会出现。
2、后台生成图片方式
后台生成图片的方式也是有非常多人採取的一种解决方式,在这样的方式下,地图上的统计图的数据代表真实的数据信息,地图上的统计图是在后台用java或者c#生成的,并在地图上展示出来,并通过点击获取具体统计信息,这样的处理方式就是将压力交给server,减小client压力。可是显示的效果不好。
3、前台直接展示方式
前台直接展示是将统计数据传给前台,前台生成统计图的方式。这样的方式对client的压力比較大。并且从技术上来说,也是最难的。
了解了上述三种统计图的生成方式。接下来了解一下统计图在地图中的展示方式。
不论是上述那种方式。统计图在地图中的显示都是通过graphic和graphiclayer来展示的,仅仅是前两种展示的是栅格图,后一种方式展示的是矢量图,每个统计图是一个graphic对象。统计图在graphiclayer中显示。
下文将具体的讲述上述三种状态下的实现思路与方式。
第一,载入统计图。
在此,数据是json格式的。统计图的显示是通过X与Y去定位的,JSON的数据例如以下:
var CITY_DATA={
"total":34,
"items":[{"id":1,"name":"乌鲁木齐","X":87.575829,"Y":43.782212},
{"id":2,"name":"拉萨","X":91.162998,"Y":29.71042},
{"id":3,"name":"西宁","X":101.797303,"Y":36.593642},
{"id":4,"name":"兰州","X":103.584297,"Y":36.119086},
{"id":5,"name":"成都","X":104.035508,"Y":30.714179},
{"id":6,"name":"重庆","X":106.519115,"Y":29.478925},
{"id":7,"name":"贵阳","X":106.668071,"Y":26.457312},
{"id":8,"name":"昆明","X":102.726775,"Y":24.969385},
{"id":9,"name":"银川","X":106.167225,"Y":38.598524},
{"id":10,"name":"西安","X":108.967128,"Y":34.276112},
{"id":11,"name":"南宁","X":108.233931,"Y":22.748296},
{"id":12,"name":"海口","X":110.346181,"Y":19.96992},
{"id":13,"name":"广州","X":113.226683,"Y":23.18307},
{"id":14,"name":"长沙","X":112.947928,"Y":28.169916},
{"id":15,"name":"南昌","X":115.893715,"Y":28.652363},
{"id":16,"name":"福州","X":119.246768,"Y":26.070765},
{"id":17,"name":"台北","X":121.503567,"Y":25.008274},
{"id":18,"name":"杭州","X":120.183046,"Y":30.330584},
{"id":19,"name":"上海","X":121.449707,"Y":31.253361},
{"id":20,"name":"武汉","X":114.216597,"Y":30.579253},
{"id":21,"name":"合肥","X":117.262302,"Y":31.838353},
{"id":22,"name":"南京","X":118.805692,"Y":32.085022},
{"id":23,"name":"郑州","X":113.6511,"Y":34.746308},
{"id":24,"name":"济南","X":117.048331,"Y":36.60841},
{"id":25,"name":"石家","X":114.478215,"Y":38.033276},
{"id":26,"name":"太原","X":112.483066,"Y":37.798404},
{"id":27,"name":"呼和浩特","X":111.842806,"Y":40.895751},
{"id":28,"name":"天津","X":117.351094,"Y":38.925719},
{"id":29,"name":"沈阳","X":123.296299,"Y":41.801604},
{"id":30,"name":"长春","X":125.26142,"Y":43.981984},
{"id":31,"name":"哈尔","X":126.567138,"Y":45.69381},
{"id":32,"name":"北京","X":116.068276,"Y":39.892225},
{"id":33,"name":"香港","X":114.093117,"Y":22.427852},
{"id":34,"name":"澳门","X":113.552482,"Y":22.184495}
]
};
紧接着,就是显示统计图,代码例如以下:
var chartLayer = new GraphicsLayer({"id":"chartLayer"});
map.addLayer(chartLayer,1);
chartLayer.on("click",showDetailChart);
addReadPopup(CITY_DATA); function addReadPopup(data){
var items= data.items;
for(var i=0;i<data.total;i++){
var symbol = new PictureMarkerSymbol("bar.png",20,30);
symbol.setOffset(-10,18);
var pt=new Point(items[i].X,items[i].Y,map.spatialReference);
var graphic = new esri.Graphic(pt,symbol,items[i]);
chartLayer.add(graphic);
}
};
通过X与Y。将每个统计图通过graphic的方式加入到graphiclayer里。
第二。缩放时统计图大小的变化。
地图缩放时,统计图的大小也得随着地图的缩放发生相相应的变化,例如以下:
map.on("zoom-end",function(zoom){
var level=zoom.level;
var symbol = new PictureMarkerSymbol("bar.png",20*(level-3),30*(level-3));
symbol.setOffset(-10*(level-3),18*(level-3));
var graphics = chartLayer.graphics;
for(var i=0;i<graphics.length;i++){
graphics[i].symbol = symbol;
chartLayer.redraw();
}
});
这里。主要通过监听map的zoom-end事件,去又一次绘制统计图。
第三,点击显示具体图。
点击是监听的graphiclayer的click事件,点击图通过infowindow的方式显示具体统计图信息,这里面就好做多了,例如以下:
function showDetailChart(evt){
var graphic = evt.graphic;
graphic.symbol.url="bar_select.png";
chartLayer.redraw();
map.infoWindow.setTitle("<b>"+graphic.attributes.name+"</b>");
var content="<div style='text-align: center;'><img src='bar_detail.png'/></div>";
map.infoWindow.setContent(content);
map.infoWindow.show(graphic.geometry);
$(".maximize").hide();
$(".close").click(function(){
restoreChart(evt);
});
};
function restoreChart(evt){
var graphic = evt.graphic;
graphic.symbol.url="bar.png";
chartLayer.redraw();
};
通过以上几步,就基本上实现了地图统计图部分的功能。完整代码例如以下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Simple Map</title>
<link rel="stylesheet" href="http://localhost/arcgis_js_api/library/3.9/3.9/js/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;
margin: 0;
padding: 0;
}
body {
background-color: #FFF;
overflow: hidden;
font-family: "Trebuchet MS";
}
</style>
<script src="http://localhost/arcgis_js_api/library/3.9/3.9/init.js"></script>
<script src="jquery-1.8.3.js"></script>
<script>
var CITY_DATA={
"total":34,
"items":[{"id":1,"name":"乌鲁木齐","X":87.575829,"Y":43.782212},
{"id":2,"name":"拉萨","X":91.162998,"Y":29.71042},
{"id":3,"name":"西宁","X":101.797303,"Y":36.593642},
{"id":4,"name":"兰州","X":103.584297,"Y":36.119086},
{"id":5,"name":"成都","X":104.035508,"Y":30.714179},
{"id":6,"name":"重庆","X":106.519115,"Y":29.478925},
{"id":7,"name":"贵阳","X":106.668071,"Y":26.457312},
{"id":8,"name":"昆明","X":102.726775,"Y":24.969385},
{"id":9,"name":"银川","X":106.167225,"Y":38.598524},
{"id":10,"name":"西安","X":108.967128,"Y":34.276112},
{"id":11,"name":"南宁","X":108.233931,"Y":22.748296},
{"id":12,"name":"海口","X":110.346181,"Y":19.96992},
{"id":13,"name":"广州","X":113.226683,"Y":23.18307},
{"id":14,"name":"长沙","X":112.947928,"Y":28.169916},
{"id":15,"name":"南昌","X":115.893715,"Y":28.652363},
{"id":16,"name":"福州","X":119.246768,"Y":26.070765},
{"id":17,"name":"台北","X":121.503567,"Y":25.008274},
{"id":18,"name":"杭州","X":120.183046,"Y":30.330584},
{"id":19,"name":"上海","X":121.449707,"Y":31.253361},
{"id":20,"name":"武汉","X":114.216597,"Y":30.579253},
{"id":21,"name":"合肥","X":117.262302,"Y":31.838353},
{"id":22,"name":"南京","X":118.805692,"Y":32.085022},
{"id":23,"name":"郑州","X":113.6511,"Y":34.746308},
{"id":24,"name":"济南","X":117.048331,"Y":36.60841},
{"id":25,"name":"石家","X":114.478215,"Y":38.033276},
{"id":26,"name":"太原","X":112.483066,"Y":37.798404},
{"id":27,"name":"呼和浩特","X":111.842806,"Y":40.895751},
{"id":28,"name":"天津","X":117.351094,"Y":38.925719},
{"id":29,"name":"沈阳","X":123.296299,"Y":41.801604},
{"id":30,"name":"长春","X":125.26142,"Y":43.981984},
{"id":31,"name":"哈尔","X":126.567138,"Y":45.69381},
{"id":32,"name":"北京","X":116.068276,"Y":39.892225},
{"id":33,"name":"香港","X":114.093117,"Y":22.427852},
{"id":34,"name":"澳门","X":113.552482,"Y":22.184495}
]
};
var map, mapCenter;
require([
"esri/map",
"esri/layers/ArcGISTiledMapServiceLayer",
"esri/layers/FeatureLayer",
"esri/layers/GraphicsLayer",
"esri/geometry/Point",
"esri/symbols/PictureMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/renderers/SimpleRenderer",
"dojo/_base/Color",
"dojo/domReady!"],
function(Map,
Tiled,
FeatureLayer,
GraphicsLayer,
Point,
PictureMarkerSymbol,
SimpleLineSymbol,
SimpleRenderer,
Color)
{
map = new Map("map", {logo:false,slider: true});
var tiled = new Tiled("http://localhost:6080/arcgis/rest/services/chinamap/MapServer");
map.addLayer(tiled,0);
mapCenter = new Point(103.847, 36.0473, map.spatialReference);
map.centerAndZoom(mapCenter,4);
var chartLayer = new GraphicsLayer({"id":"chartLayer"});
map.addLayer(chartLayer,1);
chartLayer.on("click",showDetailChart);
addReadPopup(CITY_DATA); function addReadPopup(data){
var items= data.items;
for(var i=0;i<data.total;i++){
var symbol = new PictureMarkerSymbol("bar.png",20,30);
symbol.setOffset(-10,18);
var pt=new Point(items[i].X,items[i].Y,map.spatialReference);
var graphic = new esri.Graphic(pt,symbol,items[i]);
chartLayer.add(graphic);
} map.on("zoom-end",function(zoom){
var level=zoom.level;
var symbol = new PictureMarkerSymbol("bar.png",20*(level-3),30*(level-3));
symbol.setOffset(-10*(level-3),18*(level-3));
var graphics = chartLayer.graphics;
for(var i=0;i<graphics.length;i++){
graphics[i].symbol = symbol;
chartLayer.redraw();
}
});
};
function showDetailChart(evt){
var graphic = evt.graphic;
graphic.symbol.url="bar_select.png";
chartLayer.redraw();
map.infoWindow.setTitle("<b>"+graphic.attributes.name+"</b>");
var content="<div style='text-align: center;'><img src='bar_detail.png'/></div>";
map.infoWindow.setContent(content);
map.infoWindow.show(graphic.geometry);
$(".maximize").hide();
$(".close").click(function(){
restoreChart(evt);
});
};
function restoreChart(evt){
var graphic = evt.graphic;
graphic.symbol.url="bar.png";
chartLayer.redraw();
};
});
</script>
</head> <body>
<div id="map">
</div>
</body>
</html>
最后,第三种方式的实现眼下本人正在努力实现。实现后会第一时间与大家分享,如有不正确。还望指正!
如有疑问。请联系QQ:1004740957或者e-mail:niujp08@qq.com。联系请说明来意。谢谢!
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Arcgis for Javascript实现图的更多相关文章
- Arcgis for Javascript之featureLayer图和属性互操作性
说明:主要实现加载FeatureLayer并显示属性表,而要实现联动属性表与地图,首先,看看实施后的效果: 显示效果 如上图所看到的,本文章主要实现了下面几个功能:1.FeatureLayer属性表的 ...
- ArcGIS for JavaScript继承TiledMapServiceLayer来实现“动态切图”
这种方式可以提高出图速度于效果,算法见http://blog.newnaw.com/?p=633,我用ArcGIS for JavaScript API来实现.具体代码为: function init ...
- Arcgis for Javascript之featureLayer图和属性的互操作
说明:主要实现加载FeatureLayer与显示属性表,并实现属性表与地图的联动,首先,看看实现后的效果: 显示效果 如上图所示,本文章主要实现了以下几个功能:1.FeatureLayer属性表的分页 ...
- Arcgis for Javascript API下类似于百度搜索A、B、C、D marker的实现方式
原文:Arcgis for Javascript API下类似于百度搜索A.B.C.D marker的实现方式 多说无益,首先贴两张图让大家看看具体的效果: 图1.百度地图搜索结果 图2.Arcgis ...
- arcgis for javascript之ArcGISDynamicMapServiceLayer图层控制的实现
图层控制是非常多GIS系统里面必须的一个小功能,本文就说说arcgis for javascript下ArcGISDynamicMapServiceLayer图层控制的实现方式.首先看图: 实现效果 ...
- Arcgis for javascript map操作addLayer具体解释
本节的内容非常easy.说说Arcgis for Javascript里面map对象的addLayer方法.在for JS的API中,addLayer方法有两种.例如以下图: watermark/2/ ...
- 利用Arcgis for javascript API绘制GeoJSON并同时弹出多个Popup
1.引言 由于Arcgis for javascript API不可以绘制Geojson,并且提供的Popup一般只可以弹出一个,在很多专题图制作中,会遇到不少的麻烦.因此本文结合了两个现有的Arcg ...
- ArcGIS for JavaScript学习(一)
一 API准备 从网上下载开发包:ArcGIS for JavaScript(百度网盘地址) sdk中含有API的帮助和例子 2.离线部署(以IIS为例) 配置IIS(详见网络):解压离线包,包中的 ...
- Arcgis for Javascript之统计图的实现
首先,截个图给大家看看效果: 初始化状态 放大后的状态 点击选中后的状态 如上图所示,一般的涉及到的地图的统计涉及到上述所展示的三个状态:1.初始化状态:2.缩放后的状态:3.点击选中显示详情状态.第 ...
随机推荐
- ocx 中使用CImage和CComPtr
#include <atlimage.h> using namespace ATL;
- 【Codeforces Round #439 (Div. 2) C】The Intriguing Obsession
[链接] 链接 [题意] 给你3种颜色的点. 每种颜色分别a,b,c个. 现在让你在这些点之间加边. 使得,同种颜色的点之间,要么不连通,要么连通,且最短路至少为3 边是无向边. 让你输出方案数 [题 ...
- ios开发之级联菜单(两个tableView实现)
一:在ios项目实际开发中经常会看到级联菜单的效果:如图:点击左侧菜单,右侧菜单刷新数据.此篇用两个tableView来实现如图效果: 二:代码: 1:构造数据模型:利用kvc快速构建数据模型 #im ...
- JMS是一种应用于异步消息传递的标准API
JMS是一种应用于异步消息传递的标准API,作为Java平台的一部分,JMS可以允许不同应用.不同模块之间实现可靠.异步数据通信.一些概念 JMS provider An implementat ...
- CentOS下安装和配置MySQL-JDK-Tomcat-Nginx(个人官网环境搭建手册)
今天,重新弄我的个人云主机的环境,准备运营自己用Java写的个人官网等网站. 服务器环境:阿里云CentOS 6.4位 包括以下脚本在内的绝大部分命令和脚本,都是我亲自执行过,靠谱的. 完整的&quo ...
- 关于CoordinatorLayout与Behavior的一点分析
Behavior是Android新出的Design库里新增的布局概念.Behavior只有是CoordinatorLayout的直接子View才有意义.可以为任何View添加一个Behavior.Be ...
- 如何让eclipse输出结果的console栏自动换行?
在console栏内容上面,鼠标右键有个word-wrap,就行了
- NOIP 模拟 路径求和 - Tarjan+dfs+码
题目大意: 各一个奇环内向森林,求每两个点对间的距离之和.无法到达则距离为-1. 分析: 首先Tarjan找出size大于1的连通分量(环),环中的边的贡献可以单独计算. 然后从入度为0的点向内dfs ...
- Java中的浮点数-科学计数法-加减乘除
上次,提到"元转分"这个浮点数问题,boss倾向于手动把1.23元这种格式,转换成123分. 但实际上,浮点数很容易遇到精度问题. 比如,System.out.prin ...
- NSString与int和float的相互转换
NSString *tempA = @"123"; NSString *tempB = @"456"; 1,字符串拼接 NSString *newString ...