Skip to content

Instantly share code, notes, and snippets.

@ajturner
Last active December 12, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ajturner/4686451 to your computer and use it in GitHub Desktop.
Save ajturner/4686451 to your computer and use it in GitHub Desktop.
Esri API example to draw arcs.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title></title>
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">
<style>
html, body, #map {
height: 100%; width: 100%; margin: 0; padding: 0;
}
</style>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>
<script>
var map, toolbar;
require(["esri/map", "esri/toolbars/draw"],
function() {
map = new esri.Map("map", {
basemap: "streets",
center: [ 19.291, 48.343 ],
zoom: 4
});
map.addLayer(new esri.layers.GraphicsLayer({ id: "arcs" }));
dojo.connect(map, "onLoad", function() {
toolbar = new esri.toolbars.Draw(map);
toolbar.activate(esri.toolbars.Draw.POINT);
dojo.connect(toolbar, "onDrawEnd", addToMap);
});
function addToMap(geom) {
map.graphics.add(new esri.Graphic(
geom,
new esri.symbol.SimpleMarkerSymbol()
));
var total = map.graphics.graphics.length
if ( ( total % 2) == 0 ) {
// draw a geodesic line between the last two graphics
var p1 = esri.geometry.webMercatorToGeographic(map.graphics.graphics[total-2].geometry);
var p2 = esri.geometry.webMercatorToGeographic(map.graphics.graphics[total-1].geometry);
console.log("p1 and p2: ", p1, p2);
var geographicLine = new esri.geometry.Polyline(new esri.SpatialReference(4326));
geographicLine.addPath([p1, p2]);
var line = esri.geometry.geodesicDensify(geographicLine, 5000);
map.getLayer("arcs").add(new esri.Graphic(
line,
new esri.symbol.SimpleLineSymbol()
));
console.log("added arc...");
}
}
}
);
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment