AnsweredAssumed Answered

base map+query buffer

Question asked by anjelinaponkerat on Nov 26, 2017
Latest reply on Nov 26, 2017 by anjelinaponkerat


I add query buffer to your sample code, but the map service can not show!!. 

 If I remove     map.addLayer(featureLayer);     from code the map service load ok . please help me





<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Display Multiple ArcGIS Online Services</title>
<link rel="stylesheet" href="">
<link rel="stylesheet" href="">
body {
height: 97%;
width: 98%;
margin: 1%;

#map {
border: solid 1px #B5BCC7;
padding: 0;

#paneHeader {
background: url(images/header.png) repeat-x;
color: white;
border-bottom: solid 1px #B5BCC7;
text-align: center;
height: 30px;
margin: 0;
overflow: hidden;
font-size: 16px;
padding: 8px 5px;

#rightPane {
width: 150px;
margin: 0;
padding: 0;

<script src=""></script>

var map;
"dojo/dom", "esri/Color", "dojo/keys", "dojo/parser", "esri/config",
"esri/sniff", "esri/map", "esri/SnappingManager", "esri/dijit/Measurement",
"esri/layers/FeatureLayer", "esri/renderers/SimpleRenderer", "esri/tasks/GeometryService",
"esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",

], function(
dom, Color, keys, parser, esriConfig,
has, Map,SnappingManager, Measurement,
FeatureLayer, SimpleRenderer, GeometryService,
SimpleLineSymbol, SimpleFillSymbol,
Scalebar, BasemapGallery, BasemapLayer, Basemap, OverviewMap, Locator, Search, PictureMarkerSymbol, InfoTemplate , HomeButton , Extent, SpatialReference, VisibleScaleRangeSlider, scaleUtils, VETiledLayer, Button, Query, Circle, Graphic, SimpleMarkerSymbol
) {

map = new Map("map");

var basemaps = [];
var waterTemplateLayer = new BasemapLayer({
url: ""
var waterBasemap = new Basemap({
layers: [waterTemplateLayer],
title: "Water Template",
thumbnailUrl: "images/waterThumb.png"
var publicSafetyLayer = new BasemapLayer({
url: ""
var publicSafetyBasemap = new Basemap({
layers: [publicSafetyLayer],
title: "Public Safety",
thumbnailUrl: "images/safetyThumb.png"

var basemapGallery = new BasemapGallery({
showArcGISBasemaps: false,
basemaps: basemaps,
map: map
}, "basemapGallery");

basemapGallery.on("error", function(error) {





 = "/proxy/";

// Add the census block points in on demand mode. An outfield is specified since it is used when calculating the total population falling within the one mile radius.
var featureLayer = new FeatureLayer("",{
outFields: ["POP2000"]

// Selection symbol used to draw the selected census block points within the buffer polygon
var symbol = new SimpleMarkerSymbol(
new SimpleLineSymbol(
new Color([247, 34, 101, 0.9]), 
new Color([207, 34, 171, 0.5])


// Make unselected features invisible
var nullSymbol = new SimpleMarkerSymbol().setSize(0);
featureLayer.setRenderer(new SimpleRenderer(nullSymbol));




var circleSymb = new SimpleFillSymbol(
new SimpleLineSymbol(
new Color([105, 105, 105]),
), new Color([255, 255, 0, 0.25])
var circle;

// When the map is clicked create a buffer around the click point of the specified distance
map.on("click", function(evt){
circle = new Circle({
center: evt.mapPoint,
geodesic: true,
radius: 1,
radiusUnit: "esriMiles"
var graphic = new Graphic(circle, circleSymb);;

var query = new Query();
query.geometry = circle.getExtent();
// Use a fast bounding box query. It will only go to the server if bounding box is outside of the visible map.
featureLayer.queryFeatures(query, selectInBuffer);

function selectInBuffer(response){
var feature;
var features = response.features;
var inBuffer = [];
// Filter out features that are not actually in buffer, since we got all points in the buffer's bounding box
for (var i = 0; i < features.length; i++) {
feature = features[i];
var query = new Query();
query.objectIds = inBuffer;
// Use an objectIds selection query (should not need to go to the server)
featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){
var totalPopulation = sumPopulation(results);
var r = "";
r = "<b>The total Census Block population within the buffer is <i>" + totalPopulation + "</i>.</b>";
dom.byId("messages").innerHTML = r;


function sumPopulation(features) {
var popTotal = 0;
for (var x = 0; x < features.length; x++) {
popTotal = popTotal + features[x].attributes["POP2000"];
return popTotal;









<body class="claro">
<span id="messages">Click on the map to select census block points within 1 mile.</span>


<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:true" style="width:100%;height:100%;">

<div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">

<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'" id="rightPane">

<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:false" style="width:100%;height:100%;">
<div id="paneHeader" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'">
<span>Select Basemap</span>
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
<div id="basemapGallery"></div>