Mouse events on maps and graphics(Mouse events on map and graphics, specifically those on map and graphiclayer)
The ArcGIS javascript API map and graphics layer provide a large set of Mouse
Events users can use to interact with these objects(ArcGIS javascript API map and graphiclayer provide a large number of mouse events through which users can interact with these objects). To register to listen to
Map's onclick event:
Function Init () {var map = new ESRI. map (...); dojo. connect (MAP, "onclick", myclickhandler); map. addlayer (...);}
When a user clicks the map, a mouse event is generated and all registered click
Handlers are called. The mouse event is passed as an argument to each handler.
In addition to all properties populated by the browser, A mappoint and
Screenpoint are encoded as properties of the event. The mappoint represents
The coordinates of the click in map coordinates and the screenpoint represents
The coordinates of the click in screen coordinates.
Function myclickhandler (event) {alert ("user clicked at" + event. screenpoint. X + "," + event. screenpoint. Y + "on the screen. the map coordinate at this point is "+ event. mappoint. X + "," + event. mappoint. Y );}
In addition to the mappoint and screenpoint properties, the event returned
Between des a graphic property, which is the ESRI. Graphic
Object that has ed the event. The code below shows how you cocould handle
Map's onclick event to report which graphic the user clicked. notice that
Listener for The onclick event will only be in effect after the map's onload
Event has fired. In this situation, a listener is dependent on another
Listener.
Function Init () {var map = new ESRI. map (...); dojo. connect (MAP, "onLoad", function () {dojo. connect (map. graphics, "onclick", mygraphicsclickhandler) ;});} function mygraphicsclickhandler (EVT) {alert ("user clicked on" + EVT. graphic );}
Since the map. graphics object is only
Available to use after the map. onload event
Is fired, you shoshould wait to register Event Listeners until the map. onload
Event is fired.
(Because the map. graphics object is only available after the map. onload event is triggered, you should wait for the event to be registered until the map. onload event is triggered. // added by zhangjun at worth noting)
___________________________________________________________________________________________
Next, useDojo. addonload
To specify an initialization function that will execute once the HTML is loaded(Next, use dojo. addonload to specify an initialization function, which will be executed after HTML loading). In the initialization function, namedInit
, The map is created and a new basemap layer is added to the map. The basemap layer is a service fromArcgis.com.