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("http://localhost:6080/arcgis/rest/services/Education_landusage/MapServer"); map.addLayer(layer); dojo.connect(map, "onClick", executeQueryTask); queryTask = new esri.tasks.QueryTask("http://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="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/esri/css/esri.css" /> <link rel="stylesheet" href="http://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="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/"></script> <script type="text/javascript" src="newjavascript.js"></script> </head> <body> <div id="map"></div> </body> </html>
3、设置样式
html,body,#map{ padding: 0; width: 100%; height: 100%; }