Skip to content

Commit

Permalink
Merge 140b180 into 068cfe6
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Jan 20, 2016
2 parents 068cfe6 + 140b180 commit 1215e06
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"document",
"window",
"-Promise",
"google"
"google",
"MarkerClusterer"
],
"browser": true,
"boss": true,
Expand Down
42 changes: 42 additions & 0 deletions addon/components/g-map-cluster-marker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Ember from 'ember';
import GMapClusterer from './g-map-clusterer';
import GMapMarkerComponent from './g-map-marker';

const { isPresent, computed, assert } = Ember;

const GMapClusterMarkerComponent = GMapMarkerComponent.extend({
mapContext: computed.alias('clustererContext.mapContext'),
clusterer: computed.alias('clustererContext.clusterer'),

init() {
this._super(arguments);

const clustererContext = this.get('clustererContext');
assert('Must be inside {{#g-map-clusterer}} component with context set',
clustererContext instanceof GMapClusterer);
},

unsetMarkerFromMap() {
const marker = this.get('marker');
const clusterer = this.get('clusterer');

if (isPresent(marker) && isPresent(clusterer)) {
clusterer.removeMarker(marker);
}
},

setMap() {
const clusterer = this.get('clusterer');
const marker = this.get('marker');

if (isPresent(marker) && isPresent(clusterer)) {
clusterer.addMarker(marker);
}
}
});

GMapClusterMarkerComponent.reopenClass({
positionalParams: ['clustererContext']
});

export default GMapClusterMarkerComponent;
60 changes: 60 additions & 0 deletions addon/components/g-map-clusterer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import Ember from 'ember';
import layout from '../templates/components/g-map-clusterer';
import GMapComponent from './g-map';

const { isEmpty, isPresent, computed, observer, run, assert } = Ember;

const GMapClustererComponent = Ember.Component.extend({
layout: layout,
classNames: ['g-map-clusterer'],

map: computed.oneWay('mapContext.map'),
markers: computed.oneWay('mapContext.markers'),

init() {
this._super(arguments);

const mapContext = this.get('mapContext');
assert('Must be inside {{#g-map}} component with context set', mapContext instanceof GMapComponent);

if (isEmpty(this.get('options'))) {
this.set('options', {});
}
},

mapWasSet: observer('map', function() {
const map = this.get('map');
const clusterer = this.get('clusterer');

if (isPresent(map) && isEmpty(clusterer)) {
const options = this.get('options');
this.set('clusterer', new MarkerClusterer(map, [], options));
}
}),

willDestroyElement() {
const clusterer = this.get('clusterer');

if (isPresent(clusterer)) {
clusterer.clearMarkers();
}
},

markersChanged: observer('markers.@each.lat', 'markers.@each.lng', function() {
run.once(this, 'repaintClusterer');
}),

repaintClusterer() {
const clusterer = this.get('clusterer');

if (isPresent(clusterer)) {
clusterer.repaint();
}
}
});

GMapClustererComponent.reopenClass({
positionalParams: ['mapContext']
});

export default GMapClustererComponent;
1 change: 1 addition & 0 deletions addon/templates/components/g-map-clusterer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield this}}
1 change: 1 addition & 0 deletions app/components/g-map-cluster-marker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-g-map/components/g-map-cluster-marker';
1 change: 1 addition & 0 deletions app/components/g-map-clusterer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-g-map/components/g-map-clusterer';
6 changes: 6 additions & 0 deletions blueprints/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"predef": [
"console"
],
"strict": false
}
7 changes: 7 additions & 0 deletions blueprints/ember-g-map/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
normalizeEntityName: function() {},

afterInstall: function() {
return this.addBowerPackageToProject('markerclustererplus', '~2.1.4');
}
};
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"jquery": "^2.1.4",
"loader.js": "ember-cli/loader.js#3.2.1",
"qunit": "~1.18.0",
"sinonjs": "~1.17.1"
"sinonjs": "~1.17.1",
"markerclustererplus": "~2.1.4"
},
"devDependencies": {
"blanket": "~1.1.5"
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = {
included: function(app, parentAddon) {
var target = (parentAddon || app);
target.import('vendor/addons.css');

app.import(app.bowerDirectory + '/markerclustererplus/src/markerclusterer.js');
},

contentFor: function(type, config) {
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/components/g-map-cluster-marker-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('g-map-cluster-marker', 'Integration | Component | g map cluster marker', {
integration: true
});

test('it renders', function(assert) {
assert.expect(2);

// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

this.render(hbs`
{{#g-map as |context|}}
{{#g-map-clusterer context as |clustererContext|}}
{{g-map-cluster-marker clustererContext}}
{{/g-map-clusterer}}
{{/g-map}}
`);

assert.equal(this.$().text().trim(), '');

// Template block usage:
this.render(hbs`
{{#g-map as |context|}}
{{#g-map-clusterer context as |clustererContext|}}
{{#g-map-cluster-marker clustererContext}}
template block text
{{/g-map-cluster-marker}}
{{/g-map-clusterer}}
{{/g-map}}
`);

assert.equal(this.$().text().trim(), 'template block text');
});
32 changes: 32 additions & 0 deletions tests/integration/components/g-map-clusterer-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('g-map-clusterer', 'Integration | Component | g map clusterer', {
integration: true
});

test('it renders', function(assert) {
assert.expect(2);

// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

this.render(hbs`
{{#g-map as |context|}}
{{g-map-clusterer context}}
{{/g-map}}
`);

assert.equal(this.$().text().trim(), '');

// Template block usage:
this.render(hbs`
{{#g-map as |context|}}
{{#g-map-clusterer context}}
template block text
{{/g-map-clusterer}}
{{/g-map}}
`);

assert.equal(this.$().text().trim(), 'template block text');
});

0 comments on commit 1215e06

Please sign in to comment.