This is a review of RavenBurgerCo, created as a sample app for RavenDB spatial support by Simon Bartlett. This is by no means an unbiased review, if only because I had laughed out load and crazily when I saw the first page:
What is this about?
Raven Burger Co is a chain of fast food restaurants, based in the United Kingdom. Their speciality is burgers made with raven meat. All their restaurants offer eat-in/take-out service, while some offer home delivery, and others offer a drive thru service.
This sample application is their online restaurant locator.
Good things about this project? Here is how you get started:
- Clone this repository
- Open the solution in Visual Studio 2012
- Press F5
And it actually works! It uses embeddable RavenDB to make it super easy and stupid to run it, right out of the box.
We will start this review by looking at the infrastructure for this project, starting, as usual, from Global.asax:
Let us see how RavenDB is setup:
So use embedded RavenDB, and if there isn’t enough data in the db, load the default data set using RavenDB’s new Bulk Insert feature.
Note that we set MvcApplication.DocumentStore property, let us see how this is used.
Simon did a really nice thing here. Note that UseEmbeddedHttpServer is set to true, which means that RavenDB will find an open port and use it, this is then exposed in the UI:
So you can click on the link and land right in the studio for your embedded database, which gives you the ability to view, debug & modify how things are actually going. This is a really nice way to expose it.
Now, let us move to the actual project code itself. Exploring the options in this project, we have map browsing:
And here I have to admit ignorance. I have no idea on how to use maps, so this is quite nice for me, something new to learn. The core of this page is this script:
You can see that loadMarkers method, which is getting called whenever the map is moved, and on startup. This end up calling this method with the boundaries of the visible UI on the server:
Note that in this case, we are doing a search for items inside the rectangle. But the search options are a bit funky. You have to send the data in WKT format. Luckily, Simon already create a better solution (in this case, he is using the long hand method to make sure that we all understand what he is doing). The better method would be to use his Geo library, in which case the code would look like:
So that was the map, now let us look at another example, the Eat In example. In that case, we are looking for restaurants near our location to be figure out where to eat. This looks like this:
Right in the bull’s eye!
Here is the server side code:
And on the client side, we just do the following:
We define several circles of different opacities, and then show up the returned markers.
It is all pretty simple code, but the result it quite stunning. I am getting really excited by this thing. It is simple, beautiful and quite powerful. Wow!
The delivery tab does pretty much the same thing as the eat-in mode, but it does so in a different way. First, you might have noticed the LocationIndex in the previous two examples, this looks like this:
Before we look at this, we need to look at a sample document:
I am note quite sure why we have in LocationIndex both SpatialGenerate() and SpatialGenerate(“location”). I think that this is just a part of the demo. Because the data is the same, and both lines should produce the same results.
However, for deliveries, the situation is quite different. We don’t just deliver to a certain distance, as you can see, we have a polygon that determines where do we actually delivers to. On the map, this looks like this:
The red circle is where I am located, the blue markers are the restaurants that delivers to my location and the blue polygon is the delivery area for the selected burger joint. Let us see how this works, okay? We will start from the index:
So we are indexing just restaurants that have a drive through polygon, and then we query it like this:
This basically says, give me all the Restaurants who delivers to a locations that includes me. And then the rest all happens on the client side.
The final example is the drive thru mode, which looks like this:
Given that I am driving from the green dot to the red dot, what restaurants can I stop at?
Here is the index:
And now the code for this:
We get the driving direction from the map, convert it to a line string, and then just check if our path intersects with the drive thru area for the restaurants.
Pretty cool application, and some really nice UI.
Okay, enough with the accolades, next time, I’ll talk about the things that can be better.