Public Lab

Update initializers to class factory syntax

The problem

What's supposed to happen:

From the official Leaflet docs:

Class Factories

You may have noticed that Leaflet objects are created without using the new keyword. This is achieved by complementing each class with a lowercase factory method:

new L.Map('map'); // becomes:
L.map('map');

What actually does happen:

We use built-in Leaflet classes such as L.Control.Layers, L.Map, and L.LatLng, but we don't take advantage of their suggested class factory syntax. Let's clean up the below file a bit to do that:

Solution

  1. remove the new keyword and change the initializer to L.map https://github.com/publiclab/mapknitter/blob/fb876407671f27e0bc97cb9da1edb2baa8797ac0/app/views/map/_leaflet.html.erb#L57
  2. remove the new keyword and change the initializer to L.control.layers https://github.com/publiclab/mapknitter/blob/fb876407671f27e0bc97cb9da1edb2baa8797ac0/app/views/map/_leaflet.html.erb#L70
  3. remove the new keyword and change the initializer to L.latLng https://github.com/publiclab/mapknitter/blob/fb876407671f27e0bc97cb9da1edb2baa8797ac0/app/views/map/_leaflet.html.erb#L73

Additional Information

Please find further information on installation, solving, & getting help on the linked issue.

Thank You 😊

Task tags

  • leaflet
  • refactoring
  • javascript
  • easy
  • beginner

Students who completed this task

VladeDev

Task type

  • code Code

Level

Beginner
close

2019