diff --git a/package.json b/package.json index fa647e5..aabb058 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "vue-location-picker", - "version": "1.0.1", + "name": "vue-location-picker2", + "version": "2.0.0", "author": "Pantelis Peslis ", "license": "MIT", "description": "Location Picker component for Vue.js", @@ -22,7 +22,7 @@ "build": "cross-env NODE_ENV=production webpack --progress --hide-modules" }, "dependencies": { - "vue": "^1.0.0", + "vue": "^2.2.6", "babel-runtime": "^5.8.0" }, "devDependencies": { @@ -35,8 +35,9 @@ "css-loader": "^0.23.0", "vue-hot-reload-api": "^1.2.0", "vue-html-loader": "^1.0.0", - "vue-loader": "^8.2.1", + "vue-loader": "^11.3.3", "vue-style-loader": "^1.0.0", + "vue-template-compiler": "^2.2.6", "webpack": "^1.12.2", "webpack-dev-server": "^1.12.0" } diff --git a/src/LocationPicker.vue b/src/LocationPicker.vue index 110ee5f..3d634f7 100644 --- a/src/LocationPicker.vue +++ b/src/LocationPicker.vue @@ -1,8 +1,8 @@ @@ -34,7 +34,7 @@ 'location-picker-init' (options) { this.geocoder = new google.maps.Geocoder() - this.map = new google.maps.Map(this.$els.map, Object.assign({ + this.map = new google.maps.Map(this.$refs.map, Object.assign({ center: { lat: 0, lng: 0 }, zoom: 3, disableDefaultUI: true @@ -50,10 +50,10 @@ content: this.$refs.info.$el }, options.infoWindow)) - this.autocomplete = new google.maps.places.Autocomplete(this.$els.input, Object.assign({ + this.autocomplete = new google.maps.places.Autocomplete(this.$refs.input, Object.assign({ types: ['geocode'] }, options.autocomplete)) - this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(this.$els.input) + this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(this.$refs.input) // events google.maps.event.addListenerOnce(this.map, 'idle', this.openInfoWindow) @@ -74,7 +74,7 @@ geocodeLocation (e) { this.map.panTo(e.latLng) - this.$els.input.value = '' + this.$refs.input.value = '' this.geocoder.geocode({'latLng': e.latLng}, (response) => { if (response && response.length > 0) { diff --git a/src/init.js b/src/init.js index a982924..81085df 100644 --- a/src/init.js +++ b/src/init.js @@ -1,26 +1,35 @@ -module.exports = (app, config, options) => { - if (!config.key) { - console.error('[Vue Location Picker warn]: You should give a Google Maps API key') - return - } +import Vue from 'vue' +import LocationPicker from './LocationPicker.vue' - config.libraries = 'places' - config.callback = 'initLocationPicker' +LocationPicker.install = function (Vue, options) { + console.log(options); + if (! options || !options.key) { + console.error('[Vue Location Picker warn]: You should give a Google Maps API key') + return + } - // set the callback function - global.initLocationPicker = () => { - app.$broadcast('location-picker-init', options || {}) - } + options.libraries = 'places'; + options.callback = 'initLocationPicker'; - // construct the url - var apiUrl = 'https://maps.googleapis.com/maps/api/js' - var params = Object.keys(config).map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(config[key])}`) - var url = `${apiUrl}?${params.join('&')}` + // set the global event bus + global.vueLocationPickerEventBus = new Vue(); - // create and append the script to body - var script = document.createElement('script') - script.src = url - script.async = true - script.defer = true - document.body.appendChild(script) + // set the callback function + global.initLocationPicker = () => { + global.vueLocationPickerEventBus.$emit('location-picker-init') + }; + + // construct the url + var apiUrl = 'https://maps.googleapis.com/maps/api/js'; + var params = Object.keys(options).map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(options[key])}`); + var url = `${apiUrl}?${params.join('&')}`; + + // create and append the script to body + var script = document.createElement('script'); + script.src = url; + script.async = true; + script.defer = true; + document.body.appendChild(script); } +export default LocationPicker; +