183 lines
4.4 KiB
JavaScript
183 lines
4.4 KiB
JavaScript
|
|
"use strict";
|
||
|
|
const common_vendor = require("../common/vendor.js");
|
||
|
|
const utils_tools = require("./tools.js");
|
||
|
|
const utils_api = require("./api.js");
|
||
|
|
const sdkKey = "BECBZ-EJIEQ-LUU5N-B5ISQ-3TLMZ-BXFLG";
|
||
|
|
const getMap = (mapid, instance) => {
|
||
|
|
return common_vendor.index.createMapContext(mapid, {
|
||
|
|
this: instance.proxy
|
||
|
|
});
|
||
|
|
};
|
||
|
|
const getLoalcation = (oMap, success, fail) => {
|
||
|
|
common_vendor.index.getLocation({
|
||
|
|
type: "gcj02",
|
||
|
|
// 返回可以用于 wx.openLocation 的经纬度
|
||
|
|
geocode: true,
|
||
|
|
success(res) {
|
||
|
|
const {
|
||
|
|
latitude,
|
||
|
|
longitude
|
||
|
|
} = res;
|
||
|
|
moveToLocation(oMap, longitude, latitude);
|
||
|
|
if (success)
|
||
|
|
success({
|
||
|
|
latitude,
|
||
|
|
longitude
|
||
|
|
});
|
||
|
|
},
|
||
|
|
fail(res) {
|
||
|
|
if (fail)
|
||
|
|
fail(res);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
};
|
||
|
|
const reverseGeocoder = (qqmapsdk, longitude, latitude, success, fail) => {
|
||
|
|
qqmapsdk.reverseGeocoder({
|
||
|
|
location: {
|
||
|
|
latitude,
|
||
|
|
longitude
|
||
|
|
},
|
||
|
|
success: (res) => {
|
||
|
|
if (success)
|
||
|
|
success(res.result);
|
||
|
|
},
|
||
|
|
fail: (res) => {
|
||
|
|
if (fail)
|
||
|
|
success(fail);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
};
|
||
|
|
const addMarker = (id, longitude, latitude, icon) => {
|
||
|
|
return {
|
||
|
|
id,
|
||
|
|
latitude,
|
||
|
|
longitude,
|
||
|
|
width: 30,
|
||
|
|
height: 30,
|
||
|
|
zIndex: "100",
|
||
|
|
iconPath: "/static/map/" + icon
|
||
|
|
};
|
||
|
|
};
|
||
|
|
const addPolygon = (scolor, fcolor, arrPolygonsPoits) => {
|
||
|
|
return {
|
||
|
|
points: arrPolygonsPoits,
|
||
|
|
fillColor: fcolor,
|
||
|
|
strokeWidth: 3,
|
||
|
|
strokeColor: scolor,
|
||
|
|
zIndex: 11
|
||
|
|
};
|
||
|
|
};
|
||
|
|
const addCirle = (scolor, fcolor, longitude, latitude, radius) => {
|
||
|
|
return {
|
||
|
|
latitude,
|
||
|
|
longitude,
|
||
|
|
radius,
|
||
|
|
color: scolor,
|
||
|
|
fillColor: fcolor,
|
||
|
|
strokeWidth: 3
|
||
|
|
};
|
||
|
|
};
|
||
|
|
const moveToLocation = (oMap, longitude, latitude) => {
|
||
|
|
const point = {
|
||
|
|
latitude,
|
||
|
|
longitude
|
||
|
|
};
|
||
|
|
oMap.moveToLocation(point);
|
||
|
|
};
|
||
|
|
const getRegionData = (arrRegionID, callback) => {
|
||
|
|
if (!arrRegionID || arrRegionID.length == 0)
|
||
|
|
return;
|
||
|
|
const arrMethods = [];
|
||
|
|
arrRegionID.map((regionId) => {
|
||
|
|
const params = {
|
||
|
|
regionId
|
||
|
|
};
|
||
|
|
arrMethods.push(utils_api.callOperateApi("ebikeRegion/getRegion", params, "get"));
|
||
|
|
});
|
||
|
|
Promise.all(arrMethods).then((res) => {
|
||
|
|
const arrCircles = [];
|
||
|
|
const arrPolygons = [];
|
||
|
|
const arrData = [];
|
||
|
|
res.map((item) => {
|
||
|
|
const {
|
||
|
|
code,
|
||
|
|
message,
|
||
|
|
data: arrRegion
|
||
|
|
} = item;
|
||
|
|
if (code != 200)
|
||
|
|
return;
|
||
|
|
arrRegion.map((data) => {
|
||
|
|
const {
|
||
|
|
regionId,
|
||
|
|
shapeType,
|
||
|
|
radius,
|
||
|
|
points
|
||
|
|
} = data;
|
||
|
|
arrData.push(data);
|
||
|
|
const scolor = "#58d4c0";
|
||
|
|
const fcolor = "#c1f5f1";
|
||
|
|
if (shapeType == 1) {
|
||
|
|
const {
|
||
|
|
longitude: lng,
|
||
|
|
latitude: lat
|
||
|
|
} = points[0];
|
||
|
|
arrCircles.push(addCirle(scolor, fcolor, lng, lat, radius));
|
||
|
|
} else if (shapeType == 2) {
|
||
|
|
const arrPoint = points.map((p) => {
|
||
|
|
return {
|
||
|
|
longitude: p.longitude,
|
||
|
|
latitude: p.latitude
|
||
|
|
};
|
||
|
|
});
|
||
|
|
arrPolygons.push(addPolygon(scolor, fcolor, arrPoint));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
if (callback)
|
||
|
|
callback({
|
||
|
|
arrData,
|
||
|
|
arrCircles,
|
||
|
|
arrPolygons
|
||
|
|
});
|
||
|
|
});
|
||
|
|
};
|
||
|
|
const getBikeData = (arrRegionID, callback) => {
|
||
|
|
if (!arrRegionID || arrRegionID.length == 0)
|
||
|
|
return;
|
||
|
|
const arrMethods = [];
|
||
|
|
arrRegionID.map((regionId) => {
|
||
|
|
const params = {
|
||
|
|
regionId
|
||
|
|
};
|
||
|
|
arrMethods.push(utils_api.callOperateApi("ebikeRegion/getOperationBike", params, "get"));
|
||
|
|
});
|
||
|
|
Promise.all(arrMethods).then((arrRes) => {
|
||
|
|
const arrPoints = [];
|
||
|
|
const arrData = [];
|
||
|
|
arrRes.map((res) => {
|
||
|
|
const { code, message, data } = res;
|
||
|
|
if (code != 200) {
|
||
|
|
utils_tools.showModelMessage(message);
|
||
|
|
} else {
|
||
|
|
data.map((item) => {
|
||
|
|
const { bikeId, longitude, latitude, state } = item;
|
||
|
|
const id = arrPoints.length;
|
||
|
|
let icon = "bike.png";
|
||
|
|
arrPoints.push(addMarker(id, longitude, latitude, icon));
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
callback({ arrData, arrPoints });
|
||
|
|
});
|
||
|
|
};
|
||
|
|
exports.addCirle = addCirle;
|
||
|
|
exports.addMarker = addMarker;
|
||
|
|
exports.addPolygon = addPolygon;
|
||
|
|
exports.getBikeData = getBikeData;
|
||
|
|
exports.getLoalcation = getLoalcation;
|
||
|
|
exports.getMap = getMap;
|
||
|
|
exports.getRegionData = getRegionData;
|
||
|
|
exports.reverseGeocoder = reverseGeocoder;
|
||
|
|
exports.sdkKey = sdkKey;
|
||
|
|
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/map.js.map
|