Quantcast
Channel: maps for developers - Medium
Viewing all 2294 articles
Browse latest View live

Bengaluru office opening party February 26!

$
0
0

We’ve been heads down over the past months setting up shop in the tech capital of India. Our preparation work is entering the home stretch now with moving into our new office space and a kick off sprint for the team, all focused on improving OpenStreetMap data. Join us for our mapping workshop on Saturday February 28 and open our new digs with us on February 26th with a party. Were starting at 6PM, drop in — we’re looking forward!

Mapbox office opening party
Thursday February 26th 2015 Starting at 6PM
Mapbox Office
No 221, 13th Cross Road, 2nd Main
Indiranagar, 560038
No RSVP needed


Mapping turn restrictions and speed limits with Mapillary

$
0
0

Mapillary coverage is growing fast and the collected imagery is great for mapping turn restrictions and speed limits in OpenStreetMap. Here’s how

The Mapillary team is moving fast, the recently added street sign detection feature is highly useful. Here’s my wishlist for an even smoother workflow

  • Better mapillary support in JOSM
  • Fine tuning of the blurring algorithm to not exclude street signs like here
  • Larger mapillary image in iD
  • A link from an image on Mapillary.com to OpenStreetMap.org that opens iD with the right image present

I spent some time working with Mapillary. I chose three routes from a variety and looked through them. In contrast to the panoramas, such as Google and Yandex (Yandex has given the permission to the usage photos from their panoramas in OSM), Mapillary has several limitations. The imagery of Mapillary is basically not panorama, because images are taken in the one direction. We should be very careful to identify all the necessary details (there are also pictures out of focus).

out of focus

I tried to answer to some questions and I can say next:

Can we use Mapillary for mapping turn restrictions?

Yes, we can use Mapillary for this purpose in combination with satellite images. Since Mapillary shots are not always taken in the right place and it is just addition to satellite images. I tried to add to the OSM rules of turn lane restrictions at intersections. There are two schemes for this in OSM (scheme 1, scheme 2). I used scheme 2 as it has a convenient plug-in in JOSM.

It is necessary to determine which scheme is preferable.

Can we use Mapillary for mapping max speed?

Yes, speed limit signs can be discerned on images, but it would be nice to know the local traffic features or rules.max speed

How is the editing workflow with OpenStreetMap, what could be better?

I’ve worked with Mapillary and JOSM since JOSM is more familiar for me. I know that Mapillary layer is present in the iD, but the picture, that is displayed in the iD, is too small to see the details. I was moving between Mapillary shots on the website and, if necessary, using the control elements on the site to enlarge the picture to see the details. In the case of finding objects that can be added to the OSM, I used the link under the image for editing in JOSM. For more accurate orientation I used Mapbox satellite images as a background on the Mapillary site and JOSM. Sometimes I had to spend a lot of time in order to establish the position of objects on images. It would be easier if the pictures could be enlarged in iD. It would be great if the same place from Mapillary could be opened in ID with the same photo in the preview.

But back to Mapillary.

  • One inconvenient thing is that if you change the zoom of the captured image the control of navigation between images disappears.
  • In the case of car going at high speed, many shots are out of focus and there can be seen only general details on them.
  • The algorithm of blurring signs and people faces in Mapillary should be reviewed, so that the inscription on road signs were not processed.

    blur of sign

  • And one more wish to Mapillary users is to install the camera at the angle to the direction of motion, rather than the direction of travel. Thus, we could descry more details which are on the side of the road.

What other information could we gain from Mapillary?

Except of turn restrictions and speed limitations we can add information about all objects which we can discern in the picture and which we are interested in. Among them: the number of lanes on the road, allowed turns from a given (turn) lane, the presence of cycling lanes, sidewalks, crosswalks, traffic lights, possible type of road surface; as well all kinds of POI, banks, shops, fire hydrants, petrol stations, cafes, and information contained on road signs.

P.S. After this article was prepared, Mapillary has introduced a new feature of Traffic Sign Recognition on images.

All images by Mapillary / CC BY-SA 4.0

Customization and support for arbitrary feature types in iD

$
0
0

The OpenStreetMap iD editor provides powerful map editing in the browser with an emphasis on great user experience. It’s a great tool in its own right, so the Moabi initiative decided to use it. Moabi is a collaborative map of environmental data built on OpenStreetMap software (that’s right, not the data).

To use iD on other data than OpenStreetMap, you’ll be looking for two main customization aspects: presets and imagery. Presets capture map features - in OpenStreetMap that would be streets, parks, buildings - in the case of Moabi these could be mining or logging concessions. In terms of imagery, OpenStreetMap uses Bing, Mapbox Satellite and a variety of other providers where Moabi uses a combination of sources like the University of Maryland forest cover.

To make iD easier to customize I spent two weeks working closely with Aaron Lidman and John Firebaugh with the support from the Moabi initiative. We implemented simple preset and imagery customization and as Moabi frequently deals with very large features, we’ve made it easier to edit them.

Custom presets

iD now makes it really easy to load custom presets. You simply load presets together with the editor:

variD=iD().presets(customPresets);

The format for presets is defined in the iD documentation. An example declaration for custom presets would look like this:

{mining:{"name":"Mining Concession","geometry":["point","line","area"],"tags":{"concession":"mining"},}}

To supply inline help and autocomplete functionality for presets you can also specify your own tag info service like OpenStreetMap TagInfo like:

variD=iD().presets(customPresets).taginfo(iD.taginfo());

Custom imagery

Just like custom presets, to overwrite the default imagery selection in iD with your own, use the .imagery() accessor like here:

variD=iD().imagery(customImagery);

The expected format for imagery options is specified in the editor-imagery index documentation. An example would look like this:

{"name":"Bing aerial imagery","type":"bing","description":"Satellite and aerial imagery.","template":"http://www.bing.com/maps/","scaleExtent":[0,22],"id":"Bing","default":true}

Editing large features

Editing data that contains very large and very small features in the same areas is challenging. To address this issue we have enabled a locking mechanism that limits access to very large features at high zoom levels.

For optimum performance, the minimum zoom level for editing is set at 16 by default. Depending on your data and use case, the minimum editable zoom level can now be configured like:

variD=iD()..minEditableZoom(12);

The Moabi initiative is using these features today. If this type of work is exciting for you - Moabi is hiring.

Rethinking data + design

$
0
0

Connecting custom data to design has always been a confusing and difficult part of making maps. You need to grapple with file formats, projections, weak metadata, and multiple applications just to put data on a map.

We’re reimagining this from the perspective of Mapbox GL and our platform of APIs: what if visualizing custom data was a seamless experience, and a gateway into managing geospatial data in the cloud, organized and scaled effortlessly?

Downloading shapefiles from Amsterdam's open data website

Making a map with Amsterdam’s UNESCO Shapefile. The file is in a local projection, EPSG:28992, but Mapbox’s API autodetects this, reprojects, and produces efficient vector tiles.

adding the shapefile to Mapbox via the upload UI

The Shapefile is processed within a minute and accessible through the same interface: adding it to the map immediately shows the desired area.

Adding a layer to the mapj

Because the entire map is styled on the fly with Mapbox GL, the age-old problem of placing the visualization at the right place in the stack is thoroughly solved: by dragging the layer through the list of layers, the world heritage layer can appear above or below roads, buildings, water, or any other feature type.

Styling the layer

Startups support net neutrality

$
0
0

We strongly support the framework on net neutrality rules currently before the Federal Communications Commission, including the use of Title II to put the new rules on solid legal footing.

We’re built on open source software, open data, and open standards, but all this work depends on an open Internet. We’ve built global infrastructure to serve beautiful maps insanely fast, but it only works if Internet users everywhere can reliably get to our servers.

Like most startups, we have some big competitors. If cable companies and telcos are allowed to become gatekeepers online, the big established players will win and disruptive challengers like us will lose, every time. This clarification is important; recently one of the FCC Commissioners seriously confused this issue:

Fourth, President Obama’s plan to regulate the Internet will hurt competition and innovation and move us toward a broadband monopoly. The plan saddles small, independent businesses and entrepreneurs with heavy-handed regulations that will push them out of the market.
February 6, 2015 STATEMENT OF FCC COMMISSIONER AJIT PAI ON PRESIDENT OBAMA’S PLAN TO REGULATE THE INTERNET

This is simply not true. Please tweet about how startups support real Net Neutrality and sign the petition: “Yes, my startup supports net neutrality!”.

This isn’t just a Silicon Valley issue, or a Washington, DC issue - this is about the strength of our core economy and true freedom of information, and next week’s vote is vital to every startup.

Streamlining map feedback

$
0
0

On every Mapbox map you will see an “Improve this map” link, letting anyone quickly share feedback and make the map better. We’ve now made it even simpler to submit feedback — reducing the number of clicks needed to let us know what’s wrong from four to two. All submissions help improve underlying OpenStreetMap data. Based on popular request, we’ve also moved a direct edit button back to the first screen for fast click-through directly to OpenStreetMap.

Map feedback interface 2.0

The simplifications are all designed to gather as much feedback as possible. Submissions range from issues related to technical errors to general mapping tasks. Here are a couple examples:

There are a bunch of streets that run north-south missing between Holly St.and Monaco St. There’s also another cross street between 6th and 8th - it’s Severn St. and it runs east-west from Dahlia St. to Monaco Pkwy.

Spelling feedback is quite common:

This is misspelled. It should be Seneca, like the golf course below it.

We’re using Zapier to turn submissions into tickets on a Github issue queue that our data team is subscribed to.

If feedback is map related, we address it immediately by editing map data directly on OpenStreetMap.org. If local knowledge is required, we post a note on OpenStreetMap instead to solicit help from the greater community.

Edit flow

Mapping turn restrictions and speed limits with Mapillary

$
0
0

Mapillary coverage is growing fast and their team is adding exciting new features like traffic sign recognition by the week. The ability to use Mapillary imagery for OpenStreetMap is particularly exciting, so I’ve set out to take a look at mapping two of the most important features for navigation — turn restrictions and speed limits— with Mapillary’s help. Here is how to map these features with the two most popular editors in OpenStreetMap.

max speed

Spotting a speed limit on Mapillary.

Mapping with iD

To work with Mapillary on OpenStreetMap’s web based iD editor, just enable the Mapillary layer like so:

show how to enable Mapillary layer

You can then easily follow down roads to look for speed limits or turn restrictions like seen in the animate gifs below.

iD turn restriction dialog

Mapping a turn restriction in iD.

iD speed limit setting

Mapping a speed limit in iD.

Mapping with JOSM

OpenStreetMap’s desktop editor JOSM does not offer direct Mapillary integration, but you can use the Mapillary web site to browse images which works well. The web site comes with an edit button that allows you to hop directly into JOSM for editing (the edit button also supports iD for that matter). For mapping turn restrictions, first install the respective plugin in JOSM:

Installing the turn restrictions plugin

You can then explore areas on the Mapillary web site and click “edit” to open JOSM (make sure remote control is enabled):

The following two animated GIFs show how to map a turn restriction and a speed limit in JOSM. JOSM also has a nice plugin for proposed turn lanes if you want to go into details.

map a turn restriction

Mapping a turn restriction in JOSM.

map a speed limit

Mapping a speed limit in JOSM.

More data

Of course there’s more information that can be gleaned from Mapillary than turn restrictions and speed limits. Here are a series of features I’ve found possible to map:

  • number of lanes on a road including turn lanes versus through lanes
  • cycling lanes
  • sidewalks and crosswalks
  • traffic lights
  • road surface
  • all kinds of points of interests like banks, shops, fire hydrants, petrol stations, cafés

A wish list

While using Mapillary with OpenStreetMap, I ran into a few items that would be nice to see streamlined to provide a more frictionless experience:

  • Show traffic signs layer in iD (we’ve heard from Mapillary this is happening)
  • Larger Mapillary image in iD - often the pictures are too small to see details
  • Embedded Mapillary support in JOSM - this would eliminate the need to hop between windows
  • Fine tuning of the blurring algorithm to not exclude street signs like here
  • A link from images on Mapillary.com directly to OpenStreetMap.org that opens iD with the right image present

All images by Mapillary / CC BY-SA 4.0

Atlas Server now available on the AWS Marketplace

$
0
0

Atlas Server is now available in the Amazon Web Services Marketplace, the app store for pre-configured EC2 instances. It takes one click to spin up Atlas Server via the AWS Marketplace. From there you have access to your own private map server with worldwide streets and terrain maps as well as our Cloudless Atlas satellite imagery. Atlas includes self-contained versions of Mapbox.js and Turf so you can build interactivity, add data feeds, and run GIS operations inside your mapping applications.

Email us at enterprise@mapbox.com if you have questions about Atlas or check out the AWS Marketplace listing.


Maptime in Oklahoma City on Monday

$
0
0

On Monday at noon I’m hosting the first ever Maptime in Oklahoma City. With Maptime in OKC, we’re following the Maptime tradition of creating a shared space for mappers of all skill levels to learn from each other and talk about their projects. On Monday we’ll be introducing folks to OpenStreetMap and jumping right into the basics of using OpenStreetMap to map and build mapping applications.

A big thank you to Oseberg.io for hosting the event. Come check us out on Monday – you can still RSVP and we have more information about Maptime OKC on our site and on Twitter!

Upload twice as much imagery with BigTIFF

$
0
0

In January we increased the file upload limit for imagery from 260 MB to 4 GB. Now, we're increasing the limit on TIFF files again, to 10 GB. This allows you to upload even more detailed satellite and drone imagery to your Mapbox account making it easier to publish imagery from government sources, commerical imagery providers, and drone flights.

We increased this limit by adding support for BigTIFFs, a special flavor of the TIFF format that uses 64-bit offsets to far exceed the 4 GB file size limit that normal TIFFs have.

Spanning over 20 square miles, this image shows the mediterranean city of Montpellier, France at 16 cm resolution. This set of open data, captured just last year, is provided by the City of Montpellier. View full screen map.

Here are a few examples of what you can upload with the new 10 GB limit:

  • All of Paris, France at 60 cm resolution from Digital Globe
  • A 50,000 acre farm at 5 meter resolution from RapidEye
  • Drone footage of Machu Picchu at 10 cm resolution
  • Beautiful imagery of Zhangjiajie National Forest Park at 1 meter resolution
  • 10,000,000 olympic sized trampolines imaged at a 20 cm resolution

You can create a BigTIFF using the command line raster utility, `gdal_translate` (using GDAL version >= 1.5.0).

      gdal_translate -of GTiff -co BIGTIFF=YES -co TILED=YES -co COMPRESS=LZW original.jp2 bigtiff.tif
  • The `-of` flag stands for "output format". The above command is setting the output to GeoTIFF.
  • The `-co` flag stands for "creation option". The above command is passing the BIGTIFF option to the output format driver to create a BigTIFF. The TILED command breaks the image up into square tiles. Pre-cutting high-res imagery into tiles can make accessing and processing that image more efficient. Also, the COMPRESS command helps decrease the overall filesize.

Questions? You can contact me on Twitter @carolbirgitta or email help@mapbox.com.

Welcome Vanessa!

$
0
0

A big welcome to Vanessa, who has joined the Mapbox team! She’ll be on operations, supporting our growing team across four offices and five time zones - making sure we nail the logistics across them all. Vanessa will be based out of our San Francisco office, and the one behind making sure our space is amazing.

Vanessa just finished her Masters degree in epidemiology at George Washington University where she also worked at the startup incubator 1776, supporting hundreds of startups in their early days and running the logistics and programming for their training events.

Welcome Vanessa!

Animated heatmaps and grids with Turf

$
0
0

The latest release of Turf includes powerful new functions to aggregate dense point data into grids & heatmaps. In this example, I aggregated and classified hail data for 1955 to 2013 and created an animated map usingMapbox.js.

Try selecting the various visualizations using the buttons across the top.Hexagonal bins in particular are of interest because they often avoid false pattern recognition associated with square bins. In the same article, Johnson also succinctly describes the benefit of binning:

For the user, showing every single point can lead to cognitive overload, and may even be inaccurate, as overlapping points lead to a misreading of density.

The analysis code is open source on GitHub and this data is free from NOAA.

Used properly, heatmaps and grids provide a simple way to visualize massive point datasets so they are easier to grasp. Turf enables apps like this with nothing more than an interesting dataset and a few lines of code.

Want to learn more? Check out our new introduction to Turf and start building your own interactive GIS analysis apps. Have a question not answered by the guides? Let me know at @morganherlocker.

The first ten years of OpenStreetMap

$
0
0

In the first 10 years of OpenStreetMap, hundreds of thousands of people have mapped 25 million miles of roads in every country in the world. Here is a look back at how the most detailed map of the world started.

This area near Koblenz, Germany exemplifies the process. In a way analogous to how cities themselves grow, volunteer mappers began with a bare framework of major roads and then worked outward to fill in adjacent areas with ever-increasing detail.

Looking closer at cities highlights that even once the map is “complete,” it is never really done. This view of Manila shows that the streets of the city were nearly all mapped in the first few years, but refinement of detail has never ceased.

Many US cities cut short the early stages of the process by importing street data from the Census Bureau’s TIGER maps. This view of eastern Los Angeles shows the rapid import after an initial period of purely community mapping, followed by ongoing extensive community work to clean up the imported data.

Finally, an overview of Japan shows how an entire country comes to be mapped. Tokyo fills in first, followed by other major cities and the roads connecting them, and then a series of waves of activity adding more rural areas and further enhancing the urban detail.

We made an animated map so you can see how everywhere else in the world also came to be mapped in OpenStreetMap. Use the Jump button to see other highlights, or pan and zoom to your own neighborhood.

Minh Nguyễn joins Mapbox

$
0
0

Minh Nguyễn just joined the Mapbox team, bringing years of experience in open data communities and software engineering. He’s hacking on Mapbox GL and our iOS tools and will be reaching into many corners of our stack in the future.

Minh cofounded the Vietnamese Wikipedia and is a longtime editor there. He’s also a prolific contributor to OpenStreetMap, holding “Crazy Mapper” status and helping to translate the iD editor into Vietnamese. Previously, he worked on developer tools at Apple and on presentation software at Microsoft. He holds a bachelor’s degree in Computer Science from Stanford University.

Welcome Minh!

BlackBridge country mosaics on Atlas Server

$
0
0

All full-country imagery mosaics from BlackBridge can now plug into Atlas Server. You can be serving your BlackBridge imagery of an entire country from your private cloud or on-premise in a matter of minutes. The imagery from BlackBridge is gorgeous: five meter resolution, seamless, cloudless, ready off-the-shelf for 20+ countries.

Here are some shots of BlackBridge’s 924,000 square kilometer Nigeria mosaic served from Atlas Server running on my Macbook:

The Gurara Dam project in central Nigeria generates 30 megawatts of electricity and pipes 13 cubic meters per second of fresh water through a 75 kilometer pipeline to Abuja.

In addition to serving imagery, Atlas Server comes loaded with worldwide street and terrain maps. Combine them to overlay place names and the world’s road network on top of your imagery.

Downtown Abuja, with a view of the National Assembly, National Stadium, and Aso Rock.

Beyond base maps, Atlas Server is a platform that enables business to integrate their data into custom maps and applications. Atlas Server ships with a self-contained version of Mapbox.js, the same API that powers Mapbox.com, and Turf, the future of GIS. You and your users can use dozens of plugins to make heat maps, cluster dense data, swipe between before/after imagery, and annotate your imagery. The API also plugs into our open source iOS and Android SDKs so that you can power private mobile apps with your imagery.

The Niger River Delta, where 31 cubic kilometers of the Niger River’s flow are lost annually to seepage and evaporation before before the river drains into the Gulf of Guinea.

Want to bring Atlas Server and BlackBridge imagery to your your cloud or local network? Hit me up on Twitter @mtirwin or email enterprise@mapbox.com.


Talking time travel at GeoDC

$
0
0

Tonight I’ll be at the March GeoDC meetup to talk about temporal map analysis and map hacking in the 4th dimension. I’ll show some examples of stories you can tell by combining time and other data and share some strategies for how you can make your own time maps on the web.

Jon Bowen will also be there showing off story maps, and Nate Smith from Development Seed will talk about how they’re using open data to give more context to current events.

Tonight’s meetup is at 7:00 pm at Stetsons. GeoDC is a monthly gathering of cartography and GIS folks from various fields who get together to talk maps. For updates, follow @geo_dc on Twitter and join the meetup group.

Chicago crime data with Turf

$
0
0

Turf can be used on massive datasets using Node.js streams. I was able to process three gigabytes of Chicago crime data from their Socrata portal - all crimes from 2001 to today - for this time-series visualization with just a bit of code.

Drag a horizontal section of the timeline below the map to loop over that period. Note the gradual decline of crime over the decade, as well as the seasonal ebbs and flows. Compelling interfaces like this can be built by combining Turf with Mapbox.js and D3.

In this example, Turf is used for preprocessing and compressing the raw data and for visualizing the crime trends on the fly. Because Turf is a JavaScript library, the same geo processing engine can be used everywhere, so you don’t need to worry about learning multiple APIs for different contexts. Crunch huge datasets on the server and visualize smaller ones in the browser blazing fast.

Interested in learning more? Let us know at @mapbox and read our introductory guide to Turf.

Inauguramos Mapbox Perú el 17 de Marzo

$
0
0

Les invitamos a la fiesta de inauguración oficial de Mapbox Perú. Tenemos muchos años de estar presente en el Perú — desde que se fundó la empresa antecesora de Mapbox aquí en Ayacucho en 2003. Este año es el momento de consolidar nuestra presencia con una oficina oficial en el distrito de Jesús Nazareno - Ayacucho. Celebramos en esta ocasión con una fiesta el día Martes, 17 de Marzo. Contaremos con el alcalde Dr. Hugo Aedo Mendoza y también Eric y Alex van a llegar desde San Francisco a participar.

Fiesta de inauguración de Mapbox Perú

Martes 17 de Marzo de 2015
A partir de 18:30
Jirón José Santos Chocano N°416, Jesús Nazareno

Add a third dimension to Mapbox.js with CSS

$
0
0

Our recent Capital Bikeshare post received a lot of Twitter love, particularly for the 3D view of elevation profile. Several people even asked how it was done, so I’ve put together a little guide to making your own.

Since Mapbox.js was not built with 3D in mind, we’ll hack some of the existing map elements with CSS and JavaScript to bring 3D to Mapbox.js. Onward!

What we’ll cover

Draw a flat map

We’ll start in two dimensions. First, initiate a Mapbox.js map in the usual fashion (I will add it to a div with id="map", but you can use whatever).

varmap=L.mapbox.map('map','peterqliu.9d05be4d',{zoomControl:false}).setView([48.8572046,2.348],14);

Next, add markers with L.divIcon, wrapping your custom HTML in a div classed marker. We’ll eventually stand these upright in 3D space, but for now, design them as if they were lying flat on the map. To illustrate, here I’ve defined my custom markers as a linked PNG, and added them to the map:

varmyIcon=L.divIcon({className:'',html:'<div class="marker"><img src="marker.png"/></div>',iconSize:[35,46]});L.marker(<latlng>,{icon:myIcon}).addTo(map);

Next, in our CSS we’ll add some styling to set up our 3D space:

/*makeverticalobjectsvisible*/#map{overflow:visible;}/* removes a flickering background color */.leaflet-container{background:none;}/* set up our 3D space */#map,#map*{-webkit-transform-style:preserve-3d;transform-style:preserve-3d;}/* Optional: this will help you see what's going on as we build the tilted view, but can be removed */.marker{-webkit-transform:translateZ(1px);transform:translateZ(1px);}

Say Hello to CSS Transformations

3D might sound like something that involves hardcore number-crunching and SOHCAHTOA in code. But thanks to a rule called transform (with its vendor prefixes), modern browsers can perform basic operations right in CSS. It also happens to be fast for 2 reasons:

1) Layout isolation: Transforms change the visual appearance of an element, but not the space it occupies on the page. This means the browser can focus on moving, turning, stretching, and skewing an element, without worrying about whether it pushes down the other content on the page.

2) Hardware acceleration: all the above calculations are offloaded to your computer’s GPU, freeing up your main thread to do other number-crunching.

You can read more about the performance perks of transformhere.

Rotation, made simple

There are four CSS transform properties: translate, scale, rotate, and skew. As it turns out, Mapbox.js already uses translate to move markers as you zoom and pan around the map.

But we’ll focus on rotation here. If we look at an image head-on, there are three axes around which it can turn: a horizontal X-axis so that it spins like an awning window, a vertical Y-axis so that it spins like a revolving door, and a Z-axis pointing straight at you, so that it spins like a windmill. By default, the center of the image is also the center of rotation.

Let’s turn some things!

Play around with the demo at the top of this page. Feel free to tick and untick the boxes in any sequence, to get a sense for what each transformation does.

1) Tilt the map back

Our first step is to tilt the entire map object, to get that oblique view: we’ll want to tip it backward, along the X axis:

#map{transform:rotateX(-60deg);}/* Pick a number between 0 and -90.*/

For this and all subsequent CSS rules, remember to add -webkit- and other applicable vendor prefixes to render correctly on all browsers.

2) Add some perspective

That’s a start, but our map looks awfully squished– in real-life objects, objects nearby are large, and shrink from view as they approach the vanishing point. Fortunately, we can do precisely this by applying a perspective rule to the parent element of our transformed object (in my case, that’s the <body> tag):

body{perspective:1200;}

This defines how far we are from the transformed object: smaller values make objects appear closer, by producing more extreme foreshortening. I’ve found that values between 1000-1800 work best, but season to your taste.

3) Flip the markers up

Now we can stand our markers up on the map. First, let’s find them in the DOM:

<divclass="leaflet-marker-pane"> // map markers go in here<divclass="leaflet-marker-icon"><divclass='marker'>
      // Your custom HTML here //</div></div><divclass="leaflet-marker-icon">...</div><divclass="leaflet-marker-icon">...</div></div>

Tucked inside each .leaflet-marker-icon is the custom marker HTML we wrote earlier, wrapped in a div that we classed as .marker. Let’s apply the rotation here– tilted like the map, but forward and a full 90 degrees:

.marker{transform:rotateX(90deg);}

4) Set the origin of rotation

So far, so good. But before we move on, let’s make sure we applied our rotation correctly.

Earlier, we learned that by default, all rotations are applied at the center of each element. This worked well for tilting our map back, but check out what happened when rotating our markers around their respective centers (Fig 2-1):

The marker is only half above the map surface, poking out like a shark fin. Instead of rotating the marker around its center, we need to put the pivot point at its bottom tip (Fig 2-2), so that the entire marker stands above the map.

We can also do this in CSS, via transform-origin. The rule takes vertical and horizontal positioning as its two parameters:

.marker{transform-origin:bottomcenter;}

Now our markers are fully above the map.

4) Rotate the map

A challenge with 3D spaces is obstruction: dense groups of tall markers can often block each other, and it becomes useful to pivot the entire map around to see what’s behind. There are a number of affordances you can build to accomplish this: explicit left/right buttons to rotate in each direction, or a mouse dragging event like the one I made for the Capital Bikeshare demo.

Regardless of your input UI, you’ll want to translate that user action to an angle measure that turns the map around. On top of the rotateX we applied in step #1 to tilt the map, we’ll add a rotateZ to spin it around like a lazy susan:

// after rotation is triggereddocument.getElementsByClassName('marker').setAttribute("style","transform:rotateX(-60deg) rotateZ( // PIVOT ANGLE HERE (positive is clockwise) // )");

(Earlier rotations like tilting the map and propping up markers have been static transformations that we applied declaratively with CSS. However, this one will change with user interaction, which means we’ll have to do it in JavaScript).

5) Pivot markers to face the user

We’re almost done! You might have noticed that though we’ve rotated our markers in 3D space, they don’t become 3D objects. This flatness becomes really apparent when the map rotates 90 in either direction, as we look on them edgewise and get only slivers of each marker. How do we solve this?

Here’s a thought experiment: turn your head left and right, while keeping your eyes on this sentence. What keeps your gaze from sliding off the screen as your head turns away?

Your eyeballs do a compensatory rotation (rotateY, in fact) to negate your head turning. That’s exactly what we’ll do for our markers, to keep them pointing toward us:

// after map rotation is triggereddocument.getElementsByClassName('marker').setAttribute("style","transform:rotateX(-90deg) rotateY( // PIVOT ANGLE HERE // )");

And that’s it! You have the basics for a three-dimensional map with Mapbox.js

The Extra Mile

If you really want to spruce up your map and refine some nitpicky details, here are some further considerations:

Reduce the horizon: Leaflet (upon which Mapbox.js is built) smartly loads only tiles currently visible in the frame. But tipping the map backwards exposes the edge of this frame, which you might not want. To force-load tiles outside the frame, try:

vargetPxBounds=map.getPixelBounds;map.getPixelBounds=function(){varbounds=getPxBounds.call(this);// ... extend the boundsbounds.min.x=bounds.min.x-1000;bounds.min.y=bounds.min.y-1000;bounds.max.x=bounds.max.x+1000;bounds.max.y=bounds.max.y+1000;returnbounds;};

Disable scroll-zooming: Zooming still works in 3D, but I’ve found that map controls work better than the mousewheel here. If you are using mouse dragging for Z-rotation, I also suggest map.dragging.disable() to avoid inadvertent panning.

Popups: The simplest 3D popup implementation I’ve found involves a hidden <div>, set inside the marker element itself that appears on hover. If you find a way to do this with default Mapbox.js popups, let me know!

Discretion: 3D objects are certainly cooler than flat, but that doesn’t mean it’s the best for every (or even most) use cases– traditional chloropeths and heat maps can often display the same data more simply, and equally capably. Be judicious with the extra dimension, and use only when it truly illuminates.

See you at FOSS4G in San Francisco!

$
0
0
Viewing all 2294 articles
Browse latest View live