1. 程式人生 > >給定點,繪製路徑,點選point,彈出infoTemplate

給定點,繪製路徑,點選point,彈出infoTemplate

var pt1=new Point( {"x":2262826.1689284374, "y": 548956.7494148497, "spatialReference": {"wkid": 102021 } });
var pt2=new Point( {"x":2261863.0518302172, "y": 548038.0813060887, "spatialReference": {"wkid": 102021 } });

var points = [pt1, pt2];
//create polyline
var line = new esri.geometry.Polyline(map.spatialReference
); line.addPath(points); var pointSym = new esri.symbol.SimpleMarkerSymbol(); var lineSym = new esri.symbol.SimpleLineSymbol().setColor(new dojo.Color("blue")); var infoTemplate = new esri.InfoTemplate("title","content"); var gLayer = new GraphicsLayer({ "id" : "scratch" }); // create a graphic var
pt1Graphic = new esri.Graphic(pt1, pointSym); var pt2Graphic = new esri.Graphic(pt2, pointSym); pt1Graphic.setInfoTemplate(infoTemplate); pt2Graphic.setInfoTemplate(infoTemplate); var lineGraphic = new esri.Graphic(line, lineSym); // add it to the graphics layer gLayer.add(lineGraphic); gLayer.add(pt1Graphic
); gLayer.add(pt2Graphic); // add the graphics layer to the map map.addLayer(gLayer);