SlideShare une entreprise Scribd logo
1  sur  39
When Google Maps
    Gives You Lemons,
     Make Lemonade
            Wm Leler
            Flightstats
  http://www.slideshare.net/
wmleler/opensourcebridge2012
Audience
• This talk is about JavaScript map APIs
• Do you just want to put a simple map on a
  web page or blog post?
 • Use a static image of a map
 • Mapbox Embed (no JavaScript!)
    http://mapbox.com/hosting/embedding/
 • If you need traffic info (or street view, ...)
    you’re likely stuck with Google Maps
    (or MapQuest, Bing, Nokia, etc.)
Google Maps API
• 7 years old, used by 350,000 websites
• Was free until recently
 • Now charging heavy users (price drop!)
 • Google will be adding advertising
• Suppressed development of alternatives
• Google owns you and controls you
 • V2 to V3 API bungle
Problems with
     Google Maps API
• Closed, proprietary system - no source
 • Difficult to fix bugs or add features
 • Clumsy object model
 • Poor separation of maps from API
• Generic, one-size-fits-all
 • Three basemaps: street, satellite, terrain
 • Largely automobile centric
Maps in 3 Movements
 Map           Imagery Geography
          Maps & Info & Routes
 Data


Server     Map Tiles, Geom, etc.


                                   • User controls
 Client
            JavaScript Map API
                                   • Loads Map Tiles
Browser                            • Markers and
                                    annotations
What You Need
1. A JavaScript map API
2. A server to serve map tiles and geometry
  •   your own or other (paid or free)
3. One or more base maps (lots of choices)
  • comes with server, or custom
1. JavaScript Map APIs
• Proprietary:
 • Google Maps API
 • Mapquest, Microsoft Bing, Nokia, ...
• Open:
 • OpenLayers - http://openlayers.org/
 • Leaflet - http://leaflet.cloudmade.com/
 • Modest Maps - http://modestmaps.com/
 • Polymaps - http://polymaps.org/
Google Maps
<html style="height:100%"><head>
<title>Google Maps Example</title>
<script src="http://maps.googleapis.com/maps/api/js?
key=API_KEY&sensor=false"></script>
</head><body style="height:100%;margin:0;padding:0">
  <div id="map" style="width:100%; height:100%"></div>
<script type="text/javascript">
  var pdx = new google.maps.LatLng(45.53, -122.67);
  var map = new google.maps.Map(
    document.getElementById('map'),
    { center: pdx, zoom: 14,
      mapTypeID: google.maps.MapTypeId.ROADMAP) } );
</script>
</body></html>
OpenLayers
<html style="height:100%"><head>
<title>OpenLayers Example</title>
<script src="http://openlayers.org/api/OpenLayers.js">
</script>
</head><body style="height:100%;margin:0;padding:0">
  <div id="map" style="width:100%; height:100%"></div>
<script type="text/javascript">
  var map = new OpenLayers.Map('map');
  var mapnik = new OpenLayers.Layer.OSM();
  map.addLayer(mapnik);
  var pdx = new OpenLayers.LonLat(-122.67, 45.53).
    transform(new OpenLayers.Projection("EPSG:4326"),
    map.getProjectionObject());
  map.setCenter(pdx, 14);
</script>
</body></html>
Leaflet
<html style="height:100%"><head>
  <title>Leaflet Example</title>
  <link rel="stylesheet" href="leaflet.css" />
  <!--[if lte IE 8]><link rel="stylesheet"
href="leaflet.ie.css" /><![endif]-->
  <script type="text/javascript" src="leaflet.js"></script>
</head><body style="height:100%;margin:0;padding:0">
<div id="map" style="height: 100%;width:100%"></div>
<script type="text/javascript">
  var map = new L.Map('map');
  var tiles = new L.TileLayer(
'http://mt{s}.google.com/vt/v=w2.106&x={x}&y={y}&z={z}&s=',
{ subdomains:'0123', attribution:'&copy; Google 2011' });
  var pdx = new L.LatLng(45.58961, -122.592121);
  map.addLayer(tiles).setView(pdx, 14);
</script>
</body></html>
Comparison
• OpenLayers is mature, very powerful,
  somewhat complicated and large
• Leaflet is new but lots of committers,
  excellent object model, easily extensible,
  modern design, good for mobile
• Modest maps is compact, minimal
• Polymaps uses SVG, renders geometry
  directly on client (no tiles)
Map Tiles

• Instead of downloading entire map into
  the browser, slice up into square pieces
• Enables interactivity, smooth scrolling
 • uses AJAX calls to download tiles
 • lowers resource needs for browser and
    server, lowers bandwidth demands
The Tao of Tiles
• Longitude (x) goes
  from -180º to 180º

• Latitude (y) goes from
  85.051º to -85.051º
  (arctan sinh π), not 90º

• Tile is 256 x 256 pixels
• Zoom level 0 has one
  tile for entire world
Zoom level 1 has 4 tiles
                 number of tiles
                           zoom
                   =   4
                       1
                   4 =4
Tile Explosion
• City level (11) = 4,194,304 tiles

• Street level (16) =
  4,294,967,296 tiles


Google maps goes
to level 22 =
> 17 trillion tiles
Subdomains
• Browsers used to be limited to 2 network
  connections per domain. (Recent browsers
  raised limit as high as 6.)
• To get around this limitation, map servers
  generally point multiple (3 or 4) subdomains
  at a single tile server.
  http://mt0.google.com/
  http://mt1.google.com/
  http://mt2.google.com/
  http://mt3.google.com/
Tile Alternatives
                (side note)

• Google’s experimental MapsGL uses
  WebGL to draw streets, buildings, and
  other features directly in a canvas
• Polymaps uses SVG
• GeoJSON draws geography
• Renders in browser instead of using tiles
• Bad for satellite or other imagery
• Doesn’t work on all browsers
2. Map Servers
• Use a free public map server:
  • MapQuest Open (Open Street Map)
• Use someone else’s map server
• Use a commercial map server
  • CloudMade, MapBox
• Your own server
  • or cloud storage
MapQuest Open
• http://developer.mapquest.com/web/
  products/open/map
• OpenStreetMap, aerial, and overlay tiles
• Free!
• Supports high bandwidth on request
• Reliability is not guaranteed
Mapquest Open Tiles
• Leaflet templates (subdomains: 1 2 3 4):
 http://otile{s}.mqcdn.com/tiles/
 1.0.0/osm/{z}/{x}/{y}.jpg

 http://oatile{s}.mqcdn.com/tiles/
 1.0.0/sat/{z}/{x}/{y}.jpg

 http://otile{s}.mqcdn.com/tiles/
 1.0.0/hyb/{z}/{x}/{y}.png
Someone Else’s Server
• Almost all map tile servers are unsecured
• You are identified by the referrer header
• OK for low volume use
• No reliability guarantees
• Just need to determine server URL
 • (except for Microsoft Bing maps)
Map Server URLs
Easy to determine URL using browser debugger

                         Google Maps

                         Safari Browser
                            debugger
Constructing
            Tile URLs
http://mt1.google.com/vt/lyrs=m@174227760&hl=en&

                src=app&x=81&y=183&z=9&s=Ga
  subdomain
                    column      row    zoom
new L.TileLayer(
'http://mt{s}.google.com/vt/lyrs=m@174227760&hl=en&
  src=app&x={x}&y={y}&z={z}&s=Ga',
{ subdomains:'0123', attribution:'&copy; Google' })

• Leaflet plugs in the values for you
Slippy Maps

• “slippy” naming convention for map tiles:
http://otile1.mqcdn.com/tiles/1.0.0/osm/4/63/99.png

http://<sub>.domain.com/.../<zoom>/<x>/<y>.png

• Tiles can be served as normal files
   No need for a special tile server
3. Rendering Map Data
 Map Data: roads, boundaries, names, ...
                                Styles:
                                colors,
  Zoom
                Render          line widths,
  levels
                                fonts,
                  Tile          hill shading,
                                visibility,
                                detail, ...
           Map Tiles to Serve
CloudMade
• Has a large number of maps, or
• Map Studio allows you to create your own
  map styles
• Based on OSM data
• CloudMade will host your map tiles ($)
 • or you can download and host yourself
• CloudMade also created Leaflet API
MapBox
• TileMill allows you to create maps, using
  any data (not just styles)
• Uses Mapnik, Carto, other open tools
• MapBox will host your tiles ($)
 • or you can download and host yourself
• They have created a large number of maps
• Can dynamically modify tiles
Sources of Map Data
• Not free: Navteq, Navinfo, DigitalGlobe,
  SRTM, Planetary Visions, Google
• OpenStreetMap, US Census TIGER
• NASA/JPL, US Dept. of Agriculture
• Natural Earth, CGIAR-CSI
• any geographic source
 • anyone with a GPS unit
Hosting Your Own Tiles

• Can host as files, using Slippy map format
• Or as database, using MBTiles (SQLite)
• Host in cloud
• Or use caching proxy
• Open (CC) maps, or your own maps
http://rtp.trimet.org/
• Multi-modal regional trip planner
 • car, bus, light rail, streetcar, trolley,
   commuter train, aerial tram, bicycle, walk
 • Open data allows customization
• OpenLayers on the browser
• Open Mapquest servers, OpenStreetMap
• Developing their own map
Foursquare
• Leaflet on the browser
• Mapbox servers (paid)
• Mapbox “Streets” map
  (based on OSM data)
Flightstats
• Leaflet
• Amazon S3 and CloudFront servers
• various open maps:
 • Stamen Design Terrain map
 • University of Heidelberg Open Map Surfer
 • NASA Blue Marble
 • our own maps
http://www.slideshare.net/wmleler/
       opensourcebridge2012

       http://flightstats.com
     http://flightstats-inc.com

Contenu connexe

En vedette

Teclado partes principales
Teclado partes principalesTeclado partes principales
Teclado partes principalesvalenronchi
 
BUS 115 Chap011 written contracts
BUS 115 Chap011   written contractsBUS 115 Chap011   written contracts
BUS 115 Chap011 written contractsneogenesis6
 
Major economic indicators of Banladesh in mid 2015
Major economic indicators of Banladesh in mid 2015Major economic indicators of Banladesh in mid 2015
Major economic indicators of Banladesh in mid 2015Zahidul Islam
 
Importance of foregin Reserve to maintain stable foreign exchange rate
Importance of foregin Reserve to maintain stable foreign exchange rateImportance of foregin Reserve to maintain stable foreign exchange rate
Importance of foregin Reserve to maintain stable foreign exchange rateA.R. Rabin Islam
 
HTE - Low OHM Power Resistors
HTE - Low OHM Power ResistorsHTE - Low OHM Power Resistors
HTE - Low OHM Power Resistorshtrindia
 
Daily Routines:Vocabulary Activities (video)
Daily Routines:Vocabulary Activities (video)Daily Routines:Vocabulary Activities (video)
Daily Routines:Vocabulary Activities (video)A. Simoes
 

En vedette (9)

Resume Stanglin 2015
Resume Stanglin 2015Resume Stanglin 2015
Resume Stanglin 2015
 
Teclado partes principales
Teclado partes principalesTeclado partes principales
Teclado partes principales
 
BUS 115 Chap011 written contracts
BUS 115 Chap011   written contractsBUS 115 Chap011   written contracts
BUS 115 Chap011 written contracts
 
Mobile LBS
Mobile LBSMobile LBS
Mobile LBS
 
Major economic indicators of Banladesh in mid 2015
Major economic indicators of Banladesh in mid 2015Major economic indicators of Banladesh in mid 2015
Major economic indicators of Banladesh in mid 2015
 
Desafios primer ciclo
Desafios primer cicloDesafios primer ciclo
Desafios primer ciclo
 
Importance of foregin Reserve to maintain stable foreign exchange rate
Importance of foregin Reserve to maintain stable foreign exchange rateImportance of foregin Reserve to maintain stable foreign exchange rate
Importance of foregin Reserve to maintain stable foreign exchange rate
 
HTE - Low OHM Power Resistors
HTE - Low OHM Power ResistorsHTE - Low OHM Power Resistors
HTE - Low OHM Power Resistors
 
Daily Routines:Vocabulary Activities (video)
Daily Routines:Vocabulary Activities (video)Daily Routines:Vocabulary Activities (video)
Daily Routines:Vocabulary Activities (video)
 

Dernier

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Dernier (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

OpenSourceBridge2012: When Google Maps Gives You Lemons, Make Lemonade

  • 1. When Google Maps Gives You Lemons, Make Lemonade Wm Leler Flightstats http://www.slideshare.net/ wmleler/opensourcebridge2012
  • 2. Audience • This talk is about JavaScript map APIs • Do you just want to put a simple map on a web page or blog post? • Use a static image of a map • Mapbox Embed (no JavaScript!) http://mapbox.com/hosting/embedding/ • If you need traffic info (or street view, ...) you’re likely stuck with Google Maps (or MapQuest, Bing, Nokia, etc.)
  • 3. Google Maps API • 7 years old, used by 350,000 websites • Was free until recently • Now charging heavy users (price drop!) • Google will be adding advertising • Suppressed development of alternatives • Google owns you and controls you • V2 to V3 API bungle
  • 4.
  • 5. Problems with Google Maps API • Closed, proprietary system - no source • Difficult to fix bugs or add features • Clumsy object model • Poor separation of maps from API • Generic, one-size-fits-all • Three basemaps: street, satellite, terrain • Largely automobile centric
  • 6. Maps in 3 Movements Map Imagery Geography Maps & Info & Routes Data Server Map Tiles, Geom, etc. • User controls Client JavaScript Map API • Loads Map Tiles Browser • Markers and annotations
  • 7. What You Need 1. A JavaScript map API 2. A server to serve map tiles and geometry • your own or other (paid or free) 3. One or more base maps (lots of choices) • comes with server, or custom
  • 8. 1. JavaScript Map APIs • Proprietary: • Google Maps API • Mapquest, Microsoft Bing, Nokia, ... • Open: • OpenLayers - http://openlayers.org/ • Leaflet - http://leaflet.cloudmade.com/ • Modest Maps - http://modestmaps.com/ • Polymaps - http://polymaps.org/
  • 9. Google Maps <html style="height:100%"><head> <title>Google Maps Example</title> <script src="http://maps.googleapis.com/maps/api/js? key=API_KEY&sensor=false"></script> </head><body style="height:100%;margin:0;padding:0"> <div id="map" style="width:100%; height:100%"></div> <script type="text/javascript"> var pdx = new google.maps.LatLng(45.53, -122.67); var map = new google.maps.Map( document.getElementById('map'), { center: pdx, zoom: 14, mapTypeID: google.maps.MapTypeId.ROADMAP) } ); </script> </body></html>
  • 10.
  • 11. OpenLayers <html style="height:100%"><head> <title>OpenLayers Example</title> <script src="http://openlayers.org/api/OpenLayers.js"> </script> </head><body style="height:100%;margin:0;padding:0"> <div id="map" style="width:100%; height:100%"></div> <script type="text/javascript"> var map = new OpenLayers.Map('map'); var mapnik = new OpenLayers.Layer.OSM(); map.addLayer(mapnik); var pdx = new OpenLayers.LonLat(-122.67, 45.53). transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()); map.setCenter(pdx, 14); </script> </body></html>
  • 12.
  • 13. Leaflet <html style="height:100%"><head> <title>Leaflet Example</title> <link rel="stylesheet" href="leaflet.css" /> <!--[if lte IE 8]><link rel="stylesheet" href="leaflet.ie.css" /><![endif]--> <script type="text/javascript" src="leaflet.js"></script> </head><body style="height:100%;margin:0;padding:0"> <div id="map" style="height: 100%;width:100%"></div> <script type="text/javascript"> var map = new L.Map('map'); var tiles = new L.TileLayer( 'http://mt{s}.google.com/vt/v=w2.106&x={x}&y={y}&z={z}&s=', { subdomains:'0123', attribution:'&copy; Google 2011' }); var pdx = new L.LatLng(45.58961, -122.592121); map.addLayer(tiles).setView(pdx, 14); </script> </body></html>
  • 14.
  • 15. Comparison • OpenLayers is mature, very powerful, somewhat complicated and large • Leaflet is new but lots of committers, excellent object model, easily extensible, modern design, good for mobile • Modest maps is compact, minimal • Polymaps uses SVG, renders geometry directly on client (no tiles)
  • 16. Map Tiles • Instead of downloading entire map into the browser, slice up into square pieces • Enables interactivity, smooth scrolling • uses AJAX calls to download tiles • lowers resource needs for browser and server, lowers bandwidth demands
  • 17. The Tao of Tiles • Longitude (x) goes from -180º to 180º • Latitude (y) goes from 85.051º to -85.051º (arctan sinh π), not 90º • Tile is 256 x 256 pixels • Zoom level 0 has one tile for entire world
  • 18. Zoom level 1 has 4 tiles number of tiles zoom = 4 1 4 =4
  • 19. Tile Explosion • City level (11) = 4,194,304 tiles • Street level (16) = 4,294,967,296 tiles Google maps goes to level 22 = > 17 trillion tiles
  • 20. Subdomains • Browsers used to be limited to 2 network connections per domain. (Recent browsers raised limit as high as 6.) • To get around this limitation, map servers generally point multiple (3 or 4) subdomains at a single tile server. http://mt0.google.com/ http://mt1.google.com/ http://mt2.google.com/ http://mt3.google.com/
  • 21. Tile Alternatives (side note) • Google’s experimental MapsGL uses WebGL to draw streets, buildings, and other features directly in a canvas • Polymaps uses SVG • GeoJSON draws geography • Renders in browser instead of using tiles • Bad for satellite or other imagery • Doesn’t work on all browsers
  • 22. 2. Map Servers • Use a free public map server: • MapQuest Open (Open Street Map) • Use someone else’s map server • Use a commercial map server • CloudMade, MapBox • Your own server • or cloud storage
  • 23. MapQuest Open • http://developer.mapquest.com/web/ products/open/map • OpenStreetMap, aerial, and overlay tiles • Free! • Supports high bandwidth on request • Reliability is not guaranteed
  • 24. Mapquest Open Tiles • Leaflet templates (subdomains: 1 2 3 4): http://otile{s}.mqcdn.com/tiles/ 1.0.0/osm/{z}/{x}/{y}.jpg http://oatile{s}.mqcdn.com/tiles/ 1.0.0/sat/{z}/{x}/{y}.jpg http://otile{s}.mqcdn.com/tiles/ 1.0.0/hyb/{z}/{x}/{y}.png
  • 25. Someone Else’s Server • Almost all map tile servers are unsecured • You are identified by the referrer header • OK for low volume use • No reliability guarantees • Just need to determine server URL • (except for Microsoft Bing maps)
  • 26. Map Server URLs Easy to determine URL using browser debugger Google Maps Safari Browser debugger
  • 27. Constructing Tile URLs http://mt1.google.com/vt/lyrs=m@174227760&hl=en& src=app&x=81&y=183&z=9&s=Ga subdomain column row zoom new L.TileLayer( 'http://mt{s}.google.com/vt/lyrs=m@174227760&hl=en& src=app&x={x}&y={y}&z={z}&s=Ga', { subdomains:'0123', attribution:'&copy; Google' }) • Leaflet plugs in the values for you
  • 28. Slippy Maps • “slippy” naming convention for map tiles: http://otile1.mqcdn.com/tiles/1.0.0/osm/4/63/99.png http://<sub>.domain.com/.../<zoom>/<x>/<y>.png • Tiles can be served as normal files No need for a special tile server
  • 29. 3. Rendering Map Data Map Data: roads, boundaries, names, ... Styles: colors, Zoom Render line widths, levels fonts, Tile hill shading, visibility, detail, ... Map Tiles to Serve
  • 30. CloudMade • Has a large number of maps, or • Map Studio allows you to create your own map styles • Based on OSM data • CloudMade will host your map tiles ($) • or you can download and host yourself • CloudMade also created Leaflet API
  • 31.
  • 32. MapBox • TileMill allows you to create maps, using any data (not just styles) • Uses Mapnik, Carto, other open tools • MapBox will host your tiles ($) • or you can download and host yourself • They have created a large number of maps • Can dynamically modify tiles
  • 33. Sources of Map Data • Not free: Navteq, Navinfo, DigitalGlobe, SRTM, Planetary Visions, Google • OpenStreetMap, US Census TIGER • NASA/JPL, US Dept. of Agriculture • Natural Earth, CGIAR-CSI • any geographic source • anyone with a GPS unit
  • 34. Hosting Your Own Tiles • Can host as files, using Slippy map format • Or as database, using MBTiles (SQLite) • Host in cloud • Or use caching proxy • Open (CC) maps, or your own maps
  • 35. http://rtp.trimet.org/ • Multi-modal regional trip planner • car, bus, light rail, streetcar, trolley, commuter train, aerial tram, bicycle, walk • Open data allows customization • OpenLayers on the browser • Open Mapquest servers, OpenStreetMap • Developing their own map
  • 36.
  • 37. Foursquare • Leaflet on the browser • Mapbox servers (paid) • Mapbox “Streets” map (based on OSM data)
  • 38. Flightstats • Leaflet • Amazon S3 and CloudFront servers • various open maps: • Stamen Design Terrain map • University of Heidelberg Open Map Surfer • NASA Blue Marble • our own maps
  • 39. http://www.slideshare.net/wmleler/ opensourcebridge2012 http://flightstats.com http://flightstats-inc.com

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n