本人对地理信息相关知识一窍不通,由于公司目前要基于arcgis做数据展现,于是进行arcgis for js的开发学习,思路很清晰,但是困难很多,搞了两三天,才在发布的地图图层上根据给定的经纬度数据进行标注,不过这个做好了,下面就目标清晰了,无非是从后台取数据,然后在前台进行展现;
基于js的arcgis开发,需要学习以下知识:
1. 地理信息相关的基础知识
2. dojo js框架的学习
3. arcgis for js api的熟悉(https://developers.arcgis.com/javascript/jsapi/polygon-amd.html)
以下是代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My fisrt ArcGis Map</title>
<link rel="stylesheet" type="text/css"
href="http://localhost:8080/gis/arcgis_js/js/dojo/dijit/themes/tundra/tundra.css" />
<link rel="stylesheet" type="text/css"
href="http://localhost:8080/gis/arcgis_js/js/esri/css/esri.css" />
<script type="text/javascript"
src="http://localhost:8080/gis/arcgis_js/init.js"></script>
<script type="text/javascript">
var myMap;
require([
"esri/map", "esri/toolbars/draw",
"esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol","esri/symbols/PictureMarkerSymbol","esri/geometry/Point","esri/layers/GraphicsLayer",
"esri/symbols/PictureFillSymbol", "esri/symbols/CartographicLineSymbol", "esri/SpatialReference","esri/InfoTemplate",
"esri/graphic",
"dojo/_base/Color", "dojo/dom", "dojo/on", "dojo/domReady!"
], function(
Map, Draw,
SimpleMarkerSymbol, SimpleLineSymbol,PictureMarkerSymbol,Point,GraphicsLayer,
PictureFillSymbol, CartographicLineSymbol, SpatialReference,InfoTemplate,
Graphic,
Color, dom, on
) {
myMap = new Map("arcgisDiv");
dojo.connect(myMap, "onClick", showCoordinatesAndAddPoint);
dojo.connect(myMap, "onLoad", graphicLoad);
var myTiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer(
"http://192.168.254.161:8080/arcgis/rest/services/GISServer/farmland/ImageServer");
myMap.addLayer(myTiledMapServiceLayer);
function showCoordinatesAndAddPoint(evt) {
//get mapPoint from event
var mp = evt.mapPoint; // 可以从mp对象的属性中查找到图层对应的wkid的值,这个值和下面红色注释的值要保持一致
//display mouse coordinates
dojo.byId("info").innerHTML = mp.x + ", " + mp.y;
// 102100
var newPoint = new Point(mp.x, mp.y, new SpatialReference({ wkid: 102100 }));
var picSymbol = new PictureMarkerSymbol("http://localhost:8080/gis/images/chaosu.png", 20, 20);
var picGraphic = new Graphic(newPoint, picSymbol);
myMap.graphics.add(picGraphic);
}
function graphicLoad()
{
// new SpatialReference({ wkid: 102100 }) 这个参数必须加,而且wkid的值要和图层保持一致,否则显示不出来,这个值可以从
var newPoint = new Point(13184586.725552682, 3951448.604221201, new SpatialReference({ wkid: 102100 }));
var picSymbol = new PictureMarkerSymbol("http://localhost:8080/gis/images/chaosu.png", 20, 20);
var picGraphic = new Graphic(newPoint, picSymbol);
var infoTemplate = new InfoTemplate();
infoTemplate.setTitle("hello world");
infoTemplate.setContent("hello world说说撒 hello world");
picGraphic.setInfoTemplate(infoTemplate);
myMap.graphics.add(picGraphic);
}
});
</script>
</head>
<body class="tundra">
<div id="arcgisDiv"
style="width: 900px; height: 600px; border: 1px solid #000;"></div>
<div id="info"></div>
</body>
</html>