SlideShare uma empresa Scribd logo
1 de 42
Powerful Mapping Web
Applications with Open
     Source Tools
   Wm Leler - Flightstats, Inc.
      Mele Sax-Barnett &
   Grant Humphries - TriMet
Part 1 - Leaflet

• Build an online map webapp
• We will be using Leaflet, but most things
  would be similar using OpenLayers, Modest
  Maps, Polymaps, Google Maps API, Bing,
  Nokia, etc.
Files
• http://demo.flightstats-ops.com/NACIS/
 • requirements.html
 • workshop.zip (exercise source + jQuery)
 • talk/ (these slides)
• Unzip workshop.zip and put Leaflet in the
  same directory
Directory structure

• workshop/
 • ex*.html and ex*.js
 • img/
 • jquery-1.8.2.js
 • Leaflet/
Maps in 3 Movements
 Map      Maps, Imagery Geography
 Data     OSM & Info & Routes



Server     Map Tiles, Geom, etc.


                                    • User controls
 Client
            JavaScript Map API
                                    • Loads Map Tiles
Browser                             • Markers and
                                     annotations
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
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
Map Tiles

• Instead of downloading entire map into
  the browser, slice up into 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 directly
• Renders in browser instead of using tiles
• Bad for satellite or other imagery
• Doesn’t work on all browsers
Ex 1
• Very simple map using Leaflet
 • JavaScript and CSS
• Uses MapQuest Open tile server
 • Map data from OSM
• No jQuery (yet)
• Chaining of Leaflet commands
Ex 2
• Move JavaScript into a separate file
• Pattern to isolate namespace
• jQuery
 • $(document).ready()
 • instead of “onload”
• L.latLng location
Ex 3

• Overlay layer
 • Composite weather radar data from
    NEXRAD (National Weather Service)
 • Iowa State server
 • WMS (Web Map Server)
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
Make Your Own Maps
• Lots of Open Source Software for creating
  maps
• CloudMade
 • http://cloudmade.com/products/style-
    editor/gallery
• Mapbox
 • http://mapbox.com/tilemill/gallery/
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
• MapBox will host your tiles ($)
 • or you can download and host yourself
• They have created a large number of maps
• Can dynamically modify tiles
Ex 4
• Map options
• Layers, Scale, Attribution controls
 • override Attribution control
• Two basemaps: street and satellite
 • MapQuest Open
• Two overlays: weather radar and streets
 • Iowa and MapQuest Open
Tile Servers
• Lots of tile servers out there
• Raw tile servers (like MapQuest, Google)
 • http://demo.flightstats-ops.com/maps
• WMS (Like Iowa weather)
 • http://trac.osgeo.org/openlayers/wiki/
    AvailableWMSServices
• Many more
Someone Else’s Server
• Almost all map tile servers are unsecured
• You are identified by the referrer header
• Can be 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

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

                src=app&x=81&y=183&z=9&s=Ga
  subdomain
                    column      row    zoom
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:'© Google' })
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>.<format>

http://otile{s}.mqcdn.com/tiles/1.0.0/osm/
{z}/{x}/{y}.png

• Tiles can be served as normal files
   No need for a special tile server
Bing

• Bing tiles use a different naming scheme,
  based on quadtrees.
• There’s a Leaflet plugin for that!
• https://gist.github.com/1221998
Ex 5
• Exercise:
 • Add a new base map
 • Add an overlay
• Use http://demo.flightstats-ops.com/maps
  or any other map (with raw tile server)
• Use the debugger to figure out URL
  template
Adding a Data Source
• We are going to request real-time airplane
  positions from the Flightstats data API
  • appId = ‘ebc6552f’; appKey = ‘NACIS’
• https://developer.flightstats.com/api-docs/
  flightstatus/v2/airport
  • Airport tracks (departures)
  • Live documentation
AJAX

• jQuery makes it very easy to make an
  AJAX call to a remote API
• We are using the JSONP protocol and data
  format
• Show position of each airplane with a
  marker and a popup
Ex 6

• AJAX call to get data
 • Get airplane positions
• Add markers and popups
 • L.marker
Ex 7

• Replace marker with Geometry (circle)
 • L.circleMarker
• Handle both departing and arriving flights
Ex 8

• Add airport control tower
• Add image icon to a marker
 • img/tower.png
 • L.icon class
Ex 9

• Create a custom image for a marker
• airplane icons
• Use divIcon class
 • L.divIcon
• Add rotate method to Marker class
Custom Layers
• You can define custom map layers
• Define methods:
 • initialize, onAdd, onRemove
• call private update_ method on scroll
• turn off zoom animation
• L.Class.extend
Ex 10

• Create custom layers for airplanes and
  airport
• Extend L.Class
• You lose some functionality of L.marker,
  but you can add it back
Plug-ins

• http://leaflet.cloudmade.com/plugins.html
• https://github.com/shramov/leaflet-plugins
 • Rotate markers!
 • (reinventing the wheel)
Libraries
• Link to minified jQuery library
 • See http://jquery.com/download/
• Link to minified Leaflet library
 • See http://leaflet.cloudmade.com/
    download.html
• Versions on a popular CDN will be faster
Ex 11

     CDN (Content Delivery Network)
1.   <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.css" />
2.   <!--[if lte IE 8]>
3.      <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.ie.css" />
4.   <![endif]-->
5.   <script src="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.js"></script>
6.   <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>



     jQuery also on Google and Microsoft CDNs
Part 2


• Open Street Map and QGIS
• Mele and Grant

Mais conteúdo relacionado

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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...
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

NACIS 2012 Workshop

  • 1. Powerful Mapping Web Applications with Open Source Tools Wm Leler - Flightstats, Inc. Mele Sax-Barnett & Grant Humphries - TriMet
  • 2. Part 1 - Leaflet • Build an online map webapp • We will be using Leaflet, but most things would be similar using OpenLayers, Modest Maps, Polymaps, Google Maps API, Bing, Nokia, etc.
  • 3. Files • http://demo.flightstats-ops.com/NACIS/ • requirements.html • workshop.zip (exercise source + jQuery) • talk/ (these slides) • Unzip workshop.zip and put Leaflet in the same directory
  • 4. Directory structure • workshop/ • ex*.html and ex*.js • img/ • jquery-1.8.2.js • Leaflet/
  • 5. Maps in 3 Movements Map Maps, Imagery Geography Data OSM & Info & Routes Server Map Tiles, Geom, etc. • User controls Client JavaScript Map API • Loads Map Tiles Browser • Markers and annotations
  • 6. 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
  • 7. 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
  • 8. Map Tiles • Instead of downloading entire map into the browser, slice up into pieces • Enables interactivity, smooth scrolling • uses AJAX calls to download tiles • lowers resource needs for browser and server, lowers bandwidth demands
  • 9. 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
  • 10. Zoom level 1 has 4 tiles number of tiles zoom = 4 1 4 =4
  • 11. 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
  • 12. 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/
  • 13. 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 directly • Renders in browser instead of using tiles • Bad for satellite or other imagery • Doesn’t work on all browsers
  • 14. Ex 1 • Very simple map using Leaflet • JavaScript and CSS • Uses MapQuest Open tile server • Map data from OSM • No jQuery (yet) • Chaining of Leaflet commands
  • 15. Ex 2 • Move JavaScript into a separate file • Pattern to isolate namespace • jQuery • $(document).ready() • instead of “onload” • L.latLng location
  • 16. Ex 3 • Overlay layer • Composite weather radar data from NEXRAD (National Weather Service) • Iowa State server • WMS (Web Map Server)
  • 17. 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
  • 18. 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
  • 19. Make Your Own Maps • Lots of Open Source Software for creating maps • CloudMade • http://cloudmade.com/products/style- editor/gallery • Mapbox • http://mapbox.com/tilemill/gallery/
  • 20. 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
  • 21.
  • 22. MapBox • TileMill allows you to create maps, using any data • not just styles • MapBox will host your tiles ($) • or you can download and host yourself • They have created a large number of maps • Can dynamically modify tiles
  • 23. Ex 4 • Map options • Layers, Scale, Attribution controls • override Attribution control • Two basemaps: street and satellite • MapQuest Open • Two overlays: weather radar and streets • Iowa and MapQuest Open
  • 24. Tile Servers • Lots of tile servers out there • Raw tile servers (like MapQuest, Google) • http://demo.flightstats-ops.com/maps • WMS (Like Iowa weather) • http://trac.osgeo.org/openlayers/wiki/ AvailableWMSServices • Many more
  • 25. Someone Else’s Server • Almost all map tile servers are unsecured • You are identified by the referrer header • Can be 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 Browser debugger
  • 27. Constructing Tile URL Templates http://mt1.google.com/vt/lyrs=m@174227760&hl=en& src=app&x=81&y=183&z=9&s=Ga subdomain column row zoom 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' })
  • 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>.<format> http://otile{s}.mqcdn.com/tiles/1.0.0/osm/ {z}/{x}/{y}.png • Tiles can be served as normal files No need for a special tile server
  • 29. Bing • Bing tiles use a different naming scheme, based on quadtrees. • There’s a Leaflet plugin for that! • https://gist.github.com/1221998
  • 30. Ex 5 • Exercise: • Add a new base map • Add an overlay • Use http://demo.flightstats-ops.com/maps or any other map (with raw tile server) • Use the debugger to figure out URL template
  • 31. Adding a Data Source • We are going to request real-time airplane positions from the Flightstats data API • appId = ‘ebc6552f’; appKey = ‘NACIS’ • https://developer.flightstats.com/api-docs/ flightstatus/v2/airport • Airport tracks (departures) • Live documentation
  • 32. AJAX • jQuery makes it very easy to make an AJAX call to a remote API • We are using the JSONP protocol and data format • Show position of each airplane with a marker and a popup
  • 33. Ex 6 • AJAX call to get data • Get airplane positions • Add markers and popups • L.marker
  • 34. Ex 7 • Replace marker with Geometry (circle) • L.circleMarker • Handle both departing and arriving flights
  • 35. Ex 8 • Add airport control tower • Add image icon to a marker • img/tower.png • L.icon class
  • 36. Ex 9 • Create a custom image for a marker • airplane icons • Use divIcon class • L.divIcon • Add rotate method to Marker class
  • 37. Custom Layers • You can define custom map layers • Define methods: • initialize, onAdd, onRemove • call private update_ method on scroll • turn off zoom animation • L.Class.extend
  • 38. Ex 10 • Create custom layers for airplanes and airport • Extend L.Class • You lose some functionality of L.marker, but you can add it back
  • 40. Libraries • Link to minified jQuery library • See http://jquery.com/download/ • Link to minified Leaflet library • See http://leaflet.cloudmade.com/ download.html • Versions on a popular CDN will be faster
  • 41. Ex 11 CDN (Content Delivery Network) 1. <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.css" /> 2. <!--[if lte IE 8]> 3. <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.ie.css" /> 4. <![endif]--> 5. <script src="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.js"></script> 6. <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script> jQuery also on Google and Microsoft CDNs
  • 42. Part 2 • Open Street Map and QGIS • Mele and Grant

Notas do Editor

  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
  40. \n
  41. \n
  42. \n