Code Monkey home page Code Monkey logo

leaflet-data-apis's Introduction

leaflet-data-apis

Leaflet map with multiple API data feeds from USGS, Socrata, Esri ArcGIS Online. View demo.

Screenshot

If you plan to query Socrata heavily, it is recommended you sign up for an API token at https://dev.socrata.com/.

Example of data fetch from Socrata

Assuming you have your map initialized and layers control created, load data from a GeoJSON endpoint in Socrata, translate each feature into a layer (circleMarker), bind a popup to the marker,and add it to the map like shown below.

$.getJSON("https://data.ct.gov/resource/v4tt-nt9n.geojson?&$$app_token=QVVY3I72SVPbxBYlTM8fA7eet", function(data) {
  
  var geoJsonLayer = L.geoJson(data, {
    pointToLayer: function(feature, latlng) {
      return L.circleMarker(latlng, {
        radius: 6,
        fillColor: 'blue',
        color: 'blue',
        weight: 2,
        opacity: 1,
        fillOpacity: 0.7
      }).bindPopup(feature.properties.name + '<br>' + feature.properties.district_name);
    }
  }).addTo(map);

  controlLayers.addOverlay(geoJsonLayer, 'Public Schools (CT Open Data-Socrata)');

});

Example of data load using esri-leaflet plugin

Esri-leaflet plugin allows you to load the data without using jQuery's getJSON function.

var bikeRoutes = L.esri.featureLayer({
  url: 'https://gis1.hartford.gov/arcgis/rest/services/OpenData_Community/MapServer/9',
  style: function(feature) {
    if (feature.properties.TYPE === 'Bike Lane') {
      return {color: 'green', weight: 3 };
    } else {
      return { color: 'blue', weight: 3 };
    }
  }
}).addTo(map);

controlLayers.addOverlay(bikeRoutes, 'Bike Routes (Hartford Open Data-ArcGIS Online)');

Learn more

Credits

  • Leaflet (see license)
  • Esri Leaflet plugin (Apache 2.0)
  • jQuery (MIT)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.