-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: layer types as static method #66
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good! Should we add better error handling while we're here? I think things might blow up if createLayer
or addLayer
are called with an unsupported layer type (which could happen once we have two engines)
src/Map.js
Outdated
@@ -105,7 +103,7 @@ export class Map extends L.Evented { | |||
} | |||
|
|||
createLayer(layer) { | |||
return this.options.layerTypes[layer.type](layer) | |||
return layerTypes[layer.type](layer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this check to make sure that layerTypes[layer.type]
actually exists before calling it? Something like this?
const layerFactory = layerTypes[layer.type]
if (layerFactory) {
return layerFactory(layer)
}
return null; // Maybe this should throw an error instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the check you suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe improve the error handling in maps-gl?
src/Map.js
Outdated
@@ -73,7 +72,6 @@ export class Map extends L.Evented { | |||
|
|||
// Accept layer as config object | |||
addLayer(layer) { | |||
const { layerTypes } = this.options | |||
let newLayer = layer | |||
|
|||
if (layer.type && layerTypes[layer.type]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call addLayer
with an unsupported layer type, it will still create a layer (I guess it will probably throw an error, since the layer
object wouldn't be valid) and add a new plane. Should we exit early if the layerType is unsupported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default behaviour is to pass in a Leaflet layer instance, but it will also accept a config object. I've added a check if "newLayer instanceof L.Layer" which all layers should extend. if createLayer returns null, it will not pass this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK sure, assuming this will be fully replaced by maps-gl
let's improve the error handling there and leave this as-is 👍
# [31.1.0](v31.0.3...v31.1.0) (2020-12-10) ### Bug Fixes * fitbounds, on layergroup and in general ([0e83006](0e83006)) * load EarthEngine directly from node_modules browser build ([#50](#50)) ([020ea5f](020ea5f)) * override circle getBounds before map is bound ([#54](#54)) ([481c187](481c187)) * support index re-ordering ([20975bc](20975bc)) ### Features * event polygons ([#52](#52)) ([c2debad](c2debad)) * export map control types ([#74](#74)) ([71e597a](71e597a)) * export supported layer types ([#73](#73)) ([6bde95c](6bde95c)) * layer types as static method ([#66](#66)) ([bb124bf](bb124bf)) * support generic layer group ([89d9156](89d9156)) * synced maps support ([#58](#58)) ([0cd7eae](0cd7eae)) * synchronize the view of two maps ([#56](#56)) ([7dbffe3](7dbffe3)) * translate options to leaflet syntax ([#75](#75)) ([f1a3245](f1a3245))
🎉 This PR is included in version 31.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
We need a way to check if the API support different layer types. The GIS API supports Google layers, while Maps GL don't. This PR allows us to check if a layer type is supported without creating a map instance (static method).