<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Shapes and Symbols</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
<style>
html, body, #mapDiv {
padding:0;
margin:0;
height:100%;
}
#buttons {
top: 10px;
font-family: arial;
right: 50px;
position: absolute;
width: 300px;
z-index: 40;
}
</style>
<script src="http://js.arcgis.com/3.8/"></script>
<script>
var map, tb, polygon, query, featureSet;
require([
"esri/map", "esri/toolbars/draw", "esri/layers/FeatureLayer", "esri/tasks/query", "esri/graphicsUtils",
"esri/tasks/FeatureSet", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleMarkerSymbol",
"esri/graphic", "esri/geometry/Polygon", "esri/SpatialReference",
"dojo/_base/Color", "dojo/dom", "dojo/on", "dojo/_base/array", "dojo/domReady!"
], function(
Map, Draw, FeatureLayer, Query, graphicsUtils,
FeatureSet, SimpleFillSymbol, SimpleLineSymbol, SimpleMarkerSymbol,
Graphic, Polygon, SpatialReference,
Color, dom, on, array
) {
map = new Map("mapDiv", {
basemap: "streets",
center: [-81.792107, 26.150807],
zoom: 8
});
map.on("load", initToolbar);
var featureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0",{
mode: FeatureLayer.MODE_ONDEMAND,
});
var symbol = new SimpleMarkerSymbol(
SimpleMarkerSymbol.STYLE_CIRCLE,
12,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_NULL,
new Color([247, 34, 101, 0.9]),
1
),
new Color([207, 34, 171, 0.5])
);
featureLayer.setSelectionSymbol(symbol);
map.addLayer(featureLayer);
query = new Query();
polygon = new Polygon(new SpatialReference({wkid:102100}));
featureSet = new FeatureSet();
on(dom.byId("clear"), "click", function(){
map.graphics.clear();
featureLayer.clearSelection();
polygon = new Polygon(new SpatialReference({wkid:102100}));
})
on(dom.byId("zoom"), "click", zoom);
var fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NULL,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
new Color([255,0,0]), 2)
);
function initToolbar() {
tb = new Draw(map);
tb.on("draw-end", addGraphic);
tb.activate(Draw.FREEHAND_POLYGON);
}
function addGraphic(evt) {
map.graphics.add(new Graphic(evt.geometry, fillSymbol));
polygon.addRing(evt.geometry.rings[0]);
query.geometry = polygon.getExtent();
console.log(query.geometry);
featureLayer.queryFeatures(query, selectInBuffer);
}
function selectInBuffer(response){
var feature;
var features = response.features;
featureSet.features = features;
for (var i = 0; i < features.length; i++) {
feature = features;
if(polygon.contains(feature.geometry)){
var highlightGraphic = new Graphic(feature.geometry, symbol);
map.graphics.add(highlightGraphic);
}
}
}
function zoom(){
var myFeatureExtent = graphicsUtils.graphicsExtent(featureSet.features);
map.setExtent(myFeatureExtent, true);
}
});
</script>
</head>
<body>
<div id="mapDiv"></div>
<div id="buttons">
<input type="button" id="zoom" value="Zoom"/>
<input type="button" id="clear" value="Clear Graphics"/>
</div>
</body>
</html>