Coder Social home page Coder Social logo

leaflet-earthquake-analysis's Introduction

In this project, GeoJSON was used as a live, programatic interface to build a tool that showed significant earthquakes that had occured in the past 24 hours. The GeoJSON feed is from the USGS' Earthquake Hazards Program and is of the type FeatureCollection.

Using D3.js and the .then() method, the url was called with a promise to execute the next step in the function.

To make sure that data was feeding in correctly, console.log() was used.

Once it was confirmed that the data was coming in correctly, a base layer was created. This layer provided the base map for any images to sit on top of. Because the majority of earthquakes happen on the west coast, Albuquerque, NM was chosedn as the center point.

Using the inspector, it could be seen that D3 returned the data as an object. The object that was returned was an array of objects (bbox, features, and metadata). From here, anonymous functions were created using D3's .then() promise to first pull the data and then run each of the specified functions below:


The first function getRadius was used to show the strength of the magnitude of each earthquake. The bigger the earthquake, the larger the marker would be. To adjust the size, a multiple of 4 was used.

Additionally, a function called getColor was used to add color to the magnitude of each earthquake. The color scheme starts with light green representing the least severe earthquakes and ends with red representing the most severe earthquakes.

Both the getRadius and the getColor functions were included in the "fillColor" and "radius" options for the circleMarker layer, which can be found in the pointToLayer below.

Next, a geoJson layer was created including Leaflet's pointToLayer and onEachFeature options to create the earthquake markers and bindPopups. For both options, the functions were internally called when the data was added by passing the GeoJSON point feature and its LatLng.

Finally, using a control layer a legend was created and placed in bottom right corner. To seperate the labels and colors, a for loop was used to iterate through the the density intervals and generate a label with a colored square for each interval.


In order to be able to see the outputs of each function, they were added to the map layer, which was assigned to the variable "myMap". The "myMap" variable was then stored in the div map.

The following libraries also needed to be added to the html page in order to run D3 and Leaflet.

leaflet-earthquake-analysis's People

Contributors

cmdenys avatar

Watchers

 avatar

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.