Created
March 5, 2016 23:41
-
-
Save davidwallacejackson/d8d6d00ef7785275b146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import BaseLayer from 'ember-leaflet/components/base-layer'; | |
import PathLayer from 'ember-leaflet/components/path-layer'; | |
import PopupMixin from 'ember-leaflet/mixins/popup'; | |
/* global L */ | |
/** | |
* An ember-leaflet wrapper for L.geoJson, which renders GeoJson data onto a | |
* map as features. | |
* | |
* NOTE: this layer uses Leaflet's standard SVG rendering for GeoJSON, so it's | |
* probably slow. | |
* | |
* Takes: | |
* - data (the GeoJSON) object to render | |
* - all standard leaflet options for L.geoJson | |
*/ | |
export default BaseLayer.extend(PopupMixin, { | |
leafletOptions: [ | |
'pointToLayer', | |
'style', | |
'onEachFeature', | |
'filter', | |
'coordsToLatLng', | |
...PathLayer.prototype.leafletOptions | |
], | |
data: null, | |
pushDataToLeaflet: Ember.observer('data', function() { | |
const data = this.get('data'); | |
if (!this._layer || !data) { | |
return; | |
} | |
//recall that GeoJSON layers are actually layer groups -- we have to clear | |
//their contents first... | |
this._layer.clearLayers(); | |
//...then add new data to recreate the child layers in an updated form | |
this._layer.addData(this.get('data')); | |
}), | |
createLayer() { | |
return L.geoJson(null, this.get('options')); | |
}, | |
didCreateLayer() { | |
this._super(...arguments); | |
this.pushDataToLeaflet(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment