Select to view content in your preferred language

HIghlight map:new bie

1926
18
08-21-2013 03:49 AM
vinayb
by
Deactivated User
HI All,

  I am new bie and we want to develop a world map which has only countries , no street or any other level .I want functionalists where when i click on any country i should be able to highlight it and also display some pop-up.I want use java-script api, can anybody let me know if  this can be achieved and how do i get started.
0 Kudos
18 Replies
vinayb
by
Deactivated User
Thank you.

Help me understand , we have people you can develop shape files.If i ask them to develop shape file , which has country boundries, if i push to aig server can i use that to do the functionality that i told u like , if i want to highlight us can i do something like dojo.byId('us') and highlight.Please guide me on this.
0 Kudos
VinayBansal
Frequent Contributor
Hi Vinay,

You can do these things to achieve this :
1. Create MXD from you shape file. or Create a FGDB and import shapefile  to FGDB and add layer in MXD from FGDB
2. Publish it to ArcGIS Server using ArcMap.
3. You cannot access the country using dojo.byId('us') as you were trying to do....
4. You need to then follow this sample to highlight the countries
https://developers.arcgis.com/en/javascript/jssamples/fl_no_basemap.html
0 Kudos
vinayb
by
Deactivated User
Thanks a lot,

  by the highlighting part is where i am struck actually , the example that u pointed out get the region attribute when u click on map but here what i want is vice versa, i want to provide region and highlight , this is very important for me so please point out something.
0 Kudos
VinayBansal
Frequent Contributor
Thanks a lot,

  by the highlighting part is where i am struck actually , the example that u pointed out get the region attribute when u click on map but here what i want is vice versa, i want to provide region and highlight , this is very important for me so please point out something.


You can use querytask to query on the layer and highlight on the map.
https://developers.arcgis.com/en/javascript/jssamples/fl_paging.html
0 Kudos
vinayb
by
Deactivated User
Great , I know i have to use query task to query the service.But my question is if i query

http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/2

which has reqion as fields that it return , i will get string but how will i use this string to highlight map , how will i identify the reqion or how i get that reqion object.Plz help.

Also can i query only feature layer , i check in ArcGISDynamicMapServiceLayer there is no help for query.
0 Kudos
VinayBansal
Frequent Contributor
Great , I know i have to use query task to query the service.But my question is if i query

http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/2

which has reqion as fields that it return , i will get string but how will i use this string to highlight map , how will i identify the reqion or how i get that reqion object.Plz help.

Also can i query only feature layer , i check in ArcGISDynamicMapServiceLayer there is no help for query.


When you query, you will get the featureset of features with attributes and graphic. If you specify returnGeometry = true in query. You can use the geometry returned to highlight to map
https://developers.arcgis.com/en/javascript/jssamples/query_click.html
0 Kudos
vinayb
by
Deactivated User
Great I was able to do that ,below is the code
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Feature Layer Only Map</title>
    <link rel="stylesheet" href="http://js.arcgis.com/3.6/js/esri/css/esri.css">
    <style>
      html, body, #map {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
    <script src="http://js.arcgis.com/3.6/"></script>
    <script>
      require([
        "dojo/dom-construct", 
        "esri/map", 
        "esri/layers/FeatureLayer",
        "esri/geometry/Extent",
        "esri/InfoTemplate",
        "dojo/domReady!"
      ], function(
          domConstruct,
          Map,
          FeatureLayer,
          Extent,
          InfoTemplate
        ) {
          var bounds = new Extent({
            "xmin":-16045622,
            "ymin":-811556,
            "xmax":7297718,
            "ymax":11142818,
            "spatialReference":{"wkid":102100}
          });

          var map = new Map("map", { 
            extent: bounds
          });
          
          
          

          var url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/2";

          var template = new InfoTemplate("World Regions", "Region: ${REGION}");

          var fl = new FeatureLayer(url, {
            id: "world-regions",
            //infoTemplate: template
          });
          
          require(["dojo/on", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "dojo/_base/Color", "esri/graphic"], function(on, SimpleFillSymbol, SimpleLineSymbol, Color, Graphic) {
                    on(fl, "click", function(evt) {
                        var queryTask = new esri.tasks.QueryTask(url);

      //build query filter
      var query = new esri.tasks.Query();
      query.returnGeometry = true;
                        query.where = "REGION='Central America'";
      dojo.connect(queryTask, "onComplete", function(featureSet) {
      map.graphics.clear();
      var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_FORWARD_DIAGONAL, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.5]));
                        //QueryTask returns a featureSet.  Loop through features in the featureSet and add them to the map.
        dojo.forEach(featureSet.features,function(feature){
       var graphic = feature;
       graphic.setSymbol(sfs);
      map.graphics.add(graphic);
          });
        });
        queryTask.execute(query);
    });
});
          
          map.addLayer(fl);
        }
      );
    </script>
  </head>
  <body>
    <div id="map"></div>
  </body>
</html>


do i have to query only the feature layer is there an option for  ArcGisDynamicMapService layer.
Secondly for highlighting is there any alternative way is it only this way?
0 Kudos
VinayBansal
Frequent Contributor


do i have to query only the feature layer is there an option for  ArcGisDynamicMapService layer.
Secondly for highlighting is there any alternative way is it only this way?



Yes you can do that for ArcGISDynamicMapService layer also.
1. Add ArcGISDynamicMapServiceLayer on map,
2. Then in querytask pass the url that you are using for creating the featurelayer.
3. Rest follow the same procedure fr highlighting the feature.
0 Kudos
vinayb
by
Deactivated User
Thank you i was able to query for featue layer i am trying to do that on dynamicMapservice.I have one question i was able to highlight the map on load of the page but it could not highlight it completly ,that i was covered on the boudry and some solid strokes in between if i want to completely cover india how do that .I know below is the piece of code which will do that but i am unable to modify it , could you please help.


var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_FORWARD_DIAGONAL, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.5]));
0 Kudos