index.vue
<template>
<view class="content">
<view>{{point.point}}</view>
<view>{{point.city +' '+ point.address + ' ' + point.name}}</view>
<button @click="chooseLocation">选择位置</button>
</view>
</template>
<script>
export default {
data() {
return {
point:{
point:{},
city:'',
address:'',
name:''
}
}
},
onLoad() {
},
methods: {
chooseLocation(){
uni.navigateTo({
url:"../choose-location/choose-location",
animationType:"slide-in-bottom",
})
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
map.nvue
<template>
<view class='container'>
<view :style="{height: height+'px'}"></view>
<uni-nav-bar leftIcon="closeempty" title="搜索位置" rightText="确定" :border="false" @clickLeft="navigateBack" @clickRight="bindConfirm"></uni-nav-bar>
<map id="map" ref="map" class="map"
:latitude="latitude"
:longitude="longitude"
:markers="markers"
:show-location="true"
:style="{width: '750rpx',height: windowHeight-height-300+'px'}"
@tap="mapTap">
</map>
<cover-image src="/static/icon-dingwei.png" class="dingwei" @click="getLocation"></cover-image>
<view class="search-box">
<scroll-view :scroll-y="true" class="scroll" @scrolltolower='refresh'>
<view class="list" v-for="(item, index) in list" :key="index" @click="bindPointClick(index)">
<view class="top">
<view class="left">
<view>
<text class="name">{{item.name}}</text>
</view>
<view>
<text class="detail">{{item.distance+'km|'+item.address}}</text>
</view>
</view>
<view v-if="item.checked">
<text class="hook">✔</text>
</view>
</view>
<view class="line"></view>
</view>
</scroll-view>
<view class="list">
<input class="input" type="text" placeholder="搜索地点" confirm-type="search" v-model="condition" @confirm="bindSearchClick"/>
</view>
</view>
</view>
</template>
<script>
import cityData from "@/utils/citys.js";
import * as turf from "@/utils/turf.min.js";
export default {
data() {
return {
sysInfo: null,
height:'',
windowHeight:'',
mapContext: null,
map: null,
searchObj: null,
searchCity:'',
latitude: '30',
longitude: '120',
myLocation:{},
myMarker:[],
pointMarker:[],
condition:'',
index:0,
list: [],
doMove: false,
}
},
onLoad() {
this.sysInfo = uni.getSystemInfoSync();
this.height = this.sysInfo.statusBarHeight;
this.windowHeight = this.sysInfo.windowHeight;
},
onReady() {
// 调用plus.map
this.mapContext = uni.createMapContext('map', this);
this.searchObj = new plus.maps.Search(this.mapContext);
let self = this;
this.searchObj.onPoiSearchComplete = function( state, result ){
console.log("onPoiSearchComplete: "+state+" , "+result.currentNumber);
let startPoint = turf.point([self.myLocation.longitude, self.myLocation.latitude]);
if ( state == 0 ) {
if ( result.currentNumber <= 0 ) {
console.log( "没有检索到结果" );
}else{
let list = result.poiList;
for (let i = 0; i < list.length; i++) {
let endPoint = turf.point([list[i].point.longitude, list[i].point.latitude]);
list[i].distance = turf.distance(startPoint, endPoint).toFixed(1);
}
self.list = self.list.concat(list);
if(self.list.length>0&&self.index==0){
self.list[0].checked = true;
let path = '';
let point = self.list[0].point;
if(self.doMove){
self.moveToLocation(point);
self.doMove = false;
}
}
console.log(list);
}
} else {
console.log( "检索失败" );
}
}
this.getLocation();
},
computed:{
searchDatas() {// 判断输入的是否为城市名
var searchData = []
for (let i = 0; i < cityData.length; i++) {
if (cityData[i]['cityName'].indexOf(this.condition) !== -1) {
searchData.push({
data: cityData[i],
name: cityData[i]['cityName']
})
}
}
return searchData
},
markers() {
return [...this.myMarker, ...this.pointMarker];
},
},
watch:{
condition(){ // 根据城市搜索poi点
this.index = 0;
this.list = [];
if(this.condition!=''){
if(this.searchDatas.length==1){
this.searchCity = this.searchDatas[0].data.cityName;
}
this.getPoiInCity(this.searchCity, this.condition);
}else{
setTimeout(()=>{
this.getLocation();
}, 500)
}
}
},
methods: {
navigateBack() {
uni.navigateBack({
delta:1
})
},
bindSearchClick() {
this.index = 0;
this.list = [];
this.doMove = true;
if(this.condition!=''){
if(this.searchDatas.length==1){
this.searchCity = this.searchDatas[0].data.cityName;
}
this.getPoiInCity(this.searchCity, this.condition);
}else{
this.getLocation();
}
},
bindConfirm() { // 确认按钮的方法,可自定义上一页所需参数
let point = {};
this.list.forEach(v => {
if(v.checked){
point = v;
}
})
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2].$vm;
prevPage.point = point;
uni.navigateBack({
delta:1
})
},
getLocation() { // 获取当前位置
let self = this;
this.index = 0;
this.list = [];
uni.getLocation({
type:"gcj02",
geocode:true,
success(res) {
console.log('getLocation:'+res.address.poiName)
self.longitude = res.longitude;
self.latitude = res.latitude;
self.myLocation = {
longitude: res.longitude,
latitude: res.latitude
}
self.doMove = true;
let point = new plus.maps.Point(res.longitude, res.latitude);
self.searchCity = res.address.city;
self.getNearbyPoi(point);
},
fail(res) {
console.log(res)
}
})
},
getNearbyPoi(point, index = 0){ // 获取附近poi
this.searchObj.poiSearchNearBy('', point, 1000, index);
},
getPoiInCity(city, key, index = 0){ // 获取指定城市、指定关键词搜索的poi
this.searchObj.poiSearchInCity(city, key, index);
},
refresh(){
this.index += 10;
if(this.condition){
this.getPoiInCity(this.searchCity, this.condition, this.index);
}else{
let point = new plus.maps.Point(this.longitude, this.latitude);
this.getNearbyPoi(point, this.index);
}
},
bindPointClick(index){
let point = this.list[index].point;
this.moveToLocation(point);
this.list.forEach((v,i)=>{
if(index != i){
v.checked = false;
}else{
v.checked = true;
}
})
},
mapTap(e){
this.list = [];
let point = { longitude: e.detail.longitude, latitude: e.detail.latitude };
this.moveToLocation(point);
let plusPoint = new plus.maps.Point(e.detail.longitude, e.detail.latitude)
this.getNearbyPoi(plusPoint);
},
moveToLocation(point){
let path = '';
if(this.sysInfo.platform == 'ios'){
path = '/static/location32.png';
}else{
path = '/static/location64.png';
}
this.longitude = point.longitude;
this.latitude = point.latitude;
this.pointMarker = [{
id: 'pointMarker',
longitude: point.longitude,
latitude: point.latitude,
iconPath: path
}];
},
}
}
</script>
<style>
.dingwei{
width: 80rpx;
height: 80rpx;
position: fixed;
bottom: 660rpx;
right: 30rpx;
}
.search-box{
width: 750rpx;
height: 630rpx;
position: fixed;
left: 0;
bottom: 0;
background-color: #FFFFFF;
z-index: 99;
border-radius: 20rpx;
padding-left: 20rpx;
padding-right: 20rpx;
padding-top: 30rpx;
}
.input{
width: 690rpx;
height: 80rpx;
padding-left: 20rpx;
line-height: 34rpx;
margin-top: 30rpx;
margin-left: 10rpx;
font-size: 26rpx;
background-color: #ececec;
border-radius: 8rpx;
}
.scroll{
height: 480rpx;
}
.list{
flex-direction: column;
}
.top{
flex-direction: row;
align-items: center;
}
.left{
width: 650rpx;
flex-direction: column;
}
.name{
font-size: 28rpx;
margin-bottom: 10rpx;
}
.hook{
font-size: 26rpx;
}
.detail{
font-size: 24rpx;
color: #666666;
margin-bottom: 10rpx;
}
.line{
height: 1rpx;
background-color: #CCCCCC;
margin-bottom: 14rpx;
}
</style>
components
utils
city.js
export default [{
'cityCode': '110100',
'cityName': '北京'
}, {
'cityCode': '120100',
'cityName': '天津'
}, {
'cityCode': '130100',
'cityName': '石家庄市'
}, {
'cityCode': '130200',
'cityName': '唐山市'
}, {
'cityCode': '130300',
'cityName': '秦皇岛市'
}, {
'cityCode': '130400',
'cityName': '邯郸市'
}, {
'cityCode': '130500',
'cityName': '邢台市'
}, {
'cityCode': '130600',
'cityName': '保定市'
}, {
'cityCode': '130700',
'cityName': '张家口市'
}, {
'cityCode': '130800',
'cityName': '承德市'
}, {
'cityCode': '130900',
'cityName': '沧州市'
}, {
'cityCode': '131000',
'cityName': '廊坊市'
}, {
'cityCode': '131100',
'cityName': '衡水市'
}, {
'cityCode': '140100',
'cityName': '太原市'
}, {
'cityCode': '140200',
'cityName': '大同市'
}, {
'cityCode': '140300',
'cityName': '阳泉市'
}, {
'cityCode': '140400',
'cityName': '长治市'
}, {
'cityCode': '140500',
'cityName': '晋城市'
}, {
'cityCode': '140600',
'cityName': '朔州市'
}, {
'cityCode': '140700',
'cityName': '晋中市'
}, {
'cityCode': '140800',
'cityName': '运城市'
}, {
'cityCode': '140900',
'cityName': '忻州市'
}, {
'cityCode': '141000',
'cityName': '临汾市'
}, {
'cityCode': '141100',
'cityName': '吕梁市'
}, {
'cityCode': '150100',
'cityName': '呼和浩特市'
}, {
'cityCode': '150200',
'cityName': '包头市'
}, {
'cityCode': '150300',
'cityName': '乌海市'
}, {
'cityCode': '150400',
'cityName': '赤峰市'
}, {
'cityCode': '150500',
'cityName': '通辽市'
}, {
'cityCode': '150600',
'cityName': '鄂尔多斯市'
}, {
'cityCode': '150700',
'cityName': '呼伦贝尔市'
}, {
'cityCode': '150800',
'cityName': '巴彦淖尔市'
}, {
'cityCode': '150900',
'cityName': '乌兰察布市'
}, {
'cityCode': '152200',
'cityName': '兴安盟'
}, {
'cityCode': '152500',
'cityName': '锡林郭勒盟'
}, {
'cityCode': '152900',
'cityName': '阿拉善盟'
}, {
'cityCode': '210100',
'cityName': '沈阳市'
}, {
'cityCode': '210200',
'cityName': '大连市'
}, {
'cityCode': '210300',
'cityName': '鞍山市'
}, {
'cityCode': '210400',
'cityName': '抚顺市'
}, {
'cityCode': '210500',
'cityName': '本溪市'
}, {
'cityCode': '210600',
'cityName': '丹东市'
}, {
'cityCode': '210700',
'cityName': '锦州市'
}, {
'cityCode': '210800',
'cityName': '营口市'
}, {
'cityCode': '210900',
'cityName': '阜新市'
}, {
'cityCode': '211000',
'cityName': '辽阳市'
}, {
'cityCode': '211100',
'cityName': '盘锦市'
}, {
'cityCode': '211200',
'cityName': '铁岭市'
}, {
'cityCode': '211300',
'cityName': '朝阳市'
}, {
'cityCode': '211400',
'cityName': '葫芦岛市'
}, {
'cityCode': '220100',
'cityName': '长春市'
}, {
'cityCode': '220200',
'cityName': '吉林市'
}, {
'cityCode': '220300',
'cityName': '四平市'
}, {
'cityCode': '220400',
'cityName': '辽源市'
}, {
'cityCode': '220500',
'cityName': '通化市'
}, {
'cityCode': '220600',
'cityName': '白山市'
}, {
'cityCode': '220700',
'cityName': '松原市'
}, {
'cityCode': '220800',
'cityName': '白城市'
}, {
'cityCode': '222400',
'cityName': '延边朝鲜族自治州'
}, {
'cityCode': '230100',
'cityName': '哈尔滨市'
}, {
'cityCode': '230200',
'cityName': '齐齐哈尔市'
}, {
'cityCode': '230300',
'cityName': '鸡西市'
}, {
'cityCode': '230400',
'cityName': '鹤岗市'
}, {
'cityCode': '230500',
'cityName': '双鸭山市'
}, {
'cityCode': '230600',
'cityName': '大庆市'
}, {
'cityCode': '230700',
'cityName': '伊春市'
}, {
'cityCode': '230800',
'cityName': '佳木斯市'
}, {
'cityCode': '230900',
'cityName': '七台河市'
}, {
'cityCode': '231000',
'cityName': '牡丹江市'
}, {
'cityCode': '231100',
'cityName': '黑河市'
}, {
'cityCode': '231200',
'cityName': '绥化市'
}, {
'cityCode': '232700',
'cityName': '大兴安岭地区'
}, {
'cityCode': '310100',
'cityName': '上海市'
}, {
'cityCode': '320100',
'cityName': '南京市'
}, {
'cityCode': '320200',
'cityName': '无锡市'
}, {
'cityCode': '320300',
'cityName': '徐州市'
}, {
'cityCode': '320400',
'cityName': '常州市'
}, {
'cityCode': '320500',
'cityName': '苏州市'
}, {
'cityCode': '320600',
'cityName': '南通市'
}, {
'cityCode': '320700',
'cityName': '连云港市'
}, {
'cityCode': '320800',
'cityName': '淮安市'
}, {
'cityCode': '320900',
'cityName': '盐城市'
}, {
'cityCode': '321000',
'cityName': '扬州市'
}, {
'cityCode': '321100',
'cityName': '镇江市'
}, {
'cityCode': '321200',
'cityName': '泰州市'
}, {
'cityCode': '321300',
'cityName': '宿迁市'
}, {
'cityCode': '330100',
'cityName': '杭州市'
}, {
'cityCode': '330200',
'cityName': '宁波市'
}, {
'cityCode': '330300',
'cityName': '温州市'
}, {
'cityCode': '330400',
'cityName': '嘉兴市'
}, {
'cityCode': '330500',
'cityName': '湖州市'
}, {
'cityCode': '330600',
'cityName': '绍兴市'
}, {
'cityCode': '330700',
'cityName': '金华市'
}, {
'cityCode': '330800',
'cityName': '衢州市'
}, {
'cityCode': '330900',
'cityName': '舟山市'
}, {
'cityCode': '331000',
'cityName': '台州市'
}, {
'cityCode': '331100',
'cityName': '丽水市'
}, {
'cityCode': '340100',
'cityName': '合肥市'
}, {
'cityCode': '340200',
'cityName': '芜湖市'
}, {
'cityCode': '340300',
'cityName': '蚌埠市'
}, {
'cityCode': '340400',
'cityName': '淮南市'
}, {
'cityCode': '340500',
'cityName': '马鞍山市'
}, {
'cityCode': '340600',
'cityName': '淮北市'
}, {
'cityCode': '340700',
'cityName': '铜陵市'
}, {
'cityCode': '340800',
'cityName': '安庆市'
}, {
'cityCode': '341000',
'cityName': '黄山市'
}, {
'cityCode': '341100',
'cityName': '滁州市'
}, {
'cityCode': '341200',
'cityName': '阜阳市'
}, {
'cityCode': '341300',
'cityName': '宿州市'
}, {
'cityCode': '341500',
'cityName': '六安市'
}, {
'cityCode': '341600',
'cityName': '亳州市'
}, {
'cityCode': '341700',
'cityName': '池州市'
}, {
'cityCode': '341800',
'cityName': '宣城市'
}, {
'cityCode': '350100',
'cityName': '福州市'
}, {
'cityCode': '350200',
'cityName': '厦门市'
}, {
'cityCode': '350300',
'cityName': '莆田市'
}, {
'cityCode': '350400',
'cityName': '三明市'
}, {
'cityCode': '350500',
'cityName': '泉州市'
}, {
'cityCode': '350600',
'cityName': '漳州市'
}, {
'cityCode': '350700',
'cityName': '南平市'
}, {
'cityCode': '350800',
'cityName': '龙岩市'
}, {
'cityCode': '350900',
'cityName': '宁德市'
}, {
'cityCode': '360100',
'cityName': '南昌市'
}, {
'cityCode': '360200',
'cityName': '景德镇市'
}, {
'cityCode': '360300',
'cityName': '萍乡市'
}, {
'cityCode': '360400',
'cityName': '九江市'
}, {
'cityCode': '360500',
'cityName': '新余市'
}, {
'cityCode': '360600',
'cityName': '鹰潭市'
}, {
'cityCode': '360700',
'cityName': '赣州市'
}, {
'cityCode': '360800',
'cityName': '吉安市'
}, {
'cityCode': '360900',
'cityName': '宜春市'
}, {
'cityCode': '361000',
'cityName': '抚州市'
}, {
'cityCode': '361100',
'cityName': '上饶市'
}, {
'cityCode': '370100',
'cityName': '济南市'
}, {
'cityCode': '370200',
'cityName': '青岛市'
}, {
'cityCode': '370300',
'cityName': '淄博市'
}, {
'cityCode': '370400',
'cityName': '枣庄市'
}, {
'cityCode': '370500',
'cityName': '东营市'
}, {
'cityCode': '370600',
'cityName': '烟台市'
}, {
'cityCode': '370700',
'cityName': '潍坊市'
}, {
'cityCode': '370800',
'cityName': '济宁市'
}, {
'cityCode': '370900',
'cityName': '泰安市'
}, {
'cityCode': '371000',
'cityName': '威海市'
}, {
'cityCode': '371100',
'cityName': '日照市'
}, {
'cityCode': '371200',
'cityName': '莱芜市'
}, {
'cityCode': '371300',
'cityName': '临沂市'
}, {
'cityCode': '371400',
'cityName': '德州市'
}, {
'cityCode': '371500',
'cityName': '聊城市'
}, {
'cityCode': '371600',
'cityName': '滨州市'
}, {
'cityCode': '371700',
'cityName': '菏泽市'
}, {
'cityCode': '410100',
'cityName': '郑州市'
}, {
'cityCode': '410200',
'cityName': '开封市'
}, {
'cityCode': '410300',
'cityName': '洛阳市'
}, {
'cityCode': '410400',
'cityName': '平顶山市'
}, {
'cityCode': '410500',
'cityName': '安阳市'
}, {
'cityCode': '410600',
'cityName': '鹤壁市'
}, {
'cityCode': '410700',
'cityName': '新乡市'
}, {
'cityCode': '410800',
'cityName': '焦作市'
}, {
'cityCode': '410900',
'cityName': '濮阳市'
}, {
'cityCode': '411000',
'cityName': '许昌市'
}, {
'cityCode': '411100',
'cityName': '漯河市'
}, {
'cityCode': '411200',
'cityName': '三门峡市'
}, {
'cityCode': '411300',
'cityName': '南阳市'
}, {
'cityCode': '411400',
'cityName': '商丘市'
}, {
'cityCode': '411500',
'cityName': '信阳市'
}, {
'cityCode': '411600',
'cityName': '周口市'
}, {
'cityCode': '411700',
'cityName': '驻马店市'
}, {
'cityCode': '419000',
'cityName': '省直辖县级行政区划'
}, {
'cityCode': '420100',
'cityName': '武汉市'
}, {
'cityCode': '420200',
'cityName': '黄石市'
}, {
'cityCode': '420300',
'cityName': '十堰市'
}, {
'cityCode': '420500',
'cityName': '宜昌市'
}, {
'cityCode': '420600',
'cityName': '襄阳市'
}, {
'cityCode': '420700',
'cityName': '鄂州市'
}, {
'cityCode': '420800',
'cityName': '荆门市'
}, {
'cityCode': '420900',
'cityName': '孝感市'
}, {
'cityCode': '421000',
'cityName': '荆州市'
}, {
'cityCode': '421100',
'cityName': '黄冈市'
}, {
'cityCode': '421200',
'cityName': '咸宁市'
}, {
'cityCode': '421300',
'cityName': '随州市'
}, {
'cityCode': '422800',
'cityName': '恩施土家族苗族自治州'
}, {
'cityCode': '429000',
'cityName': '省直辖县级行政区划'
}, {
'cityCode': '430100',
'cityName': '长沙市'
}, {
'cityCode': '430200',
'cityName': '株洲市'
}, {
'cityCode': '430300',
'cityName': '湘潭市'
}, {
'cityCode': '430400',
'cityName': '衡阳市'
}, {
'cityCode': '430500',
'cityName': '邵阳市'
}, {
'cityCode': '430600',
'cityName': '岳阳市'
}, {
'cityCode': '430700',
'cityName': '常德市'
}, {
'cityCode': '430800',
'cityName': '张家界市'
}, {
'cityCode': '430900',
'cityName': '益阳市'
}, {
'cityCode': '431000',
'cityName': '郴州市'
}, {
'cityCode': '431100',
'cityName': '永州市'
}, {
'cityCode': '431200',
'cityName': '怀化市'
}, {
'cityCode': '431300',
'cityName': '娄底市'
}, {
'cityCode': '433100',
'cityName': '湘西土家族苗族自治州'
}, {
'cityCode': '440100',
'cityName': '广州市'
}, {
'cityCode': '440200',
'cityName': '韶关市'
}, {
'cityCode': '440300',
'cityName': '深圳市'
}, {
'cityCode': '440400',
'cityName': '珠海市'
}, {
'cityCode': '440500',
'cityName': '汕头市'
}, {
'cityCode': '440600',
'cityName': '佛山市'
}, {
'cityCode': '440700',
'cityName': '江门市'
}, {
'cityCode': '440800',
'cityName': '湛江市'
}, {
'cityCode': '440900',
'cityName': '茂名市'
}, {
'cityCode': '441200',
'cityName': '肇庆市'
}, {
'cityCode': '441300',
'cityName': '惠州市'
}, {
'cityCode': '441400',
'cityName': '梅州市'
}, {
'cityCode': '441500',
'cityName': '汕尾市'
}, {
'cityCode': '441600',
'cityName': '河源市'
}, {
'cityCode': '441700',
'cityName': '阳江市'
}, {
'cityCode': '441800',
'cityName': '清远市'
}, {
'cityCode': '441900',
'cityName': '东莞市'
}, {
'cityCode': '442000',
'cityName': '中山市'
}, {
'cityCode': '445100',
'cityName': '潮州市'
}, {
'cityCode': '445200',
'cityName': '揭阳市'
}, {
'cityCode': '445300',
'cityName': '云浮市'
}, {
'cityCode': '450100',
'cityName': '南宁市'
}, {
'cityCode': '450200',
'cityName': '柳州市'
}, {
'cityCode': '450300',
'cityName': '桂林市'
}, {
'cityCode': '450400',
'cityName': '梧州市'
}, {
'cityCode': '450500',
'cityName': '北海市'
}, {
'cityCode': '450600',
'cityName': '防城港市'
}, {
'cityCode': '450700',
'cityName': '钦州市'
}, {
'cityCode': '450800',
'cityName': '贵港市'
}, {
'cityCode': '450900',
'cityName': '玉林市'
}, {
'cityCode': '451000',
'cityName': '百色市'
}, {
'cityCode': '451100',
'cityName': '贺州市'
}, {
'cityCode': '451200',
'cityName': '河池市'
}, {
'cityCode': '451300',
'cityName': '来宾市'
}, {
'cityCode': '451400',
'cityName': '崇左市'
}, {
'cityCode': '460100',
'cityName': '海口市'
}, {
'cityCode': '460200',
'cityName': '三亚市'
}, {
'cityCode': '460300',
'cityName': '三沙市'
}, {
'cityCode': '469000',
'cityName': '省直辖县级行政区划'
}, {
'cityCode': '500100',
'cityName': '重庆'
}, {
'cityCode': '510100',
'cityName': '成都市'
}, {
'cityCode': '510300',
'cityName': '自贡市'
}, {
'cityCode': '510400',
'cityName': '攀枝花市'
}, {
'cityCode': '510500',
'cityName': '泸州市'
}, {
'cityCode': '510600',
'cityName': '德阳市'
}, {
'cityCode': '510700',
'cityName': '绵阳市'
}, {
'cityCode': '510800',
'cityName': '广元市'
}, {
'cityCode': '510900',
'cityName': '遂宁市'
}, {
'cityCode': '511000',
'cityName': '内江市'
}, {
'cityCode': '511100',
'cityName': '乐山市'
}, {
'cityCode': '511300',
'cityName': '南充市'
}, {
'cityCode': '511400',
'cityName': '眉山市'
}, {
'cityCode': '511500',
'cityName': '宜宾市'
}, {
'cityCode': '511600',
'cityName': '广安市'
}, {
'cityCode': '511700',
'cityName': '达州市'
}, {
'cityCode': '511800',
'cityName': '雅安市'
}, {
'cityCode': '511900',
'cityName': '巴中市'
}, {
'cityCode': '512000',
'cityName': '资阳市'
}, {
'cityCode': '513200',
'cityName': '阿坝藏族羌族自治州'
}, {
'cityCode': '513300',
'cityName': '甘孜藏族自治州'
}, {
'cityCode': '513400',
'cityName': '凉山彝族自治州'
}, {
'cityCode': '520100',
'cityName': '贵阳市'
}, {
'cityCode': '520200',
'cityName': '六盘水市'
}, {
'cityCode': '520300',
'cityName': '遵义市'
}, {
'cityCode': '520400',
'cityName': '安顺市'
}, {
'cityCode': '520500',
'cityName': '毕节市'
}, {
'cityCode': '520600',
'cityName': '铜仁市'
}, {
'cityCode': '522300',
'cityName': '黔西南布依族苗族自治州'
}, {
'cityCode': '522600',
'cityName': '黔东南苗族侗族自治州'
}, {
'cityCode': '522700',
'cityName': '黔南布依族苗族自治州'
}, {
'cityCode': '530100',
'cityName': '昆明市'
}, {
'cityCode': '530300',
'cityName': '曲靖市'
}, {
'cityCode': '530400',
'cityName': '玉溪市'
}, {
'cityCode': '530500',
'cityName': '保山市'
}, {
'cityCode': '530600',
'cityName': '昭通市'
}, {
'cityCode': '530700',
'cityName': '丽江市'
}, {
'cityCode': '530800',
'cityName': '普洱市'
}, {
'cityCode': '530900',
'cityName': '临沧市'
}, {
'cityCode': '532300',
'cityName': '楚雄彝族自治州'
}, {
'cityCode': '532500',
'cityName': '红河哈尼族彝族自治州'
}, {
'cityCode': '532600',
'cityName': '文山壮族苗族自治州'
}, {
'cityCode': '532800',
'cityName': '西双版纳傣族自治州'
}, {
'cityCode': '532900',
'cityName': '大理白族自治州'
}, {
'cityCode': '533100',
'cityName': '德宏傣族景颇族自治州'
}, {
'cityCode': '533300',
'cityName': '怒江傈僳族自治州'
}, {
'cityCode': '533400',
'cityName': '迪庆藏族自治州'
}, {
'cityCode': '540100',
'cityName': '拉萨市'
}, {
'cityCode': '542100',
'cityName': '昌都地区'
}, {
'cityCode': '542200',
'cityName': '山南地区'
}, {
'cityCode': '542300',
'cityName': '日喀则地区'
}, {
'cityCode': '542400',
'cityName': '那曲地区'
}, {
'cityCode': '542500',
'cityName': '阿里地区'
}, {
'cityCode': '542600',
'cityName': '林芝地区'
}, {
'cityCode': '610100',
'cityName': '西安市'
}, {
'cityCode': '610200',
'cityName': '铜川市'
}, {
'cityCode': '610300',
'cityName': '宝鸡市'
}, {
'cityCode': '610400',
'cityName': '咸阳市'
}, {
'cityCode': '610500',
'cityName': '渭南市'
}, {
'cityCode': '610600',
'cityName': '延安市'
}, {
'cityCode': '610700',
'cityName': '汉中市'
}, {
'cityCode': '610800',
'cityName': '榆林市'
}, {
'cityCode': '610900',
'cityName': '安康市'
}, {
'cityCode': '611000',
'cityName': '商洛市'
}, {
'cityCode': '620100',
'cityName': '兰州市'
}, {
'cityCode': '620200',
'cityName': '嘉峪关市'
}, {
'cityCode': '620300',
'cityName': '金昌市'
}, {
'cityCode': '620400',
'cityName': '白银市'
}, {
'cityCode': '620500',
'cityName': '天水市'
}, {
'cityCode': '620600',
'cityName': '武威市'
}, {
'cityCode': '620700',
'cityName': '张掖市'
}, {
'cityCode': '620800',
'cityName': '平凉市'
}, {
'cityCode': '620900',
'cityName': '酒泉市'
}, {
'cityCode': '621000',
'cityName': '庆阳市'
}, {
'cityCode': '621100',
'cityName': '定西市'
}, {
'cityCode': '621200',
'cityName': '陇南市'
}, {
'cityCode': '622900',
'cityName': '临夏回族自治州'
}, {
'cityCode': '623000',
'cityName': '甘南藏族自治州'
}, {
'cityCode': '630100',
'cityName': '西宁市'
}, {
'cityCode': '630200',
'cityName': '海东市'
}, {
'cityCode': '632200',
'cityName': '海北藏族自治州'
}, {
'cityCode': '632300',
'cityName': '黄南藏族自治州'
}, {
'cityCode': '632500',
'cityName': '海南藏族自治州'
}, {
'cityCode': '632600',
'cityName': '果洛藏族自治州'
}, {
'cityCode': '632700',
'cityName': '玉树藏族自治州'
}, {
'cityCode': '632800',
'cityName': '海西蒙古族藏族自治州'
}, {
'cityCode': '640100',
'cityName': '银川市'
}, {
'cityCode': '640200',
'cityName': '石嘴山市'
}, {
'cityCode': '640300',
'cityName': '吴忠市'
}, {
'cityCode': '640400',
'cityName': '固原市'
}, {
'cityCode': '640500',
'cityName': '中卫市'
}, {
'cityCode': '650100',
'cityName': '乌鲁木齐市'
}, {
'cityCode': '650200',
'cityName': '克拉玛依市'
}, {
'cityCode': '652100',
'cityName': '吐鲁番地区'
}, {
'cityCode': '652200',
'cityName': '哈密地区'
}, {
'cityCode': '652300',
'cityName': '昌吉回族自治州'
}, {
'cityCode': '652700',
'cityName': '博尔塔拉蒙古自治州'
}, {
'cityCode': '652800',
'cityName': '巴音郭楞蒙古自治州'
}, {
'cityCode': '652900',
'cityName': '阿克苏地区'
}, {
'cityCode': '653000',
'cityName': '克孜勒苏柯尔克孜自治州'
}, {
'cityCode': '653100',
'cityName': '喀什地区'
}, {
'cityCode': '653200',
'cityName': '和田地区'
}, {
'cityCode': '654000',
'cityName': '伊犁哈萨克自治州'
}, {
'cityCode': '654200',
'cityName': '塔城地区'
}, {
'cityCode': '654300',
'cityName': '阿勒泰地区'
}, {
'cityCode': '659000',
'cityName': '自治区直辖县级行政区划'
}
]
turf.min.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.turf = {})));
}(this, (function (exports) { 'use strict';
/**
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
*/
var earthRadius = 6371008.8;
/**
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
*/
var factors = {
meters: earthRadius,
metres: earthRadius,
millimeters: earthRadius * 1000,
millimetres: earthRadius * 1000,
centimeters: earthRadius * 100,
centimetres: earthRadius * 100,
kilometers: earthRadius / 1000,
kilometres: earthRadius / 1000,
miles: earthRadius / 1609.344,
nauticalmiles: earthRadius / 1852,
inches: earthRadius * 39.370,
yards: earthRadius / 1.0936,
feet: earthRadius * 3.28084,
radians: 1,
degrees: earthRadius / 111325,
};
/**
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
*
* @name feature
* @param {Geometry} geometry input geometry
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a GeoJSON Feature
* @example
* var geometry = {
* "type": "Point",
* "coordinates": [110, 50]
* };
*
* var feature = turf.feature(geometry);
*
* //=feature
*/
function feature(geometry, properties, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var bbox = options.bbox;
var id = options.id;
// Validation
if (geometry === undefined) throw new Error('geometry is required');
if (properties && properties.constructor !== Object) throw new Error('properties must be an Object');
if (bbox) validateBBox(bbox);
if (id) validateId(id);
// Main
var feat = {type: 'Feature'};
if (id) feat.id = id;
if (bbox) feat.bbox = bbox;
feat.properties = properties || {};
feat.geometry = geometry;
return feat;
}
/**
* isNumber
*
* @param {*} num Number to validate
* @returns {boolean} true/false
* @example
* turf.isNumber(123)
* //=true
* turf.isNumber('foo')
* //=false
*/
function isNumber(num) {
return !isNaN(num) && num !== null && !Array.isArray(num);
}
/**
* isObject
*
* @param {*} input variable to validate
* @returns {boolean} true/false
* @example
* turf.isObject({elevation: 10})
* //=true
* turf.isObject('foo')
* //=false
*/
function isObject(input) {
return (!!input) && (input.constructor === Object);
}
/**
* Creates a {@link Point} {@link Feature} from a Position.
*
* @name point
* @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees)
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<Point>} a Point feature
* @example
* var point = turf.point([-75.343, 39.984]);
*
* //=point
*/
function point(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
if (coordinates.length < 2) throw new Error('coordinates must be at least 2 numbers long');
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) throw new Error('coordinates must contain numbers');
return feature({
type: 'Point',
coordinates: coordinates
}, properties, options);
}
/**
* Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
*
* @name getCoord
* @param {Array<number>|Geometry<Point>|Feature<Point>} obj Object
* @returns {Array<number>} coordinates
* @example
* var pt = turf.point([10, 10]);
*
* var coord = turf.getCoord(pt);
* //= [10, 10]
*/
function getCoord(obj) {
if (!obj) throw new Error('obj is required');
var coordinates = getCoords(obj);
// getCoord() must contain at least two numbers (Point)
if (coordinates.length > 1 && isNumber(coordinates[0]) && isNumber(coordinates[1])) {
return coordinates;
} else {
throw new Error('Coordinate is not a valid Point');
}
}
/**
* Unwrap coordinates from a Feature, Geometry Object or an Array of numbers
*
* @name getCoords
* @param {Array<number>|Geometry|Feature} obj Object
* @returns {Array<number>} coordinates
* @example
* var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);
*
* var coord = turf.getCoords(poly);
* //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
*/
function getCoords(obj) {
if (!obj) throw new Error('obj is required');
var coordinates;
// Array of numbers
if (obj.length) {
coordinates = obj;
// Geometry Object
} else if (obj.coordinates) {
coordinates = obj.coordinates;
// Feature
} else if (obj.geometry && obj.geometry.coordinates) {
coordinates = obj.geometry.coordinates;
}
// Checks if coordinates contains a number
if (coordinates) {
containsNumber(coordinates);
return coordinates;
}
throw new Error('No valid coordinates');
}
/**
* Checks if coordinates contains a number
*
* @name containsNumber
* @param {Array<any>} coordinates GeoJSON Coordinates
* @returns {boolean} true if Array contains a number
*/
function containsNumber(coordinates) {
if (coordinates.length > 1 && isNumber(coordinates[0]) && isNumber(coordinates[1])) {
return true;
}
if (Array.isArray(coordinates[0]) && coordinates[0].length) {
return containsNumber(coordinates[0]);
}
throw new Error('coordinates must only contain numbers');
}
/**
* Converts an angle in degrees to radians
*
* @name degreesToRadians
* @param {number} degrees angle between 0 and 360 degrees
* @returns {number} angle in radians
*/
function degreesToRadians(degrees) {
if (degrees === null || degrees === undefined) throw new Error('degrees is required');
var radians = degrees % 360;
return radians * Math.PI / 180;
}
/**
* Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @name radiansToLength
* @param {number} radians in radians across the sphere
* @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.
* @returns {number} distance
*/
function radiansToLength(radians, units) {
if (radians === undefined || radians === null) throw new Error('radians is required');
if (units && typeof units !== 'string') throw new Error('units must be a string');
var factor = factors[units || 'kilometers'];
if (!factor) throw new Error(units + ' units is invalid');
return radians * factor;
}
/**
* Calculates the distance between two {@link Point|points} in degrees, radians,
* miles, or kilometers. This uses the
* [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula)
* to account for global curvature.
*
* @name distance
* @param {Coord} from origin point
* @param {Coord} to destination point
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
* @returns {number} distance between the two points
* @example
* var from = turf.point([-75.343, 39.984]);
* var to = turf.point([-75.534, 39.123]);
* var options = {units: 'miles'};
*
* var distance = turf.distance(from, to, options);
*
* //addToMap
* var addToMap = [from, to];
* from.properties.distance = distance;
* to.properties.distance = distance;
*/
function distance(from, to, options) {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var units = options.units;
var coordinates1 = getCoord(from);
var coordinates2 = getCoord(to);
var dLat = degreesToRadians((coordinates2[1] - coordinates1[1]));
var dLon = degreesToRadians((coordinates2[0] - coordinates1[0]));
var lat1 = degreesToRadians(coordinates1[1]);
var lat2 = degreesToRadians(coordinates2[1]);
var a = Math.pow(Math.sin(dLat / 2), 2) +
Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
return radiansToLength(2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)), units);
}
exports.factors = factors;
exports.point = point;
exports.feature = feature;
exports.isNumber = isNumber;
exports.isObject = isObject;
exports.getCoord = getCoord;
exports.getCoords = getCoords;
exports.containsNumber = containsNumber;
exports.radiansToLength = radiansToLength;
exports.degreesToRadians = degreesToRadians;
exports.distance = distance;
Object.defineProperty(exports, '__esModule', { value: true });
})));