Select to view content in your preferred language

Layer Activation with button/icon

539
1
02-19-2012 08:11 AM
AzizulAlam1
Deactivated User
Hello,
I am new at JS API. I am trying to learn and apply this API. I want to display a point feature that will activate with click on button or icon or any link. I saw a sample with button click in ArcGIS Google API extension that is called query a point layer. I am giving the code here. I just want the same thing but not with Google.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html debug=true>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Query Task (Returns Point)</title>

    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=DioG219lPJG3WTn3zmQqebsjVg" type="text/javascript"></script>
    <script src="http://serverapi.arcgisonline.com/jsapi/gmaps/?v=1.6" type="text/javascript" ></script>

    <script type="text/javascript">

      var gmap = null;
      var qtask = null;
      var query = null;
      var mapExtension = null;
      var gOverlays = null;

      function initialize() {
        // GMap construction
        gmap = new GMap2(document.getElementById('gmap'));
        gmap.addMapType(G_NORMAL_MAP);
        gmap.addMapType(G_SATELLITE_MAP);
        gmap.addControl(new GLargeMapControl());
        gmap.addControl(new GMapTypeControl());
        gmap.setCenter(new GLatLng(33.96964806519751, -117.37674951553345), 17); // RIVERSIDE (Point)
        gmap.enableScrollWheelZoom();


        //Create MapExtension utility class
        mapExtension = new esri.arcgis.gmaps.MapExtension(gmap);


        // Query Task
        qtask = new esri.arcgis.gmaps.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0");

        // You can execute a task and listen for the complete event or use the callback to get the results
        GEvent.addListener(qtask, "executecomplete", function() {
          //console.debug("'query task complete' event fired!!!");
        });

        // Query
        query = new esri.arcgis.gmaps.Query();
      }

      function executeQuery() {
        var bounds = gmap.getBounds();

        // clear map overlays and event listeners using MapExtension removeFromMap
        mapExtension.removeFromMap(gOverlays);

        // set query parameters
        query.queryGeometry = bounds;
        query.returnGeometry = true;

        // execute query task
        qtask.execute(query, false, mycallback);

      }

      function mycallback(fset) {
        // add the feature set to google map without any style
        gOverlays = mapExtension.addToMap(fset);
      }

    </script>

  </head>

  <body onload="initialize();" onunload="GUnload();">
  <table width="100%" height="100%">
    <tr>
      <td align="center">

        <table>
          <tr align="left">
            <td>
              <input type="button" value="Execute Query" onclick="executeQuery();" /> 

              <input type="button" value="Clear Map Overlays" onclick="mapExtension.removeFromMap(gOverlays);" />
            </td>
          </tr>

          <tr align="left" valign="top">
            <td>
              <div id="gmap" style="width: 500px; height:500px;"></div>
            </td>
          </tr>


        </table>

      </td>
    </tr>
  </table>
  </body>
</html>


What I have to do if I do the same thing in ArcGIS Javascript API???

Azizul Alam Toton
Asst. GIS Specialist
Data Expert (Pvt.) Ltd
Bangladesh
0 Kudos
1 Reply
EdSaunders
Regular Contributor
Hi Azizul,

Can you give some more info?  Do you want to display a layer in a web app?  You can do that using the following code:

Add layer to map
       var featureLayer = new esri.layers.FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/MapServer/1",{
          mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
          outFields: ["*"],
          visible: false,
          infoTemplate: infoTemplate
        });
        map.addLayer(featureLayer);


Then, to display the layer
featureLayer.show();
0 Kudos