I am trying to Geocode an Address then Buffer that address....from there I want to use that buffered graphic for further queries...
I can get the Geocode to work but stuck on getting the Buffer code to create the buffered graphic of which I need to use its geometry to run further queries..
Am I way off here?
// GEOCODER START===========================================================================================
var x = "";
var y = "";
var geocoder = new Geocoder({
arcgisGeocoder: {
placeholder: "4010 West Broad St, RIchmond, Virginia"
},
autoComplete: true,
map: app.map,
}, dom.byId("search"));
geocoder.startup();
geocoder.on("select", showLocation);
geocoder.on("clear", removeSpotlight);
function showLocation(evt) {
//app.map.graphics.clear();
var point = evt.result.feature.geometry;
x = point.x
y = point.y
var symbol = new SimpleMarkerSymbol().setStyle(
SimpleMarkerSymbol.STYLE_circle).setColor(
new Color([255,0,0,0.5])
);
var graphic = new Graphic(point, symbol);
app.map.graphics.add(graphic);
// ATTAMPT TO BUFFER THE RETURNED LOCATION
//----------------------------------------------------------------------------------------
var paramsGC = new BufferParameters();
paramsGC.geometries = graphic;
paramsGC.distances = [ .5 ];
//paramsGC.bufferSpatialReference = new SpatialReference({wkid: 26917});
paramsGC.outSpatialReference = app.map.spatialReference;
paramsGC.unit = GeometryService.UNIT_STATUTE_MILE;
// geometry service that will be used to perform the buffer
var geometryServiceGC = new GeometryService("https://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryServiceGC.buffer(paramsGC);
geometryServiceGC.on("buffer-complete", function(result){
app.map.graphics.clear();
// draw the buffer geometry on the map as a map graphic
var symbol2 = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_NULL,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([105,105,105]),
2
),new Color([255,255,0,0.25])
);
var bufferGeometryGC = result.geometries[0]
var graphicGC = new Graphic(bufferGeometryGC, symbol2);
app.map.graphics.add(graphicGC);
});
//-----------------------------------------------------------------------------------------
// GEOCODER END===================================================================================================
Solved! Go to Solution.
This is the code...
// GEOCODER START =================================================================
var x = "";
var y = "";
var geocoder = new Geocoder({
arcgisGeocoder: {
placeholder: "Dallas, Texas"
},
autoComplete: true,
map: app.map,
}, dom.byId("search"));
geocoder.startup();
geocoder.on("select", showLocation);
geocoder.on("clear", removeSpotlight);
function showLocation(evt) {
//app.map.graphics.clear();
var point = evt.result.feature.geometry;
var pointGC = evt.result.feature.geometry;
x = point.x
y = point.y
var symbol = new SimpleMarkerSymbol().setStyle(
SimpleMarkerSymbol.STYLE_circle).setColor(
new Color([255,0,0,0.5])
);
var graphic = new Graphic(point, symbol);
app.map.graphics.add(graphic);
//app.map.infoWindow.setTitle("Search Result");
//app.map.infoWindow.setContent(evt.result.name);
//app.map.infoWindow.show(evt.result.feature.geometry);
var symbol_historicArchitectureGC = new SimpleFillSymbol(
"solid",
new SimpleLineSymbol("solid", new Color([0,76,153]), 2),
new Color([0,128,255,0.5])
);
flVAFWIS_historicArchitecture.setSelectionSymbol(symbol_historicArchitectureGC);
// Add the Feature Layer To Map
app.map.addLayer(flVAFWIS_historicArchitecture);
var paramsGC = new BufferParameters();
paramsGC.geometries = [ pointGC ];
paramsGC.distances = [ .5 ];
//paramsGC.bufferSpatialReference = new SpatialReference({wkid: 26917});
paramsGC.outSpatialReference = app.map.spatialReference;
paramsGC.unit = GeometryService.UNIT_STATUTE_MILE;
// geometry service that will be used to perform the buffer
var geometryServiceGC = new GeometryService("https://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryServiceGC.buffer(paramsGC);
geometryServiceGC.on("buffer-complete", function(result){
// draw the buffer geometry on the map as a map graphic
var symbol22 = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_NULL,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([247,5,38]),
2
),new Color([255,255,0,0.25])
);
var bufferGeometryGC = result.geometries[0]
var graphicGC = new Graphic(bufferGeometryGC, symbol22);
app.map.graphics.add(graphicGC);
var query_historicArchitectureGC = new Query();
query_historicArchitectureGC.geometry = bufferGeometryGC;
// Select the Points within the Buffer and show them
flVAFWIS_historicArchitecture.selectFeatures(query_historicArchitectureGC, FeatureLayer.SELECTION_NEW, function(results){
});
});
} // End function showLocation(evt) {
// GEOCODER END =====================================================================
I tried to use the variable Point as well but nothing
var point = evt.result.feature.geometry;
var paramsGC = new BufferParameters();
paramsGC.geometries = point;
paramsGC.distances = [ .5 ];
Think I got it... forgot the [ ]
paramsGC.geometries = [ point ];
This is the code...
// GEOCODER START =================================================================
var x = "";
var y = "";
var geocoder = new Geocoder({
arcgisGeocoder: {
placeholder: "Dallas, Texas"
},
autoComplete: true,
map: app.map,
}, dom.byId("search"));
geocoder.startup();
geocoder.on("select", showLocation);
geocoder.on("clear", removeSpotlight);
function showLocation(evt) {
//app.map.graphics.clear();
var point = evt.result.feature.geometry;
var pointGC = evt.result.feature.geometry;
x = point.x
y = point.y
var symbol = new SimpleMarkerSymbol().setStyle(
SimpleMarkerSymbol.STYLE_circle).setColor(
new Color([255,0,0,0.5])
);
var graphic = new Graphic(point, symbol);
app.map.graphics.add(graphic);
//app.map.infoWindow.setTitle("Search Result");
//app.map.infoWindow.setContent(evt.result.name);
//app.map.infoWindow.show(evt.result.feature.geometry);
var symbol_historicArchitectureGC = new SimpleFillSymbol(
"solid",
new SimpleLineSymbol("solid", new Color([0,76,153]), 2),
new Color([0,128,255,0.5])
);
flVAFWIS_historicArchitecture.setSelectionSymbol(symbol_historicArchitectureGC);
// Add the Feature Layer To Map
app.map.addLayer(flVAFWIS_historicArchitecture);
var paramsGC = new BufferParameters();
paramsGC.geometries = [ pointGC ];
paramsGC.distances = [ .5 ];
//paramsGC.bufferSpatialReference = new SpatialReference({wkid: 26917});
paramsGC.outSpatialReference = app.map.spatialReference;
paramsGC.unit = GeometryService.UNIT_STATUTE_MILE;
// geometry service that will be used to perform the buffer
var geometryServiceGC = new GeometryService("https://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryServiceGC.buffer(paramsGC);
geometryServiceGC.on("buffer-complete", function(result){
// draw the buffer geometry on the map as a map graphic
var symbol22 = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_NULL,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([247,5,38]),
2
),new Color([255,255,0,0.25])
);
var bufferGeometryGC = result.geometries[0]
var graphicGC = new Graphic(bufferGeometryGC, symbol22);
app.map.graphics.add(graphicGC);
var query_historicArchitectureGC = new Query();
query_historicArchitectureGC.geometry = bufferGeometryGC;
// Select the Points within the Buffer and show them
flVAFWIS_historicArchitecture.selectFeatures(query_historicArchitectureGC, FeatureLayer.SELECTION_NEW, function(results){
});
});
} // End function showLocation(evt) {
// GEOCODER END =====================================================================
Jay,
put the following outside of your showLocation function:
var point;
and then remove the var in front of point inside your showLocation function, so that it looks like this:
point = evt.result.feature.geometry;
now it should be global and ready to be used in your BufferParameters.