Fork me on GitHub

Mapping with Leaflet

Javier Abadía y Raúl Jiménez

Technical Marketing - Esri España

Presentación adaptada de la charla original en el DevSummit de Esri 2014 por @patrickarlt - http://bit.ly/1qmxndx

¿De qué va la charla?

¿Qué hace falta?

  • API Javascript
  • Mapas Base
  • Mis propios datos geográficos

La aproximación GIS tradicional

  • API Javascript para ArcGIS
  • Mapas Base de ArcGIS Online
  • Mis propios datos geográficos, en ArcGIS for Server o ArcGIS Online

vamos a ver otra forma de hacer las cosas

¿Quiénes somos?

  • Javier Abadía, desarrollador
  • Raúl Jiménez, desarrollador
  • [en espíritu] Patrick Arlt, desarrollador/diseñador de Esri Inc. (sin experiencia previa en GIS)

How I approach the [ArcGIS] JS API

The JS API is a framework not a library

Frameworks VS Libraries

Frameworks

  • Complex
  • Opinionated
  • Don't play nice
  • Defines "how"
  • Great

Libraries

  • Single purpose
  • Flexible
  • Integrate w/ frameworks
  • Defines "what"
  • Great

The JS API is a framework for building GIS apps

  • Defines the what you can do and tells you how to do it
  • Dojo is the framework, the JS API is the library
  • API is overly complex and non-intuitive (for non-GIS)
  • Difficult to separate Dojo from the JS API

Leaflet leafletjs.com

  • Open source mapping library
  • Focused on a small (33kb), extensible API
  • Simple and clear API
  • Huge plugin eco system
// create a map in the "map" div, set the view to a given lat/lng and zoom
var map = L.map('map').setView([40.4193, -3.6931], 16);

// add tiles from OpenStreetMap
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
	attribution: '© OpenStreetMap'
}).addTo(map);
// create a marker and add it to the map
var marker = new L.Marker([ 40.411440, -3.676203]).addTo(map2);

// create a polygon and add it to the map
var polygon = new L.Polygon([[40.421438, -3.680194], [40.411440, -3.676203], [40.408270, -3.678478], [40.408956, -3.685816], [40.407322, -3.686632], [40.407486, -3.688348], [40.419510, -3.688563]]).addTo(map2);
// bind a popup to our marker
marker.bindPopup("<p>Hola Mundo!<p>");
// listen for click events on the polygon
polygon.on("click", function(e){
	alert("Has hecho clic en el polígono en " + e.latlng);
});

Leaflets API

  • Simple - Uses Lat/Lng everywhere, no projections
  • Literal - Obvious class and method names
  • Consistent - Strict adherance to its own standards
  • Fully Featured - Styling, Popups, Events
  • Extendable - Classes, events, lots of utilities

Plugins!

So many plugins...

Peeerooo....

¿Tengo que renunciar a

...los mapas base de ArcGIS Online?

...la gestión de datos geográficos de ArcGIS for Server?

...el alojamiento en la nube de datos geográficos de ArcGIS Online?

REST

Esri Leaflet

Leaflet plugins for ArcGIS

// create a map
var map = new L.Map("map").setView([ 40.453020, -3.688328], 16);

// add an ArcGIS Basemap
var tiles = L.esri.basemapLayer("Imagery").addTo(map);
// create a map
var map = L.map('map').setView([46.3, -60.7], 9);

// add a tile layer from ArcGIS Online or ArcGIS Server
var charts = new L.esri.TiledMapLayer("http://services.arcgisonline.com/ArcGIS/rest/services/Specialty/World_Navigation_Charts/MapServer").addTo(map);
var map = L.map('map').setView([36.272228, -116.817001], 7);

L.esri.basemapLayer("Gray").addTo(map);

var parks = new L.esri.DynamicMapLayer("http://mapservices.nps.gov/arcgis/rest/services/LandResourcesDivisionTractAndBoundaryService/MapServer"
).addTo(map);
L.esri.featureLayer("http://services3.arcgis.com/gzPLi0vbk0c1QVGb/ArcGIS/rest/services/Gasolinerasshape/FeatureServer/0", {
   style: function (feature) {
	  return { color: "#70ca49", weight: 2 };
	},
  onEachFeature: function (feature, layer) {
		layer.bindPopup("" + feature.properties.Rotulo + "
" + feature.properties.Municipio + "
" + feature.properties.Provincia + "
" + feature.properties.Precio95 + " €/litro
" ); }}).addTo(map);
L.esri.clusteredFeatureLayer("http://services3.arcgis.com/gzPLi0vbk0c1QVGb/arcgis/rest/services/Gasolinerasshape/FeatureServer/0", {
	onEachMarker: function(feature, marker) {
		marker.bindPopup("" + feature.properties.Rotulo + "
" + feature.properties.Municipio + "
" + feature.properties.Provincia + "
" + feature.properties.Precio95 + " €/litro
" ); } }).addTo(map);
var heat = new L.esri.HeatMapFeatureLayer("http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Graffiti_Locations3/FeatureServer/0", {
  radius: 12
}).addTo(map);
var searchControl = new L.esri.Controls.Geosearch().addTo(map);

// listen for the results event and add every result to the map
searchControl.on("results", function(e){
	console.log(e.results);
});

Smackdown!

Who Wins?

No One

Everyone

Good developers choose the right tools for the project

Choose Esri Leaflet if you...

  • are integrating into existing apps
  • are already using Leaflet
  • want a simpler focused toolset
  • want to leverage non-ArcGIS Services or data
  • want to leverage Leaflet Plugins

Choose the JS API if you...

  • want a framework
  • need deep integration with ArcGIS
  • want to support everything (renderers, web maps…)
  • work in non-web-mercator/wgs 84 projections
  • love Dojo

You are my dev team

https://github.com/esri/esri-leaflet

https://github.com/Esri/esri-leaflet-geocoder

https://github.com/Esri/esri-leaflet-demographic-layer

API Roadmap

Thanks!

Twitter : @javierabadia & @hhkaos

Slides : http://bit.ly/1okOvOu

Esri