Commit 8b2a91c9 by 李伟康

替换地图SDK

1 parent 8e3b484c
...@@ -75,9 +75,11 @@ Component({ ...@@ -75,9 +75,11 @@ Component({
}, },
getLocationByIp() { getLocationByIp() {
mapApi.getLocationByIp().then(({ mapApi.getLocationByIp().then(({
city content: {
address_detail
}
}) => { }) => {
let defaultCity = city.replace('市', '') let defaultCity = address_detail.city.replace('市', '')
this.setData({ this.setData({
defaultCity, defaultCity,
cityCode: defaultCity cityCode: defaultCity
...@@ -169,7 +171,7 @@ Component({ ...@@ -169,7 +171,7 @@ Component({
}) => { }) => {
let distanceList = [] let distanceList = []
data.elements.map(e => { data.elements.map(e => {
let distance = Number((e.distance / 1000)).toFixed(2) let distance = e.distance.value ? Number((e.distance.value / 1000)).toFixed(2) : 0
distanceList.push(distance) distanceList.push(distance)
}) })
indexGroup[index].map((s, ind) => { indexGroup[index].map((s, ind) => {
...@@ -212,25 +214,20 @@ Component({ ...@@ -212,25 +214,20 @@ Component({
}, },
openLocation(e) { openLocation(e) {
let { let {
item location,
} = e.currentTarget.dataset storeName,
if (!item.distance) { address
mapApi.geocoder(item.address).then(({geocodes}) => { } = e.currentTarget.dataset.item
let location = geocodes[0].location.split(',') mapApi.translate([
wx.openLocation({ [location.latitude, location.longitude]
longitude: Number(location[0]), ], 5).then(res => {
latitude: Number(location[1]), let {x,y} = res[0]
name: item.storeName, wx.openLocation({
address: item.address latitude: y,
}) longitude: x,
name: storeName,
address
}) })
return
}
wx.openLocation({
latitude: Number(item.location.latitude),
longitude: Number(item.location.longitude),
name: item.storeName,
address: item.address
}) })
}, },
// 下拉触底 // 下拉触底
......
...@@ -53,10 +53,12 @@ Component({ ...@@ -53,10 +53,12 @@ Component({
defaultBrand defaultBrand
} = this.data } = this.data
mapApi.getLocationByIp().then(({ mapApi.getLocationByIp().then(({
city content: {
address_detail
}
}) => { }) => {
if (defaultBrand) return if (defaultBrand) return
let defaultCity = city.replace('市', '') let defaultCity = address_detail.city.replace('市', '')
this.setData({ this.setData({
defaultCity, defaultCity,
cityCode: defaultCity cityCode: defaultCity
...@@ -169,10 +171,11 @@ Component({ ...@@ -169,10 +171,11 @@ Component({
let { let {
location location
} = defaultStore } = defaultStore
if(location.latitude == '0.0') return
mapApi.calculateDistance(fromPosition, [location.latitude, location.longitude]).then(data => { mapApi.calculateDistance(fromPosition, [location.latitude, location.longitude]).then(data => {
let { let {
distance distance
} = data.elements[0] } = data.elements
this.setData({ this.setData({
'defaultStore.distance': Number((distance / 1000)).toFixed(2) 'defaultStore.distance': Number((distance / 1000)).toFixed(2)
}) })
...@@ -223,7 +226,7 @@ Component({ ...@@ -223,7 +226,7 @@ Component({
}) => { }) => {
let distanceList = [] let distanceList = []
data.elements.map(e => { data.elements.map(e => {
let distance = Number((e.distance / 1000)).toFixed(2) let distance = e.distance.value ? Number((e.distance.value / 1000)).toFixed(2) : 0
distanceList.push(distance) distanceList.push(distance)
}) })
indexGroup[index].map((s, ind) => { indexGroup[index].map((s, ind) => {
...@@ -242,25 +245,39 @@ Component({ ...@@ -242,25 +245,39 @@ Component({
openLocation(e) { openLocation(e) {
let { let {
item location,
} = e.currentTarget.dataset storeName,
if (!item.distance) { address,
mapApi.geocoder(item.address).then(({geocodes})=> { distance
let location = geocodes[0].location.split(',') } = e.currentTarget.dataset.item
wx.openLocation({ if (!distance) {
longitude: Number(location[0]), mapApi.geocoder(address).then(({
latitude: Number(location[1]), location:locat
name: item.storeName, }) => {
address: item.address mapApi.translate([
[locat.lat, locat.lng]
], 5).then(res => {
let {x,y} = res[0]
wx.openLocation({
latitude: y,
longitude: x,
name: storeName,
address
})
}) })
}) })
return return
} }
wx.openLocation({ mapApi.translate([
latitude: Number(item.location.latitude), [location.latitude, location.longitude]
longitude: Number(item.location.longitude), ], 5).then(res => {
name: item.storeName, let {x,y} = res[0]
address: item.address wx.openLocation({
latitude: y,
longitude: x,
name: storeName,
address
})
}) })
}, },
clearData() { clearData() {
......
...@@ -4,16 +4,16 @@ ...@@ -4,16 +4,16 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"glsk-map-jssdk": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/glsk-map-jssdk/-/glsk-map-jssdk-0.1.1.tgz",
"integrity": "sha512-kwCyU8A1t7Q7V2hlzC03nc9VNNW9HPXQ5YhHsGGnrEtPxykGDG7AEyT5O7LY1zZk/8adkkk6FHgCM53r6p/4yw=="
},
"glsx-applet-component": { "glsx-applet-component": {
"version": "1.1.24", "version": "1.1.24",
"resolved": "https://registry.npmjs.org/glsx-applet-component/-/glsx-applet-component-1.1.24.tgz", "resolved": "https://registry.npmjs.org/glsx-applet-component/-/glsx-applet-component-1.1.24.tgz",
"integrity": "sha512-3XTG9J99rgKVJpcC7aKS/+N7CaS+MNYdy5qmWH8siFaRFiSo1PeBRDaprfjCazaud/c31RvpoDFUof/fxNkxjw==" "integrity": "sha512-3XTG9J99rgKVJpcC7aKS/+N7CaS+MNYdy5qmWH8siFaRFiSo1PeBRDaprfjCazaud/c31RvpoDFUof/fxNkxjw=="
}, },
"glsx-map-sdk": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/glsx-map-sdk/-/glsx-map-sdk-0.2.0.tgz",
"integrity": "sha512-uEFlXvJEDofYjasR4mwkmF5yNTRs5QA2ZAynGPHiKpKdpjQkVFPJH0zGupmQEkxmh4f5B0wPbDobHvLgld7mVw=="
},
"number-precision": { "number-precision": {
"version": "1.6.0", "version": "1.6.0",
"resolved": "https://registry.npmjs.org/number-precision/-/number-precision-1.6.0.tgz", "resolved": "https://registry.npmjs.org/number-precision/-/number-precision-1.6.0.tgz",
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"description": "", "description": "",
"main": "app.js", "main": "app.js",
"dependencies": { "dependencies": {
"glsk-map-jssdk": "^0.1.1",
"glsx-applet-component": "^1.1.24", "glsx-applet-component": "^1.1.24",
"glsx-map-sdk": "^0.2.0",
"number-precision": "^1.6.0" "number-precision": "^1.6.0"
}, },
"devDependencies": {}, "devDependencies": {},
......
import { import {
equityApi equityApi
} from "../../../../api/api" } from "../../../../api/api"
import mapApi from '../../../../utils/mapapi'
const baseUrl = 'https://img02.glsx.com.cn/weapp/resource/equity-h5-new/mini/' const baseUrl = 'https://img02.glsx.com.cn/weapp/resource/equity-h5-new/mini/'
Page({ Page({
......
...@@ -93,14 +93,17 @@ Page({ ...@@ -93,14 +93,17 @@ Page({
img_version img_version
} = this.data } = this.data
const map = wx.createMapContext('map') const map = wx.createMapContext('map')
mapApi.translate([`${detail.beginGpsLat},${detail.beginGpsLon}`, `${detail.endGpsLat},${detail.endGpsLon}`], 1).then(({ mapApi.translate([
[detail.beginGpsLat, detail.beginGpsLon],
[detail.endGpsLat, detail.endGpsLon]
], 1).then(({
locations locations
}) => { }) => {
let markers = [] let markers = []
let points = [] let points = []
locations.map((e, index) => { locations.map((e, index) => {
let latitude = e.lat let latitude = e.y
let longitude = e.lng let longitude = e.x
markers.push({ markers.push({
iconPath: `${IMGURL}packageIndex/gps/${index == 0?'begin':'end'}.png?v=${img_version}`, iconPath: `${IMGURL}packageIndex/gps/${index == 0?'begin':'end'}.png?v=${img_version}`,
latitude, latitude,
......
...@@ -41,7 +41,7 @@ Page({ ...@@ -41,7 +41,7 @@ Page({
rows: [data] rows: [data]
}) => { }) => {
data.elements.map((e, index) => { data.elements.map((e, index) => {
let distance = Number((e.distance / 1000)).toFixed(2) let distance = e.distance.value ? Number((e.distance.value / 1000)).toFixed(2) : 0
this.setData({ this.setData({
[`merchantList[${index}].Distance`]: distance [`merchantList[${index}].Distance`]: distance
}) })
......
import { indexApi, mineApi } from "../../../../api/api"; import { indexApi, mineApi } from "../../../../api/api";
import mapApi from "../../../../utils/mapapi";
Page({ Page({
data: { data: {
obj: { obj: {
......
import { indexApi, mineApi } from "../../../../api/api"; import { indexApi, mineApi } from "../../../../api/api";
import mapApi from "../../../../utils/mapapi";
Page({ Page({
data: { data: {
desc: "", desc: "",
...@@ -105,7 +104,6 @@ Page({ ...@@ -105,7 +104,6 @@ Page({
store store
}); });
} }
// this.getLocationByIp();
this.getGHUserInfo(); this.getGHUserInfo();
}, },
getGHUserInfo() { getGHUserInfo() {
...@@ -118,21 +116,6 @@ Page({ ...@@ -118,21 +116,6 @@ Page({
} }
}); });
}, },
getLocationByIp() {
let storeCode = wx.$util.getStorageSync("srcm_shopmall_store_code");
if (storeCode) {
this.getStore({ storeCode });
} else {
mapApi
.getLocationByIp()
.then(({ city }) => {
this.getStore({ storeName: city });
})
.catch(() => {
this.getStore();
});
}
},
getStore(obj = {}) { getStore(obj = {}) {
indexApi.getGHStoreList({ pageNum: 1, ...obj }).then((data) => { indexApi.getGHStoreList({ pageNum: 1, ...obj }).then((data) => {
if (data.length) { if (data.length) {
......
...@@ -76,10 +76,12 @@ Page({ ...@@ -76,10 +76,12 @@ Page({
}) })
} else { } else {
mapApi.getLocationByIp().then(({ mapApi.getLocationByIp().then(({
city content: {
address_detail
}
}) => { }) => {
this.getStore({ this.getStore({
storeName: city storeName: address_detail.city
}) })
}).catch(() => { }).catch(() => {
this.getStore() this.getStore()
......
...@@ -335,26 +335,44 @@ Page({ ...@@ -335,26 +335,44 @@ Page({
}, },
openLocation(e) { openLocation(e) {
let { let {
item location,
} = e.currentTarget.dataset storeName,
if (item.location.latitude == '0.0') { address,
mapApi.geocoder(item.address).then(({ } = e.currentTarget.dataset.item
location if (location.latitude == '0.0') {
mapApi.geocoder(address).then(({
location: locat
}) => { }) => {
wx.openLocation({ mapApi.translate([
latitude: Number(location.lat), [locat.lat, locat.lng]
longitude: Number(location.lng), ], 5).then(res => {
name: item.storeName, let {
address: item.address x,
y
} = res[0]
wx.openLocation({
latitude: y,
longitude: x,
name: storeName,
address
})
}) })
}) })
return return
} }
wx.openLocation({ mapApi.translate([
latitude: Number(item.location.latitude), [location.latitude, location.longitude]
longitude: Number(item.location.longitude), ], 5).then(res => {
name: item.storeName, let {
address: item.address x,
y
} = res[0]
wx.openLocation({
latitude: y,
longitude: x,
name: storeName,
address
})
}) })
}, },
......
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
通话 通话
</view> </view>
</block> </block>
<block wx:if="{{merchantDetail.merchantAddress}}"> <block wx:if="{{merchantDetail.address}}">
<view class="item flex" bindtap="openLocation" data-item="{{merchantDetail}}"> <view class="item flex" bindtap="openLocation" data-item="{{merchantDetail}}">
<view class="sprite-icon icon-mine-gh-gps"></view> <view class="sprite-icon icon-mine-gh-gps"></view>
导航 导航
......
...@@ -9,6 +9,13 @@ ...@@ -9,6 +9,13 @@
"miniprogram": { "miniprogram": {
"list": [ "list": [
{ {
"name": "packageEquity/pages/commodity/list/list",
"pathName": "packageMine/pages/address/detail/detail",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "pages/tab/index/index", "name": "pages/tab/index/index",
"pathName": "pages/tab/index/index", "pathName": "pages/tab/index/index",
"query": "merchantId=44210895", "query": "merchantId=44210895",
......
import GlMap from 'glsx-map-sdk' import GlMap from 'glsk-map-jssdk'
export default new GlMap() export default new GlMap()
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!