|
| 1 | +# Contributions |
| 2 | + |
| 3 | +## Google Maps API Grid Overlay |
| 4 | + |
| 5 | +The `contrib` directory includes `olc_grid_overlay.js` (also a minified version). This allows you to plot an Open Location Code grid on top of a embedded Google Map. |
| 6 | + |
| 7 | +As you pan or zoom the map, the grid and labels are redrawn. |
| 8 | + |
| 9 | +### Adding the overlay |
| 10 | + |
| 11 | +```javascript |
| 12 | +// After you have created the Google Maps object, instantiate |
| 13 | +// the grid overlay, passing it the map object. |
| 14 | +var overlay = new OLCGridOverlay({map: map}); |
| 15 | + |
| 16 | +// Alternatively, use the setMap() method. |
| 17 | +var overlay = new OLCGridOverlay(); |
| 18 | +overlay.setMap(map); |
| 19 | +``` |
| 20 | + |
| 21 | +### Configuring the overlay |
| 22 | + |
| 23 | +The options object specification is as follows: |
| 24 | + |
| 25 | +| Properties || |
| 26 | +|---|---| |
| 27 | +| **map** | **Type: [Map](https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map)** Map on which to display the overlay. | |
| 28 | +| **minorGridDisplay** |**Type: boolean** Whether to display the minor grid and row/column grid labels. Defaults to **true**. | |
| 29 | +| **roadMapColor** |**Type: String** The stroke color to use for the grid lines over road or terrain maps. All CSS3 colors are supported except for extended named colors. Defaults to #7BAAF7. | |
| 30 | +| **roadMapLabelClass** | **Type: String** The CSS class name to use for text labels over road or terrain maps. Defaults to **olc_overlay_text**. | |
| 31 | +| **satelliteMapColor** | **Type: String** The stroke color to use for the grid lines over satellite or hybrid maps. All CSS3 colors are supported except for extended named colors. Defaults to #7BAAF7. | |
| 32 | +| **satelliteMapLabelClass** | **Type: String** The CSS class name to use for text labels over satellite or hybrid maps. Defaults to **olc_overlay_text**. | |
| 33 | + |
| 34 | +### Styling labels |
| 35 | +The text labels default to using the CSS class selector `.olc_overlay_text`. If there is no CSS style with that selector, one will be automatically added to the document. If you want to specify your own style, you should ensure it includes the following settings: |
| 36 | + |
| 37 | +```html |
| 38 | +text-align: center; |
| 39 | +position: fixed; |
| 40 | +display: flex; |
| 41 | +justify-content: center; |
| 42 | +flex-direction: column; |
| 43 | +``` |
| 44 | + |
| 45 | +It's a good idea to use slightly different styles for the road and satellite maps with different text colors. This is because of the different colors used in the map styles, so using different colors for the grids and labels improves legibility. |
| 46 | + |
| 47 | +Here is an example of using separate styles: |
| 48 | +```html |
| 49 | + <style> |
| 50 | + .olc_label_road { |
| 51 | + font-family: Roboto, sans; |
| 52 | + font-weight: 400; |
| 53 | + color: #7BAAF7; |
| 54 | + text-align: center; |
| 55 | + position: fixed; |
| 56 | + display: flex; |
| 57 | + justify-content: center; |
| 58 | + flex-direction: column; |
| 59 | + } |
| 60 | + .olc_label_sat { |
| 61 | + font-family: Roboto, sans; |
| 62 | + font-weight: 400; |
| 63 | + color: #3376E1; |
| 64 | + text-align: center; |
| 65 | + position: fixed; |
| 66 | + display: flex; |
| 67 | + justify-content: center; |
| 68 | + flex-direction: column; |
| 69 | + } |
| 70 | + </style> |
| 71 | +``` |
| 72 | + |
| 73 | +To use those styles, and use the same colors for the grid lines, create your overlay like this: |
| 74 | + |
| 75 | +```javascript |
| 76 | +// After you have created the Google Maps object, instantiate |
| 77 | +// the grid overlay, passing it the map object. |
| 78 | +var overlay = new OLCGridOverlay({ |
| 79 | + map: map, |
| 80 | + roadMapColor: '#7BAAF7', |
| 81 | + roadMapLabelClass: 'olc_label_road', |
| 82 | + satelliteMapColor: '#3376E1', |
| 83 | + satelliteMapLabelClass: 'olc_label_sat' |
| 84 | +}); |
| 85 | +``` |
0 commit comments