diff --git a/dist/baidu.js b/dist/baidu.js new file mode 100644 index 0000000..0dd4a63 --- /dev/null +++ b/dist/baidu.js @@ -0,0 +1,902 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + /** + * Baidu Map 2.0 + * API Documentation: http://developer.baidu.com/map/index.php?title=jspopular + * Demo: http://developer.baidu.com/map/jsdemo.htm + */ + + /*jshint -W079 */ + + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + + var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + + function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + + var Map = __webpack_require__(1); + /* jshint +W079 */ + + var domUtils = __webpack_require__(7); + var ieUtils = __webpack_require__(8); + var loaderUtils = __webpack_require__(9); + var DirectionsService = undefined; + var Marker = undefined; + var BaiduMap = undefined; + + var directionsService = undefined; + + var Baidu = (function (_Map) { + _inherits(Baidu, _Map); + + function Baidu() { + _classCallCheck(this, Baidu); + + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + _get(Object.getPrototypeOf(Baidu.prototype), 'constructor', this).apply(this, args); + + this.provider = 'Baidu'; + this.map = ''; + this.markers = []; + } + + _createClass(Baidu, [{ + key: 'render', + value: function render() { + var _this = this; + + // Init the map + this.map = new BaiduMap(this.domElement, this.options.map); + + // Create a marker for each point + this.points.forEach(function (point) { + var marker = new Marker(point, _this.options.marker, _this.options.markerLabel); + _this.map.addOverlay(marker); + _this.markers.push(marker); + + // Bind the info window on marker click if the option is set + if (_this.options.activeInfoWindow) { + ieUtils.addEventListener(marker, 'click', function (e) { + var infoWindow = new BMap.InfoWindow(_this.options.infoWindow.message(point.data) || '', _this.options.infoWindow); + + _this.map.openInfoWindow(infoWindow, e.target.getPosition()); + }); + } + }); + + // Center the map + this.map.setViewport(this.markers.map(function (marker) { + return marker.getPosition(); + })); + + // Init the clustering if the option is set + if (this.plugins.clusterer && this.options.activeCluster) { + var markerClusterer = new BMapLib.MarkerClusterer(this.map, { markers: this.markers }); + + markerClusterer.setStyles([this.options.markerCluster.style]); + } + } + }, { + key: 'load', + value: function load(callback, loadingMask) { + if (window.BMap && (!this.plugins.clusterer || window.BMapLib)) { + callback(); + return; + } + + var domElement = this.domElement; + var plugins = this.plugins; + + window._baiduCallbackOnLoad = function () { + // Require baidu object here cause they're not loaded before + BaiduMap = __webpack_require__(10); + Marker = __webpack_require__(11); + + ieUtils['delete'](window, '_baiduCallbackOnLoad'); + + if (plugins.clusterer) { + domUtils.addResources(domElement, [domUtils.createScript('//api.map.baidu.com/library/TextIconOverlay/1.2/src/TextIconOverlay_min.js'), domUtils.createScript('//api.map.baidu.com/library/MarkerClusterer/1.2/src/MarkerClusterer_min.js')], callback); + } else { + callback(); + } + }; + + if (loadingMask) { + callback = loaderUtils.addLoader(domElement, loadingMask, callback); + } + + domUtils.addScript(domElement, '//api.map.baidu.com/api?v=2.0&callback=_baiduCallbackOnLoad&ak=' + this.apiKey); + } + }, { + key: 'clickOnMarker', + value: function clickOnMarker(markerId) { + return this.focusOnMarker(markerId); + } + }, { + key: 'focusOnMarker', + value: function focusOnMarker(markerId) { + markerId = markerId.toString(); + var marker = this.markers.filter(function (marker) { + return marker.id.toString() === markerId; + }); + + if (marker.length) { + marker[0].dispatchEvent('click'); + } + } + }, { + key: 'getDirections', + value: function getDirections(origin, destination, options, callback) { + if (!directionsService) { + DirectionsService = __webpack_require__(12); + + var map = new BMap.Map(this.domElement); + directionsService = new DirectionsService(map, options.panelSelector); + } + + directionsService.getRoute(origin, destination, callback); + } + }]); + + return Baidu; + })(Map); + + window.Map = Baidu; + window.OneMap = Baidu; + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + + __webpack_require__(2); + var objectAssign = __webpack_require__(6); + + var Map = (function () { + function Map(domSelector, apiKey, locale, options, plugins) { + _classCallCheck(this, Map); + + this.domElement = document.querySelector(domSelector); + this.domId = this.domElement.id || ''; + this.apiKey = apiKey; + this.locale = locale || 'en'; + this.setOptions(options); + this.plugins = plugins || {}; + this.provider = '[No provider defined]'; + } + + _createClass(Map, [{ + key: 'setPoints', + value: function setPoints(points) { + if (Object.prototype.toString.call(points) === '[object Array]') { + this.points = points; + } else { + this.points = [points]; + } + } + }, { + key: 'setOptions', + value: function setOptions(options) { + var defaultOptions = { + map: {}, + marker: {}, + markerCluster: {}, + infoWindow: {}, + loadParams: {} + }; + + this.options = objectAssign(defaultOptions, options); + } + }, { + key: 'render', + value: function render() { + console.error(this.provider + ' has no render method implemented'); + } + }, { + key: 'load', + value: function load() { + console.error(this.provider + ' has no load method implemented'); + } + }, { + key: 'setBounds', + value: function setBounds() { + console.error(this.provider + ' has no setBounds method implemented'); + } + }, { + key: 'setIconOnMarker', + value: function setIconOnMarker() { + console.error(this.provider + ' has no setIconOnMarker method implemented'); + } + }, { + key: 'focusOnMarker', + value: function focusOnMarker() { + console.error(this.provider + ' has no focusOnMarker method implemented'); + } + }, { + key: 'clickOnMarker', + value: function clickOnMarker() { + console.error(this.provider + ' has no clickOnMarker method implemented'); + } + }, { + key: 'getDirections', + value: function getDirections() { + console.error(this.provider + ' has no getDirections method implemented'); + } + }, { + key: 'setCenter', + value: function setCenter() { + console.error(this.provider + ' has no setCenter method implemented'); + } + }, { + key: 'setZoom', + value: function setZoom() { + console.error(this.provider + ' has no setZoom method implemented'); + } + }, { + key: 'addMarkers', + value: function addMarkers() { + console.error(this.provider + ' has no addMarkers method implemented'); + } + }]); + + return Map; + })(); + + module.exports = Map; + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + // style-loader: Adds some css to the DOM by adding a