"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var location_1 = require("../../utils/location"); var tools_1 = require("../../utils/tools"); var shuffle_1 = require("../../miniprogram_npm/dai-mp/tools/shuffle"); var app = getApp(); Component({ properties: { list: { type: Array, value: [], }, calloutDisplay: { type: String, value: "BYCLICK", }, }, data: { iniLoaded: false, mapId: "myMap", mapCtx: null, setting: { enable3D: true, }, iniCenterPoint: { longitude: 0, latitude: 0, }, includePoints: { padding: [50, 20, 50, 20], points: [], }, markers: [], }, lifetimes: { attached: function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { this.init(); return [2]; }); }); }, }, methods: { init: function () { return __awaiter(this, void 0, void 0, function () { var list, mapCtx; return __generator(this, function (_a) { switch (_a.label) { case 0: this.setData({ mapId: "map" + shuffle_1.default("abcdefg1234567890"), }); list = this.properties.list; this.setData({ list: list.filter(function (item) { return item.longitude && item.latitude; }), }); return [4, this.iniMap()]; case 1: _a.sent(); this.addMarker(); this.setData({ iniLoaded: true, }); return [4, tools_1.nextTick()]; case 2: _a.sent(); mapCtx = wx.createMapContext(this.data.mapId, this); if (this.data.includePoints.points && this.data.includePoints.points.length > 0) { mapCtx.includePoints(this.data.includePoints); } return [2]; } }); }); }, iniMap: function () { return __awaiter(this, void 0, void 0, function () { var list, _a, msg, data; return __generator(this, function (_b) { switch (_b.label) { case 0: list = this.data.list; this.setData({ "includePoints.points": list.map(function (item) { return { latitude: item.latitude, longitude: item.longitude, }; }), }); return [4, location_1.getLocation(true)]; case 1: _a = _b.sent(), msg = _a.msg, data = _a.data; if (msg === "success") { this.setData({ iniCenterPoint: { longitude: data.longitude, latitude: data.latitude, }, }); } else { this.setData({ iniCenterPoint: { longitude: app.globalData.longitude, latitude: app.globalData.latitude, }, }); } return [2]; } }); }); }, handleTapMarker: function (e) { console.log(e); var markerId = e.detail.markerId; this.triggerEvent("click", { index: markerId }); }, addMarker: function () { var list = this.data.list; if (!Array.isArray(list) || list.length == 0) return; var markers = []; for (var i = 0; i < list.length; i++) { var item = list[i]; markers.push({ id: i, title: item.name, latitude: item.latitude, longitude: item.longitude, iconPath: "/assets/images/map/poi.png", width: 25, height: 28, alpha: 0.8, callout: { content: item.name.length > 19 ? item.name.substr(0, 18) + "…" : item.name, color: "#fff", bgColor: "#F37D03", display: this.data.calloutDisplay, borderRadius: 5, fontSize: 16, padding: 5, }, }); } this.setData({ markers: markers }); }, }, });