Skip to content

Commit 4ced363

Browse files
authored
Merge pull request #55 from google/overlay
Add OLC grid overlay library.
2 parents 83a6cb0 + 3725a5e commit 4ced363

File tree

5 files changed

+486
-11
lines changed

5 files changed

+486
-11
lines changed

js/README

Lines changed: 0 additions & 11 deletions
This file was deleted.

js/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Open Location Code Javascript API
2+
This is the Javascript implementation of the Open Location Code API.
3+
4+
The library file is in `src/openlocationcode.js`. There is also a minified version, and both are also available using the following CDNs:
5+
6+
* [jsDelivr](https://www.jsdelivr.com)
7+
* https://cdn.jsdelivr.net/openlocationcode/1.0.0/openlocationcode.js
8+
* https://cdn.jsdelivr.net/openlocationcode/1.0.0/openlocationcode.min.js
9+
* [cdnjs](https://cdnjs.com/)
10+
* https://cdnjs.cloudflare.com/ajax/libs/openlocationcode/1.0.0/openlocationcode.js
11+
* https://cdnjs.cloudflare.com/ajax/libs/openlocationcode/1.0.0/openlocationcode.min.js
12+
13+
Unit tests are included and can be executed by installing gulp, gulp-qunit
14+
and gulp-util and running gulp. Unit tests are automatically run on pull
15+
and push requests and visible at https://travis-ci.org/google/open-location-code.
16+
17+
Example web pages illustrating converting map clicks to Open Location Codes,
18+
and using Googles Maps API to extend place codes to full codes are in the
19+
examples/ directory.
20+
21+
More examples are on [jsfiddle](https://jsfiddle.net/user/openlocationcode/fiddles/).

js/contrib/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)