﻿$(".maplist").click(function () {
    map.clearMap();
    var num = $(this).attr("iid").split(",");
    var title = $(this).attr("title");
    map = new AMap.Map('map', {
        resizeEnable: true,
        center: [num[0], num[1]],
        zoom: 15
    });

    marker = new AMap.Marker({
        position: new AMap.LngLat(num[0],num[1]),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
        title: title
    });

    map.add(marker);
});

$("#mapbtn").click(function () {
    if ($.trim($("#mapkey").val()) == "" || $.trim($("#mapkey").val()) =="搜索销售和设施") {
        layer.msg('请输入您要搜索的销售和设施关键词')
        return false;
    } else {
        $.ajax({
            type: "POST",
            url: "/AjaxFile/Member.ashx",
            async: false,
            data: {
                CallMethod: "Getmaplist",
                key: $("#mapkey").val()
            },
            success: function (data) {
                if (data.indexOf("暂无数据") == -1) {
                    $("#maplists").html(data);

                    $(".maplist").click(function () {
                        map.clearMap();
                        var num = $(this).attr("iid").split(",");
                        var title = $(this).attr("title");
                        map = new AMap.Map('map', {
                            resizeEnable: true,
                            center: [num[0], num[1]],
                            zoom: 15
                        });

                        marker = new AMap.Marker({
                            position: new AMap.LngLat(num[0], num[1]),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                            title: title
                        });

                        map.add(marker);
                    });
                } else {
                    $("#maplists").html("<li><a>暂无数据</a></li>");
                }
            }
        });
    }
});