-
-
Save jgwhite/31cecf3b5e1af91f5427 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 config from 'minutebase/config/environment'; | |
export default Ember.Component.extend({ | |
classNames: "google-static-map", | |
tagName: "img", | |
attributeBindings: ["src"], | |
width: Ember.computed("viewport.width", { | |
get() { | |
this.get("viewport.width"); // consume it and throw it away | |
return this.$().width(); | |
} | |
}), | |
height: Ember.computed("viewport.height", { | |
get() { | |
this.get("viewport.height"); // consume it and throw it away | |
return this.$().height(); | |
} | |
}), | |
zoom: 14, | |
parts: null, | |
center: null, | |
setupParts: Ember.on("init", function() { | |
this.set("parts", []); | |
}), | |
monitorWindowSize: Ember.on("didInsertElement", function() { | |
this._listener = () => Ember.run.debounce(this, "calculateDimensions", 100); | |
Ember.$(window).on("resize", this._listener); | |
}), | |
stopMonitioringWindowSize: Ember.on("willDestroyElement", function() { | |
if (this._listener) { | |
Ember.$(window).off("resize", this._listener); | |
} | |
}), | |
src: Ember.computed("center", "width", "height", "zoom", "[email protected]", { | |
get() { | |
let url = "https://maps.googleapis.com/maps/api/staticmap?"; | |
const {center, zoom, width, height, parts} = this.getProperties("center", "zoom", "width", "height", "parts"); | |
if (!center || !width || !height) { | |
return; | |
} | |
let params = []; | |
params.push(`center=${center.lat},${center.lng}`); | |
params.push(`zoom=${zoom}`); | |
params.push(`size=${width}x${height}`); | |
params.push(`key=${config.googleKey}`); | |
params = params.concat(parts.mapBy("params")); | |
return url + params.join("&"); | |
} | |
}), | |
register(component) { | |
Ember.run.next(() => this.get("parts").pushObject(component) ); | |
}, | |
unregister(component) { | |
this.get("parts").removeObject(component); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment