955
windows
2013年7月14日-地圖展示
1、在newjavascript中編寫如下代碼:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
dojo.require("esri.map");
dojo.require("esri.tasks.query");
//dojo.require("dojo.parser");
//dojo.require("dijit.layout.BorderContainer");
//dojo.require("dijit.layout.ContentPane");
//dojo.require("esri.dijit.Scalebar");
//dojo.require("esri.dijit.OverviewMap");
var queryTask, query;
var symbol, infoTemplate;
function init(){
//esri.config.defaults.io.proxyUrl = "Support/proxy.jsp";
map = new esri.Map("map");
var layer = new esri.layers.ArcGISDynamicMapServiceLayer("https://localhost:6080/arcgis/rest/services/Education_landusage/MapServer");
map.addLayer(layer);
dojo.connect(map, "onClick", executeQueryTask);
queryTask = new esri.tasks.QueryTask("https://localhost:6080/arcgis/rest/services/Education_landusage/MapServer/10");
query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["*"];
infoTemplate = new esri.InfoTemplate("${LAYER}","${*}");
symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SASHDOT,
new dojo.Color([255,0,0]),2), new dojo.Color([255,255,0],0.5));
}
function executeQueryTask(evt){
query.geometry = evt.mapPoint;
queryTask.execute(query,showResults);
}
function showResults(featureSet){
map.graphics.clear();
dojo.forEach(featureSet.features, function(feature){
var graphic = feature;
graphic.setSymbol(symbol);
graphic.setInfoTemplate(infoTemplate);
map.graphics.add(graphic);
});
}
dojo.ready(init);
2、在newhtml.html中編寫如下代碼:
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<title>Map</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="https://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/esri/css/esri.css" />
<link rel="stylesheet" href="https://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/dojo/dijit/themes/Nihilo/Nihilo.css" />
<link rel="stylesheet" href="newcss.css" />
<script type="text/javascript" src="https://serverapi.arcgisonline.com/jsapi/arcgis/3.4/"></script>
<script type="text/javascript" src="newjavascript.js"></script>
</head>
<body>
<div ></div>
</body>
</html>
3、設置樣式
html,body,#map{
padding: 0;
width: 100%;
height: 100%;
}
最後更新:2017-04-03 16:48:34