carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

Map Field: Fall back to Leaflet.js when no Google API key is provided

Open bjoluc opened this issue 3 years ago • 0 comments

I finally found some time to contribute an implementation for #613 :tada: Instead of adding an explicit set_provider method to the Map_Field class, I ended up implementing the free mapping service as a fallback when no Google API key is provided, so the map field works out of the box for new users without an API key.

The proposed implementation is backwards compatible and uses the wonderful Leaflet.js, as well as OpenStreetMap's Nominatim service for geocoding. According to my manual tests, Google Maps and Leaflet.js are interoperable with respect to positions and zoom levels. Hence, users can easily switch implementations by setting or removing the API key returned by the carbon_fields_map_field_api_key filter.

Here's a composer.json snippet to quickly try out the PR:

  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/bjoluc/carbon-fields.git",
      "branch": "feat/leaflet-map-build"
    }
  ],
  "require": {
    "htmlburger/carbon-fields": "dev-feat/leaflet-map-build"
  },

bjoluc avatar Dec 19 '22 15:12 bjoluc