From f581e592a46115eea43fcf1e32a24b5d976cf2fd Mon Sep 17 00:00:00 2001 From: dong_bo0602 <358256383@qq.com> Date: Tue, 14 Jul 2020 19:01:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E5=8C=96=E5=9C=B0=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.json | 1 + images/marker_red.png | Bin 0 -> 812 bytes libs/bmap-wx.js | 452 +++++++++++++++++++++++++++++++ pages/cultureMap/cultureMap.js | 59 ++++ pages/cultureMap/cultureMap.json | 3 + pages/cultureMap/cultureMap.wxml | 3 + pages/cultureMap/cultureMap.wxss | 12 + pages/heritage/heritage.js | 5 + pages/heritage/heritage.wxml | 4 + 9 files changed, 539 insertions(+) create mode 100644 images/marker_red.png create mode 100644 libs/bmap-wx.js create mode 100644 pages/cultureMap/cultureMap.js create mode 100644 pages/cultureMap/cultureMap.json create mode 100644 pages/cultureMap/cultureMap.wxml create mode 100644 pages/cultureMap/cultureMap.wxss diff --git a/app.json b/app.json index ff2f78b..2bb2a4e 100644 --- a/app.json +++ b/app.json @@ -1,5 +1,6 @@ { "pages": [ + "pages/cultureMap/cultureMap", "pages/index/index", "pages/order/order", "pages/venue/venue", diff --git a/images/marker_red.png b/images/marker_red.png new file mode 100644 index 0000000000000000000000000000000000000000..8b4e20d8b2dff17ad7bca50423cfc4638edc50c0 GIT binary patch literal 812 zcmV+{1JnG8P)X1^@s6+90*i00009a7bBm001r{ z001r{0eGc9b^rhX8FWQhbW?9;ba!ELWdK2BZ(?O2No`?gWm08fWO;GPWjp`?0=Y>< zK~#9!rIy`GQ*ju_k4=w}CN0<2X3@;qam?-Ptgsv-2kukY`426FaWd-39PvA56j?0KF&&$v)1 z#Ho31a+L!eustggc~pO1WPX(5YtJNayNkckE-4e}D~D^z|O z{QT0spZpjYAm97@Ny6=xg)BY_A`K7&?*Gd11|LW+boxm;5+O;ypTu)W83Cq&g(=4i zdhjSJwvcohC8|45Iz_a8u>))x~UXlz1iV{=e&2}nZ0w$LH;*>=s-}?HB z7H4={FE_ZGCBGLHcantHTe4g!%~h6sXl8pWSro;R<@B4wbA>7YB$O`BC%+#R94nG% zCWa*+cyC!*=5#&46J*IfueV4gix>WlVj|Zln!rf3$+41>41&sBKmPzo(=3V+&ti!^ zGr8vO8te{^<0^m#tYR&$YsJ)_?jDGLUDpZcAZ!8+pbo49JSbZ(H-b_6H4BkXV(s44 z+a4M;{1J$JzzaISZcqJBH@)_*Q3@cpd=}eCfQ_e3>CV3=V)@V1wLT zhFs&STx-T59-dM)mJ}VfXTJStCcYT0000地点描述) + * + * @param {Object} param 检索配置 + * 参数对象结构可以参考 + * https://lbs.baidu.com/index.php?title=webapi/guide/webservice-geocoding-abroad + * + */ + regeocoding (param) { + var that = this; + param = param || {}; + let regeocodingparam = { + coordtype: param["coordtype"] || 'gcj02ll', + ret_coordtype: 'gcj02ll', + radius: param["radius"] || 1000, + ak: that.ak, + sn: param["sn"] || '', + output: param["output"] || 'json', + callback: param["callback"] || function () { }, + extensions_poi: param["extensions_poi"] || 1, + extensions_road: param["extensions_road"] || false, + extensions_town: param["extensions_town"] || false, + language: param["language"] || 'zh-CN', + language_auto: param["language_auto"] || 0 + }; + let otherparam = { + iconPath: param["iconPath"], + iconTapPath: param["iconTapPath"], + width: param["width"], + height: param["height"], + alpha: param["alpha"] || 1, + success: param["success"] || function () { }, + fail: param["fail"] || function () { } + }; + let type = 'gcj02'; + let locationsuccess = function (result) { + regeocodingparam["location"] = result["latitude"] + ',' + result["longitude"]; + wx.request({ + url: 'https://api.map.baidu.com/reverse_geocoding/v3', + data: regeocodingparam, + header: { + "content-type": "application/json" + }, + method: 'GET', + success(data) { + let res = data["data"]; + if (res["status"] === 0) { + let poiObj = res["result"]; + // outputRes 包含两个对象: + // originalData为百度接口返回的原始数据 + // wxMarkerData为小程序规范的marker格式 + let outputRes = {}; + outputRes["originalData"] = res; + outputRes["wxMarkerData"] = []; + outputRes["wxMarkerData"][0] = { + id: 0, + latitude: result["latitude"], + longitude: result["longitude"], + address: poiObj["formatted_address"], + iconPath: otherparam["iconPath"], + iconTapPath: otherparam["iconTapPath"], + desc: poiObj["sematic_description"], + business: poiObj["business"], + alpha: otherparam["alpha"], + width: otherparam["width"], + height: otherparam["height"] + } + otherparam.success(outputRes); + } else { + otherparam.fail({ + errMsg: res["message"], + statusCode: res["status"] + }); + } + }, + fail(data) { + otherparam.fail(data); + } + }); + }; + let locationfail = function (result) { + otherparam.fail(result); + } + let locationcomplete = function (result) { + }; + if (!param["location"]) { + that.getWXLocation(type, locationsuccess, locationfail, locationcomplete); + } else { + let longitude = param.location.split(',')[1]; + let latitude = param.location.split(',')[0]; + let errMsg = 'input location'; + let res = { + errMsg: errMsg, + latitude: latitude, + longitude: longitude + }; + locationsuccess(res); + } + } + + /** + * gc检索(地理编码:地点->经纬度) + * + * @param {Object} param 检索配置 + * 参数对象结构可以参考 + * https://lbs.baidu.com/index.php?title=webapi/guide/webservice-geocoding + * + */ + geocoding(param) { + var that = this; + param = param || {}; + let geocodingparam = { + address: param["address"] || '', + city: param["city"] || '', + ret_coordtype: param["coordtype"] || 'gcj02ll', + ak: that.ak, + sn: param["sn"] || '', + output: param["output"] || 'json', + callback: param["callback"] || function () { } + }; + let otherparam = { + iconPath: param["iconPath"], + iconTapPath: param["iconTapPath"], + width: param["width"], + height: param["height"], + alpha: param["alpha"] || 1, + success: param["success"] || function () { }, + fail: param["fail"] || function () { } + }; + if (param["address"]) { + wx.request({ + url: 'https://api.map.baidu.com/geocoding/v3', + data: geocodingparam, + header: { + "content-type": "application/json" + }, + method: 'GET', + success(data) { + let res = data["data"]; + if (res["status"] === 0){ + let poiObj = res["result"]; + // outputRes 包含两个对象: + // originalData为百度接口返回的原始数据 + // wxMarkerData为小程序规范的marker格式 + let outputRes = res; + outputRes["originalData"] = res; + outputRes["wxMarkerData"] = []; + outputRes["wxMarkerData"][0] = { + id: 0, + latitude: poiObj["location"]["lat"], + longitude: poiObj["location"]["lng"], + iconPath: otherparam["iconPath"], + iconTapPath: otherparam["iconTapPath"], + alpha: otherparam["alpha"], + width: otherparam["width"], + height: otherparam["height"] + } + otherparam.success(outputRes); + } else { + otherparam.fail({ + errMsg: res["message"], + statusCode: res["status"] + }); + } + }, + fail(data) { + otherparam.fail(data); + } + }); + } else { + let errMsg = 'input address!'; + let res = { + errMsg: errMsg + }; + otherparam.fail(res); + } + } + + /** + * 天气检索 + * + * @param {Object} param 检索配置 + */ + weather(param) { + var that = this; + param = param || {}; + let weatherparam = { + coord_type: param["coord_type"] || 'gcj02', + output: param["output"] || 'json', + ak: that.ak, + sn: param["sn"] || '', + timestamp: param["timestamp"] || '' + }; + let otherparam = { + success: param["success"] || function () { }, + fail: param["fail"] || function () { } + }; + let type = 'gcj02'; + let locationsuccess = function (result) { + weatherparam["location"] = result["longitude"] + ',' + result["latitude"]; + wx.request({ + url: 'https://api.map.baidu.com/telematics/v3/weather', + data: weatherparam, + header: { + "content-type": "application/json" + }, + method: 'GET', + success(data) { + let res = data["data"]; + if (res["error"] === 0 && res["status"] === 'success') { + let weatherArr = res["results"]; + // outputRes 包含两个对象, + // originalData为百度接口返回的原始数据 + // wxMarkerData为小程序规范的marker格式 + let outputRes = {}; + outputRes["originalData"] = res; + outputRes["currentWeather"] = []; + outputRes["currentWeather"][0] = { + currentCity: weatherArr[0]["currentCity"], + pm25: weatherArr[0]["pm25"], + date: weatherArr[0]["weather_data"][0]["date"], + temperature: weatherArr[0]["weather_data"][0]["temperature"], + weatherDesc: weatherArr[0]["weather_data"][0]["weather"], + wind: weatherArr[0]["weather_data"][0]["wind"] + }; + otherparam.success(outputRes); + } else { + otherparam.fail({ + errMsg: res["message"], + statusCode: res["status"] + }); + } + }, + fail(data) { + otherparam.fail(data); + } + }); + } + let locationfail = function (result) { + otherparam.fail(result); + } + let locationcomplete = function (result) { + } + if (!param["location"]) { + that.getWXLocation(type, locationsuccess, locationfail, locationcomplete); + } else { + let longitude = param.location.split(',')[0]; + let latitude = param.location.split(',')[1]; + let errMsg = 'input location'; + let res = { + errMsg: errMsg, + latitude: latitude, + longitude: longitude + }; + locationsuccess(res); + } + } + } + + module.exports.BMapWX = BMapWX; \ No newline at end of file diff --git a/pages/cultureMap/cultureMap.js b/pages/cultureMap/cultureMap.js new file mode 100644 index 0000000..7fc1d2a --- /dev/null +++ b/pages/cultureMap/cultureMap.js @@ -0,0 +1,59 @@ +// 引用百度地图微信小程序JSAPI模块 +var bmap = require('../../libs/bmap-wx.js'); +var app = getApp(); +Page({ + data: { + markers: [], + latitude: '', + longitude: '', + placeData: {}, + venueUrl: app.venueUrl, + }, + makertap: function(e) { + var that = this; + var id = e.markerId; + }, + onLoad: function() { + var self = this; + // 新建百度地图对象 + var BMap = new bmap.BMapWX({ + ak: 'qLbLh9KupfB8Ir72bkKogyvYi246rkKS' + }); + var fail = function(data) { + app.dialog.msg(data.msg); + }; + var success = function(code,data) { + wx.getLocation({ + altitude: 'false', + type: 'wgs84', + success: function (res) { + self.setData({ + longitude: res.longitude, + latitude: res.latitude + }) + } + }) + var arr = [] + for (var i = 0; i < data.data.length; i++) { + var obj = { + latitude: data.data[i].latitude, + longitude: data.data[i].longitude, + iconPath: '../../images/marker_red.png', + callout:{ + content:data.data[i].venueName + "\r\n地址:" + data.data[i].venuePosition + "\r\n电话:" + data.data[i].venueTelephone, + bgColor:"#fff", + padding:"5px", + borderRadius:"2px", + borderWidth:"1px", + borderColor:"#07c160", + } + } + arr.push(obj) + } + self.setData({ + markers: arr + }); + } + app.restAjax.get(app.restAjax.path('{venueUrl}/app/venuesmap/listrangevenuesinforelease', [self.data.venueUrl]),{},null,success,fail) + } +}) \ No newline at end of file diff --git a/pages/cultureMap/cultureMap.json b/pages/cultureMap/cultureMap.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/cultureMap/cultureMap.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/cultureMap/cultureMap.wxml b/pages/cultureMap/cultureMap.wxml new file mode 100644 index 0000000..df31520 --- /dev/null +++ b/pages/cultureMap/cultureMap.wxml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/pages/cultureMap/cultureMap.wxss b/pages/cultureMap/cultureMap.wxss new file mode 100644 index 0000000..f52424a --- /dev/null +++ b/pages/cultureMap/cultureMap.wxss @@ -0,0 +1,12 @@ +.map_container{ + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; +} + +.map { + height: 100%; + width: 100%; +} \ No newline at end of file diff --git a/pages/heritage/heritage.js b/pages/heritage/heritage.js index 2e358bb..55cd130 100644 --- a/pages/heritage/heritage.js +++ b/pages/heritage/heritage.js @@ -25,6 +25,11 @@ Page({ url: '../friendCircle/friendCircle', }) }, + goCultureMap: function () { + wx.navigateTo({ + url: '../cultureMap/cultureMap', + }) + }, doGetLibraryList: function(page) { var self = this; app.dialog.loading('正在加载'); diff --git a/pages/heritage/heritage.wxml b/pages/heritage/heritage.wxml index 99632f4..b487c3d 100644 --- a/pages/heritage/heritage.wxml +++ b/pages/heritage/heritage.wxml @@ -11,6 +11,10 @@ 文化分享 + + + 文化地图 +