window.location.href 截取 url 成数组

99 阅读1分钟
// var url = window.location.href;
var url = 'http://localhost:63342/appWeb/xtb-app/RemoteMap.html?point=POLYGON((103.582606028438 30.4699037630085,103.582557146421 30.4698077993192,103.582556551704 30.4697696615784,103.582613188237 30.4697583675745,103.582636438639 30.4697625503798,103.58264478386 30.4697911574964,103.582655513168 30.4698340674471,103.582654320041 30.4698531355608,103.58266624259 30.469873997834,103.5826626649 30.4698906811948,103.582606028438 30.4699037630085))&url=https://satellite-map.oss-cn-chengdu.aliyuncs.com/dayixian20230224/dayixian20230224/{z}/{x}/{y}.png';
var querys = url.substring(url.indexOf('?') + 1).split('&');
var result = [];
for (var i = 0; i < querys.length; i++) {
    var temp = querys[i].split('=');
    if (temp.length < 2) {
        result[temp[0]] = '';
    } else {
        result[temp[0]] = temp[1];
    }
}

console.log(result); //[point: 'POLYGON((103.582606028438 30.4699037630085,103.582…4698906811948,103.582606028438 30.4699037630085))', url: 'https://satellite-map.oss-cn-chengdu.aliyuncs.com/dayixian20230224/dayixian20230224/{z}/{x}/{y}.png']
var points = result['point'];
var mapUrl = result['url'];