Menu Sidebar
Menu

Custom Basemap Toggle with ArcGIS JavaScript API 4 View Models

switcherI’m super excited about the ArcGIS API for JavaScript 4.0 beta. One of the exciting things is developer friendly widgets which allows us to write our own presentation layer, and still use the logic of the core widget (the “View Model”). For example, the View Model for the Basemap Toggle Widget allows you to call toggle() and get the current/secondary basemaps, all from your own module that implements the view.

After reading through Odoenet’s great post on this subject, I thought I’d take his React example and throw together an equivalent view in Dojo.

In the postCreate function we’re setting up a watch (using dojo/stateful) and updating our thumbnails when we see the “secondaryBasemap” property change. The event for when the user clicks the thumbnail is using dijit/_TemplatedMixin to setup that event to call the toggle function when it is clicked. In our toggle function we’re just calling the View Model’s toggle function.

var BToggle = declare([_WidgetBase, _TemplatedMixin, Stateful], {
  
  	// https://github.com/odoe/esrijs4-vm-react/blob/master/src/components/basemaptoggle.jsx#L75-L78
  	templateString: '<div><div class="basemap-item basemap-item-secondary" data-dojo-attach-event="click:toggle" data-dojo-attach-point="secondaryBasemapItem"></div><div class="basemap-item basemap-item-current" data-dojo-attach-point="currentBasemapItem"></div></div>',
    
    // https://github.com/odoe/esrijs4-vm-react/blob/master/src/components/basemaptoggle.jsx#L5-L9
    bgImage: function(target, url) {
    	domStyle.set(target, 'background-image', 'url(' + url + ')');
    },
    
    // https://github.com/odoe/esrijs4-vm-react/blob/master/src/components/basemaptoggle.jsx#L13-L18
    constructor: function() {
      this.inherited(arguments);
      this.vm = new BasemapToggleVM();
      this.secondaryThumbnailUrl = '';
    },
    
    // https://github.com/odoe/esrijs4-vm-react/blob/master/src/components/basemaptoggle.jsx#L29-L50
    postCreate: function() {
    	this.inherited(arguments);
      this.vm.view = this.view;
      this.vm.secondaryBasemap = this.secondaryBasemap;
 
      var info = this.vm.getBasemapInfo(this.secondaryBasemap || 'topo');
      this.updateThumbnails(info, this.vm.currentBasemap);
      this.vm.watch('secondaryBasemap', lang.hitch(this, 'updateThumbnails'));
    },
    
    // https://github.com/odoe/esrijs4-vm-react/blob/master/src/components/basemaptoggle.jsx#L52-L59
    updateThumbnails: function(secondary, current) {
      var secInfo = this.vm.getBasemapInfo(secondary);
      var curInfo = this.vm.getBasemapInfo(current);
    	this.bgImage(this.secondaryBasemapItem, secInfo.thumbnailUrl);
      this.bgImage(this.currentBasemapItem, curInfo.thumbnailUrl);
    },
    
    // https://github.com/odoe/esrijs4-vm-react/blob/master/src/components/basemaptoggle.jsx#L61-L63
    toggle: function(evt) {
    	this.vm.toggle();
    }
  });

The code is annotated with links back to the equivalent line numbers in Rene’s example. This was a great learning experience for learning the View Models concept in the JS API – I’d encourage you to write your own!

Raspberry Pi Kitchen Dashboard

2One of my goals for 2015 was to build and assemble a Raspberry Pi based Kitchen Dashboard. The original idea was to use Dashing.io via this tutorial, but the Ruby requirement of Dashing.io made developing custom widgets tougher for me on Windows, so I ended up switching to Atlasboard.

Challenges

There were many reasons why this project had core problems with the idea. Some of those included:

  • Useful Data – other than calendar and weather, what actual useful information do you need on this type of board (And don’t tell me quote of the day!)
  • Internet access – your dashboard computer is going to need internet. That means either a wired connection or wifi. Once you’ve seeded this fact, why even run the dashboard software on the Raspberry Pi? Just have it hit a URL on a different, more high powered server.
  • Form Factor – The current setup has way too many cords and cables, and (continuing from the previous point) if you’re just hitting a webpage on a server on the internet, really you’re just building a screen display unit, which can be done sleeker, smaller, and better by manufacturers who do this for a job – like an iPad or other Android tablet. Plus going tablet allows you to use touch which makes interacting with the device easier.

1

Too much cruft!

Software

687474703a2f2f692e696d6775722e636f6d2f31724a754642712e6a7067Setting up the actual software that runs the dashboard was pretty fun – probably the best part of the project for me. I enjoyed configuring the Atlasboard widgets to my liking. I had to edit the Calendar app to work like I wanted it to with our meal planning web service. I also wanted a better weather widget, which I wrote and released on GitHub.

After using it for awhile, I actually took this down out of our kitchen. The benefits were not worth the costs. I enjoyed the project though – especially being able to release an open source widget for Atlasboard – and will maybe revisit the idea in the future.

Mapping NBA Player Movement in 2D and 3D

Having developed methods to get the NBA player shotchart data and player movement data into ArcGIS, I wanted to explore different ways to visualize the player movement data with webmaps, ArcGIS application templates, and 3D web scenes. I also wanted to look at an entire game and find ways to identify where on the court players spend the most time and what lanes or routes players are more likely to travel across the court. For this post, I’m going to describe some approaches to visualize an entire game of movement data with common GIS techniques and tools and use some really cool GIS visualization techniques to display the data and compare player movement maps.

For this post, I looked at the movement data for the entire game between the Oklahoma City Thunder and Detroit Pistons from November 27, 2015. I aligned the data so that the northern end of the basketball court is the Thunder’s offensive end and the southern end of the court is the Piston’s. I filtered the data to remove duplicate timestamps for each player on the court. This has the effect of filtering out moments where game action is occurring but the clock is not moving (for example, foul shots). This is what I wanted to do because I was interested in where players spend time on the court when the game is in progress.

Read More

Happy New Year 2016

goals-smallI don’t like new year’s resolutions. They are too often forgotten a few weeks down the road. I do, however, like to have short and long-term goals, and the beginning of a new year is a great time to reflect on what has been accomplished, and what to do in 2016.

2015 Completed List:

  1. 12 Gavinr.com blog posts (met goal of 12, with help from guest blogger Greg Brunner)
  2. Read 21 books (met goal of 15)
  3. Volunteered at least 60 hours (goal of 30)
  4. Contributed 2 small patches to Open Source Dojo JavaScript project (goal of 1)
  5. Released four new WordPress Plugins
  6. Gave three conference presentations – two at Esri Dev Summit and one at Esri User Conference
  7. Built and setup a Raspberry Pi kitchen dashboard (blog post coming soon)
  8. Released some open source projects on GitHub: atlasboard-weather, geojson-viewer, and wab-widget-search

Of course there were goals I had that I didn’t reach, including running and blogging.

Goals for 2016:

  1. Read 20 books
  2. Learn VIM – Be using at least 10 unique VIM commands in SublimeText Vintage mode daily
  3. 12 Gavinr.com blog posts
  4. 60 excercise activities (walking, running, or biking)
  5. Contribute to at least 2 open source projects
  6. Release 2 new WordPress Plugins
Older Posts

Gavin Rehkemper

JavaScript, WordPress, and GeoDev