AnsweredAssumed Answered

Zoom to Selected Features

Question asked by Geohab on Sep 4, 2014
Latest reply on Oct 5, 2015 by davidchrest

Hi

 

I have used the JavaScript code below and works well. What it does is, using the 'Select Fields' button I can draw a polygon to select features, and clear the selected features by clicking the 'Clear Selection' button. What I want now is to zoom to the selected features by clicking on the 'Zoom to Selected Features' (this is not in the code). Can anyone help me please with the write code?

 

map.on("load", initSelectToolbar);


var fieldsSelectionSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.5]));


var content = "<b>ID No: <a target='_blank' href=${xxxx}>${IDNo}</a></b><br/><b>Sv Type: ${Sv_type}</b>";


var infoTemplate = new InfoTemplate("HSB", content);


featureLayer = new FeatureLayer("http://localhost:6080/arcgis/rest/services/webmapping/newboundary/xxxxxx", {
    mode: FeatureLayer.MODE_ONDEMAND,
    infoTemplate: infoTemplate,
    outFields: ["*"]
});




featureLayer.setSelectionSymbol(fieldsSelectionSymbol);


featureLayer.on("selection-clear", function () {


});
map.addLayer(featureLayer);


on(dom.byId("selectFieldsButton"), "click", function () {
    selectionToolbar.activate(Draw.EXTENT);
});


on(dom.byId("clearSelectionButton"), "click", function () {
    featureLayer.clearSelection();
});


function initSelectToolbar(event) {
    selectionToolbar = new Draw(event.map);
    var selectQuery = new Query();


    on(selectionToolbar, "DrawEnd", function (geometry) {
        selectionToolbar.deactivate();
        selectQuery.geometry = geometry;
        featureLayer.selectFeatures(selectQuery,
        FeatureLayer.SELECTION_NEW);


    });
}

Outcomes