Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Petr Kosikhin
committed
Mar 24, 2016
1 parent
4a99905
commit e5a7a2f
Showing
12 changed files
with
389 additions
and
10 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Ember from 'ember'; | ||
import BaseLayer from 'ember-leaflet/components/base-layer'; | ||
|
||
const {get,isEmpty,isBlank,isEqual} = Ember; | ||
|
||
export default BaseLayer.extend({ | ||
layerSetup() { | ||
this._layer = this.createLayer(); | ||
this._addObservers(); | ||
this._addEventListeners(); | ||
if (get(this,'containerLayer')) { | ||
this._layer.addTo(get(this,'containerLayer')._layer); | ||
} | ||
this.didCreateLayer(); | ||
}, | ||
createLayer(){ | ||
return L.control.layers(); | ||
}, | ||
didCreateLayer(){ | ||
let layerGroups = get(this,'containerLayer._layerGroups'); | ||
if (!isBlank(layerGroups)){ | ||
layerGroups.forEach(layerGroup=>{ | ||
if (layerGroup.default){ | ||
let containerLayer = get(this,'containerLayer._layer'); | ||
layerGroup.layer.addTo(containerLayer); | ||
} | ||
this._layer.addOverlay(layerGroup.layer,layerGroup.name); | ||
}); | ||
} | ||
let baseLayers = get(this,'containerLayer._baseLayers'); | ||
if (!isBlank(baseLayers)){ | ||
baseLayers.forEach(baseLayer=>{ | ||
if (baseLayer.default){ | ||
let containerLayer = get(this,'containerLayer._layer'); | ||
baseLayer.layer.addTo(containerLayer); | ||
} | ||
this._layer.addBaseLayer(baseLayer.layer,baseLayer.name); | ||
}); | ||
} | ||
|
||
let handler = get(this,'handler') || null; | ||
if (!isEmpty(handler)){ | ||
let map = get(this,'containerLayer')._layer; | ||
map.on('overlayadd', this.attrs.handler); | ||
map.on('overlayremove', this.attrs.handler); | ||
map.on('baselayerchange', this.attrs.handler); | ||
} | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import Ember from 'ember'; | ||
import BaseLayer from 'ember-leaflet/components/base-layer'; | ||
import ContainerMixin from 'ember-leaflet/mixins/container'; | ||
|
||
const {get, getProperties, isEmpty, set, isNone} = Ember; | ||
|
||
export default BaseLayer.extend(ContainerMixin,{ | ||
baselayer: false, | ||
blockLayer: false, | ||
default: false, | ||
createLayer(){ | ||
return this.L.layerGroup(); | ||
}, | ||
didInsertElement() { | ||
this._super(...arguments); | ||
this.layerSetup(); | ||
this.get('_childLayers').invoke('layerSetup'); | ||
this.registerNameOnParent(); | ||
}, | ||
registerNameOnParent(){ | ||
let name = get(this,'name'); | ||
let container = this.get('containerLayer'); | ||
let defaultState = get(this,'default'); | ||
if (!get(this,'baselayer')){ | ||
let layerGroups = get(container,'_layerGroups'); | ||
if (isEmpty(layerGroups)){ | ||
layerGroups = Ember.A(); | ||
set(container,'_layerGroups',layerGroups); | ||
} | ||
layerGroups.addObject({ | ||
name:name, | ||
layer:get(this,'_layer'), | ||
default: defaultState | ||
}); | ||
} else { | ||
let baseLayers = get(container,'_baseLayers'); | ||
if (isEmpty(baseLayers)){ | ||
baseLayers = Ember.A(); | ||
set(container,'_baseLayers',baseLayers); | ||
} | ||
baseLayers.addObject({ | ||
name:name, | ||
layer:get(this,'_layer._layer'), | ||
default: defaultState | ||
}); | ||
} | ||
}, | ||
willDestroyLayer() { | ||
this.get('_childLayers').invoke('layerTeardown'); | ||
this.get('_childLayers').clear(); | ||
}, | ||
layerSetup() { | ||
if (isNone(get(this,'_layer'))) { | ||
if (!get(this,'baselayer')){ | ||
set(this,'blockLayer',true); | ||
this._layer = this.createLayer(); | ||
this.didCreateLayer(); | ||
if (get(this,'containerLayer')) { | ||
if (!isNone(get(this,'containerLayer')._layer)) { | ||
get(this,'containerLayer')._layer.addLayer(this._layer); | ||
} | ||
} | ||
} else { | ||
this._layer = { | ||
_layer: null, | ||
addLayer(layer){ | ||
this._layer = layer; | ||
}, | ||
removeLayer(){ | ||
this._layer = null; | ||
} | ||
}; | ||
} | ||
} | ||
|
||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{yield}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{#if blockLayer}} | ||
{{yield}} | ||
{{/if}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-leaflet-layer-control/components/layer-control'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-leaflet-layer-control/components/layer-group'; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* global L */ | ||
export default { | ||
nyc: L.latLng(40.713282, -74.006978), | ||
sf: L.latLng(37.77493, -122.419415), | ||
chicago: L.latLng(41.878114, -87.629798), | ||
paris: L.latLng(48.856614, 2.352222), | ||
london: L.latLng(51.511214, -0.119824), | ||
newdelhi: L.latLng(28.635308, 77.22496) | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import LayerControlComponent from 'ember-leaflet-layer-control/components/layer-control'; | ||
import locations from '../../helpers/locations'; | ||
import Ember from 'ember'; | ||
const {get} = Ember; | ||
/* global L */ | ||
|
||
//Needed to silence leaflet autodetection error | ||
L.Icon.Default.imagePath = 'some-path'; | ||
|
||
let layerControl; | ||
|
||
moduleForComponent('layer-control', 'Integration | Component | layer control', { | ||
integration: true, | ||
beforeEach() { | ||
|
||
this.register('component:layer-control', LayerControlComponent.extend({ | ||
init() { | ||
this._super(...arguments); | ||
layerControl = this; | ||
} | ||
})); | ||
|
||
this.set('center', locations.nyc); | ||
this.set('zoom', 13); | ||
}, | ||
afterEach() { | ||
} | ||
}); | ||
|
||
test('it works as expected', function(assert) { | ||
this.set('locations',locations); | ||
this.set('layerControl',layerControl); | ||
this.set('tileLayerName',"tilelayer#1"); | ||
this.set('layerGroupName',"markerLayer#1"); | ||
this.render(hbs` | ||
{{#leaflet-map center=center zoom=zoom}} | ||
{{#layer-group name=tileLayerName baselayer=true default=true}} | ||
{{tile-layer url="http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"}} | ||
{{/layer-group}} | ||
{{#layer-group name=layerGroupName default=true}} | ||
{{marker-layer location=locations.nyc}} | ||
{{/layer-group}} | ||
{{layer-control}} | ||
{{/leaflet-map}} | ||
`); | ||
assert.ok(layerControl._layer._baseLayersList.innerText.indexOf(get(this,'tileLayerName'))); | ||
assert.ok(layerControl._layer._overlaysList.innerText.indexOf(get(this,'layerGroupName'))); | ||
}); |
Oops, something went wrong.