Skip to content

Instantly share code, notes, and snippets.

@nommuna2
Last active April 26, 2019 21:56
Show Gist options
  • Save nommuna2/ad0a410056097d2a6222e8ae249a627a to your computer and use it in GitHub Desktop.
Save nommuna2/ad0a410056097d2a6222e8ae249a627a to your computer and use it in GitHub Desktop.
(ArcGIS API for JavaScript) Geometry Engine (cut and buffer)
//This example is using the geometry engine to buffer around a line and use the cut method to get two half's
require([
"esri/Map",
"esri/views/MapView",
"esri/geometry/Polyline",
"esri/geometry/geometryEngine",
"esri/symbols/SimpleLineSymbol",
"esri/Graphic",
"esri/symbols/SimpleFillSymbol",
"dojo/domReady!"
],
function (Map, MapView, Polyline, geometryEngine, SimpleLineSymbol, Graphic, SimpleFillSymbol) {
//Create the line for the buffer
var myPolyline = new Polyline({ //Lat long pairs
paths: [
[-105.48381445311824, 39.99523312315776],
[-90.47649023437224, 39.80981693207218]
]
});
//Create the line for the cutter. Make sure the cutter is longer than the buffer.
var cutterPolyline = new Polyline({
paths: [
[-106.80217382811804, 40.03309733400735],
[-88.77360937499783, 39.74649222301928]
]
});
//Call geometryEngine to buffer the line. Then call cut to cut the buffer in half.
var lineBuffer = geometryEngine.geodesicBuffer(myPolyline, 50, "miles");
var cut = geometryEngine.cut(lineBuffer, cutterPolyline); //This will return 2 geometries as an array.
//Symbols to render our buffer and cut polygon.
var mySimpleLineSymbol = new SimpleLineSymbol({
style: "solid",
color: "pink",
size: 20
});
var mySimpleFillSymbol = new SimpleFillSymbol({
color: "#1babd3",
style: "none"
});
var myLeftSideCUT = new SimpleFillSymbol({
color: "red",
});
//Add Symbols and Geometry to the Graphic.
var mygraphic = new Graphic({
geometry: myPolyline,
symbol: mySimpleLineSymbol
});
var myBufferGraphic = new Graphic({
geometry: lineBuffer,
symbol: mySimpleFillSymbol
});
var myLeftSideGraphic = new Graphic({
geometry: cut[0],
symbol: myLeftSideCUT
});
//Create a new map and set the basemap to Dark gray
var map = new Map({
basemap: "dark-gray",
});
//set a new view and set the properties of the view
var view = new MapView({
container: "viewDiv",
map: map,
center: [-86.049, 38.485],
zoom: 3
});
//Add Graphics onto the map.
view.graphics.add(mygraphic);
view.graphics.add(myBufferGraphic);
view.graphics.add(myLeftSideGraphic);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment