| Conditions | 1 |
| Total Lines | 63 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | // TODO: Refactor the heck out of this mess |
||
| 24 | export function setUpMap(options) |
||
| 25 | { |
||
| 26 | var mapboxAccessToken = $("#mapid").data("mapboxAccessToken"); |
||
| 27 | var locusRadius = 1609.34; // 1 mile |
||
| 28 | |||
| 29 | streetMap = L.tileLayer( |
||
| 30 | "https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}@2x?access_token=" + mapboxAccessToken, |
||
| 31 | { |
||
| 32 | // These are mapbox-specific |
||
| 33 | id: "gothick/ckhb31na304g619t67r3gcngx", |
||
| 34 | tileSize: 512, |
||
| 35 | zoomOffset: -1, |
||
| 36 | // More general |
||
| 37 | maxZoom: 19, |
||
| 38 | attribution: "Map data © <a href='https://www.openstreetmap.org/'>OpenStreetMap</a> contributors, <a href='https://creativecommons.org/licenses/by-sa/2.0/'>CC-BY-SA</a>, Imagery © <a href='https://www.mapbox.com/'>Mapbox</a>" |
||
| 39 | }); |
||
| 40 | |||
| 41 | satelliteMap = L.tileLayer( |
||
| 42 | "https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}@2x?access_token=" + mapboxAccessToken, |
||
| 43 | { |
||
| 44 | // These are mapbox-specific |
||
| 45 | id: "gothick/ckhwgr59r0uai19o077hp87w4", |
||
| 46 | tileSize: 512, |
||
| 47 | zoomOffset: -1, |
||
| 48 | // More general |
||
| 49 | maxZoom: 19, |
||
| 50 | attribution: "Map data © <a href='https://www.openstreetmap.org/'>OpenStreetMap</a> contributors, <a href='https://creativecommons.org/licenses/by-sa/2.0/'>CC-BY-SA</a>, Imagery © <a href='https://www.mapbox.com/'>Mapbox</a>" |
||
| 51 | }); |
||
| 52 | |||
| 53 | var circle = L.circle(base, { |
||
| 54 | color: "green", |
||
| 55 | fillColor: "#faa", |
||
| 56 | fillOpacity: 0.15, |
||
| 57 | radius: locusRadius, |
||
| 58 | interactive: false |
||
| 59 | }); |
||
| 60 | |||
| 61 | // Because Object.assign isn't supported in older browsers |
||
| 62 | // TODO You can go back to Object.assign now you've started using Babel in |
||
| 63 | // Webpack. It'll translate for you. |
||
| 64 | // https://stackoverflow.com/a/41455739/300836 |
||
| 65 | $.extend(options, { |
||
| 66 | maxBounds: base.toBounds(locusRadius * 5), // Give a bit of wiggle room around the circle, but don"t let the user drift too far away |
||
| 67 | layers: [streetMap, circle], |
||
| 68 | loadingControl: true, // https://github.com/ebrelsford/Leaflet.loading |
||
| 69 | tap: false, // https://github.com/domoritz/leaflet-locatecontrol#safari-does-not-work-with-leaflet-171 |
||
| 70 | }); |
||
| 71 | |||
| 72 | var map = L.map("mapid", options) |
||
| 73 | .setView(base, 14); |
||
| 74 | |||
| 75 | var baseMaps = { |
||
| 76 | "Satellite": satelliteMap, |
||
| 77 | "Streets": streetMap |
||
| 78 | }; |
||
| 79 | |||
| 80 | L.control.layers(baseMaps).addTo(map); |
||
| 81 | L.control.scale().addTo(map); |
||
| 82 | |||
| 83 | L.control.locate().addTo(map); |
||
| 84 | |||
| 85 | return map; |
||
| 86 | } |
||
| 87 | |||
| 215 |