Pu Zhibing
2024-12-13 73b750200f25df08aa64124da49e7461f9de6653
ManagementNTTravel/guns-admin/src/main/webapp/static/modular/system/tOpenCity/tOpenCity_info.js
@@ -342,22 +342,29 @@
            return;
        }
    }
    var lon = $("#longitude").val();
    var lat = $("#latitude").val();
    var lon = $("#lon").val();
    var lat = $("#lat").val();
    var lonAndLat = "("+lon+","+lat+")";
    var str = '<tr class="siteClass">' +
        '<td><input type="hidden" id="busId" name="busId" value="0">' +
        '<input type="hidden" id="time" name="time" value="'+getNowFormatDate()+'">' + getNowFormatDate() + '</td>' +
        '<td><input type="hidden" id="name" name="name" value="'+siteName+'">' + siteName + '</td>' +
        '<td><input type="hidden" id="lonAndLat" name="lonAndLat" value="'+lonAndLat+'">' + lonAndLat + '</td>' +
        '<td><input type="hidden" name="name" value="'+siteName+'">' + // 保留隐藏输入以存储原始值
        '<input type="text" class="editable-name" value="'+siteName+'" onchange="updateHiddenInput(this)"> ' + // 添加可编辑输入
        '</td>' +        '<td><input type="hidden" id="lonAndLat" name="lonAndLat" value="'+lonAndLat+'">' + lonAndLat + '</td>' +
        '<td><input type="hidden" id="siteType" name="siteType" value="'+type+'">' + siteType + '</td>' +
        '<td><button onclick="deleteSub(this)">移除</button></td></tr>';
    $("#site").append(str);
}
function updateHiddenInput(inputElement) {
    var hiddenInput = inputElement.previousElementSibling; // 假设可编辑输入后面紧跟着隐藏输入
    hiddenInput.value = inputElement.value; // 当可编辑输入的值改变时,更新隐藏输入的值
}
function deleteSub(e) {
    $(e).parent().parent().remove();
}
/*
//获取当前时间,格式YYYY-MM-DD
function getNowFormatDate() {
    var date = new Date();
@@ -470,4 +477,206 @@
            }
        });
    })
}
}*/
//起点地图加载
var marker, map = new AMap.Map("container", {
    resizeEnable: true,
    zoom: 15,
    zooms: [3, 20]
}); //定位标注当前位置
/*map.plugin('AMap.Geolocation', function () {
    geolocation = new AMap.Geolocation({
        enableHighAccuracy: true, //是否使用高精度定位,默认:true
        timeout: 10000, //超过10秒后停止定位,默认:无穷大
        maximumAge: 0, //定位结果缓存0毫秒,默认:0
        convert: true, //自动偏移坐标,偏移后的坐标为高德坐标,默认:true
        showButton: true, //显示定位按钮,默认:true
        showMarker: true, //定位成功后在定位到的位置显示点标记,默认:true
        showCircle: true, //定位成功后用圆圈表示定位精度范围,默认:true
        panToLocation: true, //定位成功后将定位到的位置作为地图中心点,默认:true
        buttonPosition: 'LB', //定位按钮的停靠位置  LB左下角、  RB右下角
        buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
        zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
    });
    function onComplete(data) {
        var str = [];
        city = data.addressComponent.citycode;
        str.push('定位结果:' + data.position);
        str.push('定位类别:' + data.location_type);
        if (data.accuracy) {
            str.push('精度:' + data.accuracy + ' 米');
        }
        //如为IP精确定位结果则没有精度信息
        str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'));
        var lnglatXY = [data.position.getLng(), data.position.getLat()];
        //地图上所标点的坐标
        AMap.service('AMap.Geocoder', function () {
            //回调函数
            geocoder = new AMap.Geocoder({});
            geocoder.getAddress(lnglatXY, function (status, result) {
                if (status === 'complete' && result.info === 'OK') {
//获得了有效的地址信息:                    //即,result.regeocode.formattedAddress
//                     console.log(result.regeocode.formattedAddress);
                    var address = result.regeocode.formattedAddress;
                    str.push('详细地址:' + address);
// todo 不弹出信息框
// alert(str.join(' | '));
                } else {
// alert(str.join(' | ')); //获取地址失败
                }
            });
        })
} //解析定位错误信息
function onError(data) {
    alert('定位失败,原因:' + data.message);
}
    map.addControl(geolocation);
    geolocation.getCurrentPosition()
    AMap.event.addListener(geolocation, 'complete', onComplete);
//返回定位信息
    AMap.event.addListener(geolocation, 'error', onError);
    //返回定位出错信息
}); //解析定位结果
*/
var city;
map.on('click', function (e) {
    if (marker != null) {
        marker.setMap(null);
    }
//添加标记点
    console.log(e.lnglat.getLng())
    console.log(e.lnglat.getLat())
    $("#lon").val(e.lnglat.getLng());
    $("#lat").val(e.lnglat.getLat());
    marker = new AMap.Marker({
        map: map,
        position: new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat()),   // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
    });
    regeoCode(e.lnglat.getLng(), e.lnglat.getLat());
});
var infoWindow = new AMap.InfoWindow({
    autoMove: true,
    offset: {
        x: 0,
        y: -30
    }
}); //回调函数
//根据经纬度获取详细地址
function regeoCode(lon, lat) {
    var lnglat = [];
    lnglat.push(lon);
    lnglat.push(lat);
    map.clearMap()
    map.add(marker);
    marker.setPosition(lnglat);
    AMap.service('AMap.Geocoder', function () {
        geocoder = new AMap.Geocoder({});
        geocoder.getAddress(lnglat, function (status, result) {
            if (status === 'complete' && result.regeocode) {
                var address = result.regeocode.formattedAddress;
                $("#address").val(address);
            } else {
                Feng.error('根据经纬度查询地址失败')
            }
            var data = {
                "name": result.regeocode.addressComponent.neighborhood,
                "location": {
                    "lat": lat,
                    "lng": lon
                },
                "address": address,
                "tel": "",
                "type": result.regeocode.addressComponent.neighborhoodType
            };
            // infoWindow.setContent(createContent(data));
            infoWindow.open(map, marker.getPosition());
        });
    })
}
//输入搜索点信息
var autoOptions = {
    city: city, //在规定城市搜索、默认全国
    input: "address"
};
var auto = new AMap.Autocomplete(autoOptions);
var placeSearch = new AMap.PlaceSearch({
    pageSize: 5, // 单页显示结果条数
    pageIndex: 1, // 页码
    children: 0, //不展示子节点数据
    city: city, // 兴趣点城市
    citylimit: true, //是否强制限制在设置的城市内搜索
    panel: "panel", // 结果列表将在此容器中进行展示。
    autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
    extensions: 'base', //返回基本地址信息  */
    map: map // 展现结果的地图实例
}); //构造地点查询类
AMap.event.addListener(auto, "select", select); //注册监听,当选中某条记录时会触发
function select(e) {
    console.log("============>e")
    console.log(e)
    placeSearch.setCity(e.poi.adcode);
    placeSearch.search(e.poi.name); //关键字查询查询        //设置搜索位置定点标注
    $("#lon").val(e.poi.location.lng);
    $("#lat").val(e.poi.location.lat);
    marker = new AMap.Marker({
        map: map,
        position: new AMap.LngLat(e.poi.location.lng, e.poi.location.lat),   // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
    });
    regeoCode(e.poi.location.lng, e.poi.location.lat);
    /* if (e.poi && e.poi.location) {
         map.setZoom(15);
         map.setCenter(e.poi.location);
         var id = e.poi.id; //详情查询
         placeSearch.getDetails(id, function (status, result) {
             if (status === 'complete' && result.info === 'OK') {
                 console.log("result-------------->")
                 console.log(result)
                 placeSearch_CallBack(result);
             }
         });
     }*/
}
function placeSearch_CallBack(data) {
    if (marker != null) {
        marker.setMap(null);
    }
    var poiArr = data.poiList.pois; //添加marker
    marker = new AMap.Marker({
        map: map,
        position: poiArr[0].location
    });
    map.add(marker);
    marker.setPosition(marker.getPosition());
    // infoWindow.setContent(createContent(poiArr[0]));
    infoWindow.open(map, marker.getPosition());
}
function createContent(poi) {
    console.log(poi);
//信息窗体内容
    $("#address").val(poi.address);
    $("#lon").val(poi.location.lng);
    $("#lat").val(poi.location.lat);
    var s = [];
    s.push("<b>名称:" + poi.name + "</b>");
    s.push("地址:" + poi.address);
    s.push("电话:" + poi.tel);
    s.push("类型:" + poi.type);
    return s.join("<br>");
}