Noah-Sager
Esri Regular Contributor
since ‎07-04-2014
35 Badges Earned
Blogger Commentor
View All Badges Earned
yesterday
1132 Posts created
857 Kudos given
124 Solutions
509 Kudos received
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

My Ideas

(0 Idea Submissions)

Latest Contributions by Noah-Sager

POST
1
9
9532
POST
0
11
9532
POST
3
13
9532
POST
0
0
955
POST
0
0
2584
POST
0
0
3218
POST
0
2
3218
BLOG
Note: Click images to enlarge.

The modular On Style Events (which means something like à la mode in French) are a bit different than Connect Style Events. Why does this matter? Because On Style Events are the recommended way to listen for and handle events with the ArcGIS JavaScript API. See the screenshot below for snippets of event styles.
on-style-event.png

Snippets of Event Styles



Since version 3.5 of the JavaScript API, these event handling functions receive a single event object from which all the event object properties can be accessed. Typically, this object is called event or evt in our samples. Instead of juggling multiple objects like with Connect Style, we can now dig into one object to access the information we need. There are two ways to use the On Style Events - with and without Dojo. The syntax for these event styles can be found in the JavaScript API reference. Let’s look at a couple code snippets to compare On Style Events with and without Dojo:on = with Dojo (on is an alias for the dojo/on module)
on(map, ’zoom-end’, function(evt) {
     console.log(evt.extent.xmin);
     console.log(evt.zoomFactor);
     console.log(evt.anchor.x);
     console.log(evt.level);
});
map.on = without Dojo (map.on means we can do this event ourselves)
map.on(’zoom-end’, function(evt) {
     console.log(evt.extent.xmin);
     console.log(evt.zoomFactor);
     console.log(evt.anchor.x);
     console.log(evt.level);
});

By examining the above code snippets, we can see that the main difference when using On Style Events is in what the event listeners return. We can also see similarities among the new styles of event handlers, but there are important differences worth exploring.

Not bad, right?

For more better understanding, here's a real-world example. You can follow along at home with the JavaScript Events application hosted on jsfiddle.net. Use the following instructions to follow along (I used Google Chrome for this example):

1. Open the application in your browser.

2. Press F12.

3. Navigate to the Console Tab, if not open already.

The following screen displays:
JSFiddle.png

JSFiddle



This application shows the functionality of dynamic layers and our elegant dark gray basemap tiles (you can also try the application live here: JavaScript Events application on GitHub). As you zoom in and out of the map, different layers become visible as indicated in the lower-left information box. There are six event listeners in this application. Let’s go through them one by one and see what they do.1) map.on("load", function()

When the map first loads, it immediately runs the unnamed function. This listener will only be called once while the application is running, and the listener does not take any arguments in the function. The purpose is to define the four other event listeners and to call the updateScale() function. This allows the scale to be defined in the information box without panning or zooming.2) map.on("zoom-end", updateScale)

After zooming in or out of a map, this event listener will call the updateScale() function. This function updates the map scale in the information box and in the Console tab. This listener does not take any arguments in the function, either.

See below for the event handler:
function updateScale() {
     dojo.byId("map-scale").innerHTML = 
       dojo.number.format(parseInt(map.getScale()));
     console.log("Map scale: " 
       + dojo.number.format(parseInt(map.getScale())));
}
3) map.on("pan-end", updateExtent)

When a user pans around the map, this event listener will call the updateExtent() function, which will update the map extent in the Console tab. This listener takes the generic evt argument in the function.Pro tip: There are many other attributes that you can dig out of the evt object. To see what is available, use the following steps (I used Google Chrome for this example):

1. Press F12 to open the developer's tools.

2. Navigate to the Source tab.

3. Find the section of code with this event handler (around line 170).

4. To set a breakpoint, click the line number to the left of the code.

See below for a screenshot of this process.
breakpointed.png

Breakpoint in Sources tab (Google Chrome)



5. Refresh the application, and when the application pauses on the breakpoint, switch to the Console tab and type “evt” into the prompt.

You can now expand the evt object to see what’s there and experiment with how to call it. View the screenshot below to see how the evt appears in the Google Chrome Console tab.
console_evt.png

evt in Console tab with Google Chrome



See below for the event handler:
 function updateExtent(evt) {
     console.log("Map extent");
     console.log(" XMin: " + evt.extent.xmin);
     console.log(" YMin: " + evt.extent.ymin);
     console.log(" XMax: " + evt.extent.xmax);
     console.log(" YMax: " + evt.extent.ymax);
}
4) map.on("zoom-start", updateOldLevel)

When a user zooms in or out of the map, as soon as the zooming action starts, this event listener will call the updateOldLevel() function. This updates the zoom level of the map in the Console tab. Again, the listener takes the generic evt argument in the function.

Please see below for the event handler:
function updateOldLevel(evt) {
     console.log("Map zoom level was: " + evt.level);
}
5) map.on("zoom-end", updateNewLevel)

When a user zooms in or out of the map, as soon as the zooming action stops, this event listener will call the updateNewLevel() function. This updates the zoom level of the map in the Console tab. Notice that it again takes the generic evt argument in the function.

Please see below for the event handler:
function updateNewLevel(evt) {
     console.log("Map zoom level is: " + evt.level);
}
6) usaLayer.on("load", load)

When the application first loads the usaLayer map service, this event listener calls the load() function, which displays the minScale values for each layer in the Console tab. If you open the map service from REST (http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer) and compare the minScale values for each layer, you see that the dynamicLayerInfo class in the code overrides each layer, which is pretty interesting. Notice that it again takes the generic evt argument in the function.

Please see below for the event handler:
function load (evt) {
     console.log("layer 1 minScale: " 
       + evt.layer.dynamicLayerInfos[0].minScale);
     console.log("layer 2 minScale: " 
       + evt.layer.dynamicLayerInfos[1].minScale);
     console.log("layer 3 minScale: " 
       + evt.layer.dynamicLayerInfos[2].minScale);
     console.log("layer 4 minScale: " 
       + evt.layer.dynamicLayerInfos[3].minScale);
}

For most of you, this is a refresher about working with On Style Events and the JavaScript API. But also for most of you, this will be new and exciting information to take your web apps (and salaries) to the next level. Let’s take a minute to review what we learned here. On Style Events have been around for a while and are slightly different than Connect Style, but are just as easy to use. On Style Events are simple and powerful ways of listening and handling many different event patterns. You can dig into all the arguments in the Console tab by setting a breakpoint and calling the argument object "evt".

Please consider reading our Concepts documentation for more information about working with events in the JavaScript API:https://developers.arcgis.com/javascript/jshelp/inside_events.html

Stay tuned until next time, when we discuss how to make your map "pop" with the new dojo.redecorate method. Happy eventing!
Noah S. - SDK Support Analyst -->
0
0
2117
POST
2
1
1040
POST
0
4
2745
POST
1
1
1896
POST
1
0
2745
POST
1
0
2366
BLOG
UC_con_2.jpg

San Diego Convention Center



Let's step back to 2012, when I was a young Student Assistant arriving in San Diego for the first time from graduate school in Chicago. I was one of 60 lucky students from around the world who were selected to attend and work at the conference. The Student Assistants are seen as the next generation of GIS, and Esri empowers them through this conference to connect with their future.

Understandably, this was one of the most amazing experiences of my life. I was overwhelmed by the excitement and knowledge of so many GIS professionals converging in one place. I don’t think my feet touched the ground all week. We were all on the same level, gorging on new technologies, meeting with new people, and buzzing through the exhibit halls and corridors in a constant state of GIS euphoria. Putting faces to names; learning how products worked; seeing what are going to be the next big things in the industry - the smile never left my face.

Fast forward to 2014, where I am a proud Esri employee working in Support Services, and I once again attend the User Conference. This time, I arrive as a staff member working with the Student Assistants. I am so excited for them. I remember what this conference meant to me then, and it still means the same to me now. Even as I write these words, I am glancing at the calendar, marking off the days until next year’s conference.
StudAssistants2014.jpg

2014 Esri Student Assistants



This year’s group of students are as strong and promising as I remember my group being. They are hungry, curious, and (relatively speaking) young. I try to explain how amazing this opportunity is for them at the User Conference, both personally and professionally. Luckily for them, I’m not the only Esri staff member on hand. We have an incredible team that works with the students. Terri B. has been working with the Student Assistants for five years, and has been at Esri for over 20 years. Terri probably knows everyone by name and is liked by every single Esri employee.Pete H. is one of the nicest and most sincere human beings I’ve ever met, not to mention extremely competent. Melissa Q. is new to the team, but threw herself into the mix with the same interest and excitement that I felt two short years ago. Michael J. works on the HR side in recruitment, and is a tireless “miracle worker” who ensures that high-caliber students are brought into our professional family. Matt P. is a fellow Support Analyst and veteran User Conference student leader, whose sharp dress and quick wit are surpassed only by his critical thinking and managerial abilities. And me? I just feel grateful to have the chance to work with these amazing people.
2014-uc-staff2.jpg

2014 Esri UC Student Assistant Staff with Monte



Now back to our regularly scheduled blog post, where people who have never attended the conference have trouble understanding what it feels like to be there. There are three main reasons that the Esri User Conference stands apart from other conferences. The first reason is the location of the conference. San Diego is a beautiful city full of unique attractions, great food, and great weather. In one day you can attend a technical workshop, get your picture taken with Jack Dangermond, grab a coffee, go to the beach, tour an aircraft carrier, grab another coffee on your way to catch a baseball game, and then meet up with your colleagues at one of the many fabulous restaurants and/or bars. And, if you brought your passport, you can even spend an afternoon in Mexico using public transportation.

The second reason, which is even more important than easy-breezy San Diego, is Esri. I wrote a blog post back in the day about what it feels like to work at Esri, and that feeling has remained unchanged after 1.5 years. Forget about the fact that I love GIS, and that Esri is all about GIS. Forget about the fact that I get to live in a mountain community with snow and bears and I can still carpool to work with my wife every day. Forget about the fact that I am constantly challenged with and trained on the latest and greatest technologies - both hardware and software. The truth remains that Esri has attracted and retained some of the most amazing people I have ever had the pleasure of working with in my life. It is these same people that come to the conference. They work, they present, they socialize. They make this conference amazing.
stud_dinner.jpg

Amazing Student Assistants at Dinner



However, better than Esri, cooler than San Diego, and undoubtedly the best part of the conference… is you. The customer, the presenter, the collaborator, the vendor - even the family and friends that come with you and hang out at the pool or Kids Camp during the conference. I met and talked with you in sessions, in line at Starbucks, in the Exhibit Hall, in the elevator, then again at the bars. We sat on the floor at Registration and watched the World Cup together. We held doors open and gave directions to each other. We laughed and ate tasty food together in the Map Gallery. There was so much joy and camaraderie in you all. This is the magic beyond planning and plenaries. This is the feeling that is greater than the sum of every button worn or selfie taken. This is why no one has ever been to a conference like the User Conference.

Now the conference is over. In this rare quiet moment, after I leave San Diego and return to my haven in the mountains, I sit and reflect on what the conference looked like through the eyes of the Student Assistants. To be honest, it’s very much the same as what you and I experienced. It’s like the first years of college or summer camp, when everything is new and possible, and everyone can be your friend. It’s like the best thing ever. I hope to share this experience with you again next year.

Until then, let's get some rest.
fun_students2.jpg

Bannerstands, with the Student Assistants

For more information on the Esri User Conference Student Assistantship Program, see: http://www.esri.com/careers/students/user-conference-student-assistants


Noah S. - SDK Support Analyst -->
2
0
1583
POST
1
1
1790
Activity Feed