ArcGIS javascript API learning 4

Source: Internet
Author: User

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. addonloadTo 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.