"use strict";

function addMarker(data) {
    let {location, nickname} = data;
    var marker = new google.maps.Marker({
        position: location,
        map: map,
        title: nickname
    });
    addInfoWindow(data, marker);
}

function addInfoWindow(data, marker) {
    var infowindow = new google.maps.InfoWindow({
        content: getInfoContent(data)
    });
    marker.addListener('click', function () {
        infowindow.open(map, marker);
    });
}

function getInfoContent(data) {
    let {address, forum, nickname, username} = data;
    var forumContent;
    if (forum === "") {
        forumContent = "";
    } else {
        forumContent = `
        传递报告:<a href="https://bgm.tv/group/topic/${forum}" target="_blank">https://bgm.tv/group/topic/${forum}</a>
        `;
    }
    return `
    <a href="https://bgm.tv/user/${username}" target="_blank">${nickname}</a>&nbsp;<small class="grey">@${username}</small><br>
    位置:${address}<br>
    ${forumContent}
    `;
}

function addLine(path, lineSymbol, map) {

}

function mapCallBack(data) {
    var current = data.current,
        route = data.route,
        undetermin = data.undetermin,
        map, statContent;
    window.map = new google.maps.Map(document.getElementById('map-content'), {
        center: { lat: 34.2596292, lng: 108.6870192 }, // 第一站 : 西安
        zoom: 5
    });
    undetermin.forEach(function (data) {
        addMarker(data);
    });
    for (var i = 0; i < route.length; i++) {
        addMarker(route[i]);
        // #stat content

        // addLine

    }
}

function initMap() {
    var request = new XMLHttpRequest(),
        dataurl = "assets/data_convert.json",
        callback = mapCallBack;
    request.open('GET', dataurl, true);
    request.onload = function () {
        if (request.status >= 200 && request.status < 400) {
            callback.call(this, JSON.parse(request.responseText));
        } else {
            alert("500啦，按下F5吧~");
        }
    };
    request.onerror = function () {
        alert("请求超时啦，按下F5吧~");
    };
    request.send();
}
@@ -42,46 +42,8 @@
  %7B%0D%0A
-    let %7Blocation, nickname%7D = data;%0D%0A
     
@@ -99,16 +99,21 @@
 sition: 
+data.
 location
@@ -127,42 +127,47 @@
     
-map: map,%0D%0A        title: nickname
+title: data.nickname,%0D%0A        map: map
 %0D%0A  
@@ -492,38 +492,108 @@
     
-let %7Baddress, forum, nickname,
+var address = data.address,%0D%0A        forum = data.forum,%0D%0A        nickname = data.nickname,%0D%0A       
  use
@@ -601,26 +601,34 @@
 name
-%7D
  = data
-;
+.username,
 %0D%0A    
-var
+   
  for
@@ -733,19 +733,9 @@
 t = 
-%60%0D%0A        
+'
 %E4%BC%A0%E9%80%92%E6%8A%A5%E5%91%8A
@@ -771,24 +771,42 @@
 p/topic/
-$%7B
+' + 
 forum
-%7D
+%0D%0A            + '
 %22 target
@@ -846,31 +846,26 @@
 pic/
-$%7B
+' + 
 forum
-%7D%3C/a%3E%0D%0A        %60
+ + '%3C/a%3E'
 ;%0D%0A 
@@ -885,15 +885,9 @@
 urn 
-%60%0D%0A    
+'
 %3Ca h
@@ -911,26 +911,28 @@
 tv/user/
-$%7B
+' + 
 username
 %7D%22 targe
@@ -923,17 +923,29 @@
 username
-%7D
+%0D%0A        + '
 %22 target
@@ -958,18 +958,20 @@
 nk%22%3E
-$%7B
+' + 
 nickname
 %7D%3C/a
@@ -966,17 +966,20 @@
 nickname
-%7D
+ + '
 %3C/a%3E&nbs
@@ -1005,18 +1005,29 @@
 y%22%3E@
-$%7B
+'%0D%0A        + 
 username
 %7D%3C/s
@@ -1022,17 +1022,20 @@
 username
-%7D
+ + '
 %3C/small%3E
@@ -1042,39 +1042,43 @@
 %3Cbr%3E
+%E4%BD%8D%E7%BD%AE:'
 %0D%0A    
-%E4%BD%8D%E7%BD%AE:$%7B
+    + 
 address
-%7D%3Cbr%3E%0D%0A    $%7B
+ + '%3Cbr%3E' + 
 foru
@@ -1089,16 +1089,8 @@
 tent
-%7D%0D%0A    %60
 ;%0D%0A%7D

convert to ES5