Skip to content

Commit

Permalink
Remove core Google maps support
Browse files Browse the repository at this point in the history
**Why?** The strategy of loading the Google maps API via a
script tag prior to initializing farmOS-map was one of the
primary drivers of slow loading - even when Google maps
wasn't used. See performance testing at farmOS#112

Although the strategy of splitting each behavior into its own
chunk mostly mitigates any cost of including Google maps support
in farmOS-map, it will be better for the maintainability of farmOS-map
not to directly include Google maps support (RE:
farmOS#99) and a contrib module
for farmOS is a cleaner place for the integration to live anyway since
such a contrib module could be fully optional and could include
optimizations about how/when to load the Google maps API JS.
  • Loading branch information
symbioquine committed Jun 3, 2021
1 parent 7fbfa4d commit 8d2392e
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 147 deletions.
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,25 +541,6 @@ instance.addBehavior("edit").then(() => {
```


### Google Maps

To add Google Maps layers to a map, perform the following steps:

1. Obtain a Google Maps JavaScript API key. For instructions, see:
https://farmos.org/hosting/apikeys/
2. Add the following script tag to the page *before* any calls to
`farmOS.map.create()`, and replace `<KEY>` with your API key:

```
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&key=<KEY>"></script>
```

3. After calling `var instance = farmOS.map.create(target)`, call
`instance.addBehavior('google');`.

It is important to set the `height` of the map element, otherwise the Google
Maps layers will not work.

## Development

`npm install` - Install JavaScript dependencies in `./node_modules` and create
Expand Down
2 changes: 0 additions & 2 deletions examples/extended-behavior/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
</head>
<body>
<div id="map"></div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyBEB1xUvz8LG_XexTVKv5ghXEPaCzF9eng"></script>
<script src="./farmOS-map.js"></script>
<script src="./farmOS-map-example-ext-behavior.js"></script>
<script src="./mapbox.js"></script>
Expand All @@ -30,7 +29,6 @@
units: 'metric',
}
var myMap = farmOS.map.create("map", options);
myMap.addBehavior("google");
myMap.addBehavior("edit").then(() => {
myMap.addBehavior("measure", { layer: myMap.edit.layer });
myMap.edit.wktOn("featurechange", console.log);
Expand Down
2 changes: 0 additions & 2 deletions examples/simple-html-consumer/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
</head>
<body>
<div id="map"></div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyBEB1xUvz8LG_XexTVKv5ghXEPaCzF9eng"></script>
<script src="./farmOS-map.js"></script>
<script src="./mapbox.js"></script>
<script>
var options = {
units: 'metric',
}
var myMap = farmOS.map.create("map", options);
myMap.addBehavior("google");
myMap.addBehavior("edit").then(() => {
myMap.addBehavior("measure", { layer: myMap.edit.layer });
myMap.edit.wktOn("featurechange", console.log);
Expand Down
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"webpack-dev-server": "^3.11.2"
},
"dependencies": {
"@farmos.org/farmos-olgm": "^1.7.0",
"ol": "^6.5.0",
"ol-geocoder": "^4.1.2",
"ol-grid": "^1.1.4",
Expand Down
4 changes: 0 additions & 4 deletions src/behavior/google.css

This file was deleted.

107 changes: 0 additions & 107 deletions src/behavior/google.js

This file was deleted.

1 change: 0 additions & 1 deletion src/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function lazyLoadedBehavior(name) {

export default {
edit: lazyLoadedBehavior('edit'),
google: lazyLoadedBehavior('google'),
measure: lazyLoadedBehavior('measure'),
rememberLayer: lazyLoadedBehavior('rememberLayer'),
snappingGrid: lazyLoadedBehavior('snappingGrid'),
Expand Down

0 comments on commit 8d2392e

Please sign in to comment.