| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- /*******************************************************************************
- * Copyright(c) 2020 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:
- * 2.功能描述:共同类
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * admin 2021-03-31 1.00 新建
- *******************************************************************************/
- var QQMapWX = require('./qqmap-wx-jssdk.min');
- const config = require('../config/config.js');
- const constants = require('../utils/constants.js');
- const util = require('./util');
- const app = getApp();
- var qqmapsdk;
- /**
- * 小程序地图调用
- */
- function onClickWxchartAddress() {
- const key = config.key; //使用在腾讯位置服务申请的key
- const referer = 'wx76a9a06e5b4e693e'; //调用插件的app的名称
- const category = '小区';
- wx.navigateTo({
- url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&category=' + category
- });
- }
- /**
- * 判断是否有按钮权限
- * @param {*} functionCode
- */
- function hasRight(functionCode) {
- let rights = app.globalData.user.rights
- let value = false
- if (rights != null && rights.length > 0) {
- rights.forEach(item => {
- if (item.FunctionCode == functionCode) {
- value = true
- return
- }
- })
- }
- return value
- }
- /**
- * 跳转到固定节点的位置
- * @param {*} selectid
- * @param {*} minus
- */
- function navigatePosition(selectid, minus) {
- //1、返回一个查询实例
- const query = wx.createSelectorQuery();
- //2、选择要跳转的节点id
- query.select('#' + selectid).boundingClientRect();
- //3、获取显示区域的尺寸、滚动等位置等信息,然后添加节点的滚动位置查询
- query.selectViewport().scrollOffset();
- //4、执行跳转
- query.exec((res) => {
- //5、res[0]是步骤2中的数据,res[1]是步骤3中的数据
- if (res[0] && res[1]) {
- //6、将页面滚动到目标位置 减300不是固定的 根据自己的要求调
- wx.pageScrollTo({
- //7、计算滚动到目标的位置
- scrollTop: res[0].top + res[1].scrollTop - minus,
- duration: 300
- })
- }
- });
- }
-
- /**
- * 导航
- */
- function navigate(address) {
- qqmapsdk.geocoder({
- //获取表单传入地址
- address: address,
- //地址参数,例:固定地址,address: '北京市海淀区彩和坊路海淀西大街74号'
- success: function (res) {//成功后的回调
- var res = res.result;
- var latitude = res.location.lat;
- var longitude = res.location.lng;
- wx.openLocation({
- latitude,
- longitude,
- scale: 18
- })
- },
- fail: function (error) {
- wx.showToast({
- title: '地址无法导航',
- image: '/static/image/warning.png',
- duration: 1000
- })
- },
- complete: function (res) {
- }
- })
- }
- /**
- * 本接口提供由坐标到坐标所在位置的文字描述的转换,输入坐标返回地理位置信息和附近poi列表。
- * @param {*} loc
- */
- function reverseGeocoder(loc) {
- return new Promise(resolve => {
- qqmapsdk.reverseGeocoder({
- location: {
- latitude: loc.latitude,
- longitude: loc.longitude
- } || '',
- //get_poi: 1, //是否返回周边POI列表:1.返回;0不返回(默认),非必须参数
- success: function (res) {//成功后的回调
- resolve(res)
- },
- fail: function (error) {
- resolve('')
- },
- complete: function (res) {
- }
- })
- });
- }
- /**
- * 调用距离计算接口
- * @param {*} fromloc
- * @param {*} toloc
- */
- function calculateDistance(fromloc, toloc) {
- return new Promise(resolve => {
- //调用距离计算接口
- qqmapsdk.calculateDistance({
- //mode: 'straight',//可选值:'driving'(驾车)、'walking'(步行),不填默认:'walking',可不填 新增直线距离计算,‘straight’(直线)
- //from参数不填默认当前地址
- //获取表单提交的经纬度并设置from和to参数(示例为string格式)
- from: fromloc, //若起点有数据则采用起点坐标,若为空默认当前地址
- to: toloc, //终点坐标
- success: function (res) {//成功后的回调
- var destinationDistance = res.result.elements[0].distance;
- console.log("calculateDistance-ok", res);
- resolve(destinationDistance)
- },
- fail: function (error) {
- console.log("calculateDistance-error", error);
- resolve(0)
- },
- complete: function (res) {
- }
- });
- });
- }
- /**
- * 百度转腾讯
- * @param {*} lat
- * @param {*} lng
- */
- function bdMap_to_wxMap(lat, lng) {
- let pi = 3.14159265358979324 * 3000.0 / 180.0;
- let x = lng - 0.0065;
- let y = lat - 0.006;
- var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi);
- var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi);
- let lngv = z * Math.cos(theta);
- let latv = z * Math.sin(theta);
- return { 'longitude': lngv, 'latitude': latv };
- }
- /**
- * 腾讯转百度
- * @param {*} lat
- * @param {*} lng
- */
- function wxMap_to_bdMap(lat, lng) {
- let pi = 3.14159265358979324 * 3000.0 / 180.0;
- let x = lng;
- let y = lat;
- var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi);
- var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi);
- let lngv = z * Math.cos(theta) + 0.0065;
- let latv = z * Math.sin(theta) + 0.006;
- return { 'longitude': lngv, 'latitude': latv };
- }
- /**
- * 在onload时间中新建qq地址对象
- */
- function openQQMap() {
- if (qqmapsdk === undefined || qqmapsdk === null) {
- qqmapsdk = new QQMapWX({
- key: '7I3BZ-VADCX-TJQ4C-TN5O4-F4BZE-RDFCK'
- });
- }
- }
- /**
- * 判断是否有按钮权限
- * @param {*} functionCode
- */
- function hasButtonRight(functionCode) {
- let buttonRights = app.globalData.buttonRights
- let orderAuditVisible = buttonRights.indexOf(functionCode)
- return orderAuditVisible == -1 ? false : true
- }
- /**
- * 判断是否有画面的uuid权限
- * @param {*} functionCode
- */
- function hasPageUUidRight(uuid) {
- let pageRights = app.globalData.pageRights
- let pageVisible = pageRights.indexOf(uuid)
- return pageVisible == -1 ? false : true
- }
- /**
- * 导出函数
- */
- module.exports = {
- openQQMap,
- navigate,
- reverseGeocoder,
- calculateDistance,
- hasButtonRight,
- hasRight,
- wxMap_to_bdMap,
- bdMap_to_wxMap,
- onClickWxchartAddress,
- hasPageUUidRight
- }
|