HIghlight map:new bie

1067
18
08-21-2013 03:49 AM
vinayb
by
New Contributor III
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
BetsySchenck-Gardner
Occasional Contributor
Hi VinayBa,
There is a perfect example of what you want to achieve in the samples section. Here's the link:
    https://developers.arcgis.com/en/javascript/jssamples/fl_no_basemap.html
The map service comes from Esri that just has world regions displayed ... no other basemap details. When you click on any of the countries, it is highlighted and displayed with just some very general information as well as a zoom function. You can edit the infoTemplate to provide more details to your popup. Hope this can get you started.
Regards,
Betsy
0 Kudos
vinayb
by
New Contributor III
Thanks a lot,

but i am unable to understand the example.I want to know where is the code which has on mouse click event where it highlights the country , i want to overide it and provide my own funcitonality how can this be done.?
0 Kudos
JakubMalec
New Contributor III
There's a "onClick" event available for the FeatureLayer. When a graphic of a FeatureLayer is clicked on a map it returns the graphic that has been clicked.

In the sample there's an infoTemplate specified for the layer which adds onclick behavior (highlights the region polygon and shows the graphic attributes in a popup).

In the sample above you could add your onClick listener after "fl" variable instantiation:
require(["dojo/on"], function(on){
    on(fl, "click", function(evt) {
        // do something with evt.graphic - get it's attributes and display them somewhere, edit it's symbol, reshape it etc.
    });
});
0 Kudos
vinayb
by
New Contributor III
Great , it worked .Thank you .But there is a default behavior where the boundaries of the   countries are highlighted,where is it coming from , is it rest service provided by the arcgis.I want a complete different map and on click i want to highlight whole country not just boundaries how can i do this.Plz help

   Plz explain where is functionality of highlighting defined.
0 Kudos
JakubMalec
New Contributor III
The highlight in the sample comes from the default behavior that comes with the infoTemplate.
That's how you can create your own highlight on click:
                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) {
                        
                        // clears current selection
                        map.graphics.clear();
                        
                        // create new graphic with selected graphic's geometry
                        var graphic = new Graphic(evt.graphic.geometry);
                        
                        // create a new symbol for the graphic
                        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]));
                        
                        // add symbol to the graphic
                        graphic.setSymbol(sfs);     
                        
                        // add the graphic to the map   
                        map.graphics.add(graphic);
                    });
                });


Also instead of adding the graphic to the map, you could create a GraphicsLayer and add the graphics to it, so you will able to clear only the graphics layer instead of all graphics on the map.
0 Kudos
vinayb
by
New Contributor III
Thanks a lot.

  Please let me know if my understanding of ArcGis is right.

   ArcGis exposes some restfull services which we can consume and apply our logic based on
  dojo or rest , where we can apply our logic.

  Below are few of my question

  1)DO i have to choose only from existing rest service from arcgis , cant i create myself services.
  2) I need a world map where i can identify each country by an two letter word id , so that if i want to highlight us , then i can something like dojo.byId('us") and apply some graphic code to highlight it.
0 Kudos
JakubMalec
New Contributor III
1)DO i have to choose only from existing rest service from arcgis , cant i create myself services.

You can create your maps in ESRI ArcMap and publish them on ESRI ArcGis Server but you need a licence to use these products and it's not cheap ;]. The alternative is using free tools such as QGIS and Geoserver - create maps with QGIS (or find some shapefiles in the Internet) and publish them as WMS services with Geoserver.

2) I need a world map where i can identify each country by an two letter word id , so that if i want to highlight us , then i can something like dojo.byId('us") and apply some graphic code to highlight it.

I don't know any public service that contains countries, but i haven't been looking :P. Creating the functionality that you mention is easy, but without the service you won't do anything.
0 Kudos
vinayb
by
New Contributor III
I have licence .My company has brought it .

Now i need a world map with only country code , can you please help me with this.
0 Kudos
JakubMalec
New Contributor III
I've found some World boundary shapefile ( http://geocommons.com/overlays/33578 ), but I won't help you with publishing it on the ArcGIS Server since I've never done it.
0 Kudos