//
const mapdata = {
"hash": "HCPT-ZwhBypTu",
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"stroke-width": 1,
"fill":"#54bcbd",
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
145.00781,
-37.73391347772705
],
[
145.00603721971058,
-37.73405155146186
],
[
145.00433254716643,
-37.73446046808056
],
[
145.00276147569326,
-37.7351245174484
],
[
145.00138436980365,
-37.73601818695872
],
[
145.00025414707946,
-37.73710714098835
],
[
144.99941424516186,
-37.73834953924055
],
[
144.99889695188722,
-37.73969764348786
],
[
144.99872216282927,
-37.74109965114486
],
[
144.99889661424515,
-37.742501685356885
],
[
144.99941362128067,
-37.74384986522648
],
[
145.0002533319394,
-37.745092376655435
],
[
145.0013834875024,
-37.74618146418615
],
[
145.0027606605532,
-37.74707526719755
],
[
145.00433192328524,
-37.74773942974214
],
[
145.0060368820685,
-37.74814842198313
],
[
145.00781,
-37.74828652227296
],
[
145.0095831179315,
-37.74814842198313
],
[
145.01128807671475,
-37.74773942974214
],
[
145.0128593394468,
-37.74707526719755
],
[
145.0142365124976,
-37.74618146418615
],
[
145.0153666680606,
-37.745092376655435
],
[
145.01620637871935,
-37.74384986522648
],
[
145.01672338575486,
-37.742501685356885
],
[
145.01689783717075,
-37.74109965114486
],
[
145.0167230481128,
-37.73969764348786
],
[
145.01620575483815,
-37.73834953924055
],
[
145.01536585292055,
-37.73710714098835
],
[
145.01423563019637,
-37.73601818695872
],
[
145.01285852430675,
-37.7351245174484
],
[
145.01128745283356,
-37.73446046808056
],
[
145.0095827802894,
-37.73405155146186
],
[
145.00781,
-37.73391347772705
]
]
]
}
}
]
}
Page({
/**
* 页面的初始数据
*/
data: {
scale:10,
latitude: "-37.73391347772705",
longitude: "145.00781",
polygons: [],
markers:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var polygons=[]
let markers=[]
mapdata.features.map((item,index)=>{
var properties=item.properties
var coordinates=item.geometry.coordinates[0]
var obj={}
obj.points=[]
let total=[];
let BbOX=[]
let latitude=[]
let longitude=[]
coordinates.map((item,index)=>{
var points={}
points.longitude=item[0]
points.latitude=item[1]
latitude.push(item[1])
longitude.push(item[0])
obj.points.push(points);
})
let lat_sort= latitude.sort((a,b)=>{
return a-b
})
let lng_sort= longitude.sort((a,b)=>{
return a-b
})
let lat={
min:latitude[0],
max:lat_sort[lat_sort.length-1]
}
let lng={
min:lng_sort[0],
max:lng_sort[lng_sort.length-1]
}
let lat1=(lat_sort[0]+lat_sort[lat_sort.length-1])/2
let lng1=(lng_sort[0]+lng_sort[lng_sort.length-1])/2
//("min",min,"max",max)
obj.fillColor= properties.fill,
obj.strokeColor= properties.stroke,
obj.strokeWidth= 2,
obj.zIndex=100
obj.properties=properties
markers.push({
iconPath: '/img/',
id: index,
latitude: lat1,
longitude: lng1,
width: 20,
height: 20,
properties:properties,
"aria-label":"lot 01",
alpha:0.1,
callout:{//不适用自定义气泡的东西,在这里面写样式和内容
content:properties.name,
textAlign:"center",
color:"#000",
borderWidth:0,
bgColor:'rgba(0,0,0,0)',//背景颜色,可使用rgba
anchorY:30,
fontSize:12,
display:"ALWAYS",
},
// customCallout: {
// anchorY: 10,
// anchorX: 0,
// display: 'BYCLICK',
// }
})
console.log("obj",obj);
polygons.push(obj);
})
this.setData({
polygons:polygons,
list:polygons,
markers:markers
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
bindtapmap:function(e){
// ("bindtapmap",e)
// let pos=
// let lat=
// let lng=
// var list=
// var polygons=
// let i=0
// ((item,index)=>{
// let Bbox=
// let min=
// let max=
// if((> && >) && (<= && <=) ){
// ("aaaa",item)
// ="#ff"+i+i+"00"
// ="#00ff00"
// =3
// polygons[index]=item
// i=i+5
// }
// })
// ({
// polygons:polygons
// })
},
bindmarkertap:function(e){
console.log("bindmarkertap",e,e.detail);
let markersid=e.detail.markerId
let list=this.data.list
let polygons=this.data.polygons
let current=list[markersid]
current.fillColor="#ff0000"
polygons[markersid]=current
this.setData({
shownMapModalProject:true,
currentProject:this.data.markers[markersid].properties,
//polygons:polygons
})
},
regionchange:function (params) {
console.log("regionchange",params)
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
//二维数组排序
const orderBy = (arr, props, orders) =>
[...arr].sort((a, b) =>
props.reduce((acc, prop, i) => {
if (acc === 0) {
const [p1, p2] = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]];
acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0;
}
return acc;
}, 0)
);
//用法:
// const users = [
// { name: 'fred', age: 48 },
// { name: 'barney', age: 36 },
// { name: 'fred', age: 40 },
// { name: 'barney', age: 34 }
// ];
// orderBy(users, ['name', 'age'], ['asc', 'desc']); // [{name: 'barney', age: 36}, {name: 'barney', age: 34}, {name: 'fred', age: 48}, {name: 'fred', age: 40}]
// orderBy(users, ['name', 'age']); // [{name: 'barney', age: 34}, {name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]