203 lines
6.0 KiB
Plaintext
203 lines
6.0 KiB
Plaintext
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||
pageEncoding="UTF-8"%>
|
||
<script type="text/javascript">
|
||
var equipmentName='${equipmentName}';
|
||
//alert("equipmentName value is:"+equipmentName);
|
||
var lng='${lng}';
|
||
//alert("lng value is:"+lng);
|
||
var lat='${lat}';
|
||
//alert("lat value is:"+lat);
|
||
var companyName='${companyName}';
|
||
//alert("companyName value is:"+companyName);
|
||
|
||
// 创建地图实例
|
||
var map = new BMap.Map("container", {
|
||
minZoom : 18,
|
||
maxZoom : 19
|
||
});
|
||
|
||
// 创建点坐标
|
||
//(珠海市大概经纬度)113.58271881713522, 22.271476394207497
|
||
//(上海市大概经纬度)121.43208992029295, 31.174275468915532
|
||
//我的经纬度 121.48789949,31.24916171
|
||
var point='';
|
||
if(''!=lng || ''!=lat){
|
||
point = new BMap.Point(lng, lat);
|
||
}else{
|
||
point = new BMap.Point(119.982345,31.800048);
|
||
}
|
||
//var point = new BMap.Point(113.58271881713522, 22.271476394207497);
|
||
// 初始化地图,设置中心点坐标和地图级别
|
||
map.centerAndZoom(point, 10);
|
||
//添加地图类型控件
|
||
map.addControl(new BMap.MapTypeControl({
|
||
mapTypes : [ BMAP_NORMAL_MAP, BMAP_HYBRID_MAP ]
|
||
}));
|
||
map.setCurrentCity("常州"); // 设置地图显示的城市 此项是必须设置的
|
||
|
||
|
||
// 添加带有定位的导航控件
|
||
var navigationControl = new BMap.NavigationControl({
|
||
// 靠左上角位置
|
||
anchor : BMAP_ANCHOR_TOP_LEFT,
|
||
// LARGE类型
|
||
type : BMAP_NAVIGATION_CONTROL_LARGE,
|
||
// 启用显示定位(定位功能不稳定,时好时坏,大概是没有充值将就着用)
|
||
enableGeolocation : true
|
||
});
|
||
map.addControl(navigationControl);
|
||
|
||
/* 备注:暂时不用 (定位功能不稳定,时好时坏,大概是没有充值将就着用)
|
||
// 添加定位控件
|
||
var geolocationControl = new BMap.GeolocationControl();
|
||
geolocationControl.addEventListener("locationSuccess", function(e) {
|
||
// 定位成功事件
|
||
var address = '';
|
||
address += e.addressComponent.province;
|
||
address += e.addressComponent.city;
|
||
address += e.addressComponent.district;
|
||
address += e.addressComponent.street;
|
||
address += e.addressComponent.streetNumber;
|
||
alert("当前定位地址为:" + address);
|
||
});
|
||
geolocationControl.addEventListener("locationError", function(e) {
|
||
// 定位失败事件
|
||
alert(e.message);
|
||
});
|
||
map.addControl(geolocationControl);
|
||
*/
|
||
|
||
//使用鼠标滑轮缩放地图
|
||
map.enableScrollWheelZoom();
|
||
//禁止双击缩放地图
|
||
map.disableDoubleClickZoom();
|
||
//设置地图默认的鼠标指针样式
|
||
//map.setDefaultCursor("url('bird.cur')");
|
||
// 百度地图API功能 浏览器定位(定位功能不稳定,时好时坏,大概是没有充值将就着用)
|
||
/*
|
||
var geolocation = new BMap.Geolocation();
|
||
geolocation.getCurrentPosition(function(r) {
|
||
if (this.getStatus() == BMAP_STATUS_SUCCESS) {
|
||
var mk = new BMap.Marker(r.point);
|
||
map.addOverlay(mk);
|
||
map.panTo(r.point);
|
||
alert('您的位置:' + r.point.lng + ',' + r.point.lat);
|
||
} else {
|
||
//alert('failed:' + this.getStatus());
|
||
console.log("failed:" + this.getStatus());
|
||
}
|
||
}, {
|
||
enableHighAccuracy : true
|
||
});
|
||
*/
|
||
//关于状态码
|
||
//BMAP_STATUS_SUCCESS 检索成功。对应数值“0”。
|
||
//BMAP_STATUS_CITY_LIST 城市列表。对应数值“1”。
|
||
//BMAP_STATUS_UNKNOWN_LOCATION 位置结果未知。对应数值“2”。
|
||
//BMAP_STATUS_UNKNOWN_ROUTE 导航结果未知。对应数值“3”。
|
||
//BMAP_STATUS_INVALID_KEY 非法密钥。对应数值“4”。
|
||
//BMAP_STATUS_INVALID_REQUEST 非法请求。对应数值“5”。
|
||
//BMAP_STATUS_PERMISSION_DENIED 没有权限。对应数值“6”。(自 1.1 新增)
|
||
//BMAP_STATUS_SERVICE_UNAVAILABLE 服务不可用。对应数值“7”。(自 1.1 新增)
|
||
//BMAP_STATUS_TIMEOUT 超时。对应数值“8”。(自 1.1 新增)
|
||
//标记点
|
||
var marker = "";
|
||
//存放所有的经纬度信息
|
||
var pointData = [];
|
||
if(''!=lng || ''!=lat){
|
||
pointData.push(lng,lat);
|
||
var point = new BMap.Point(lng,lat);
|
||
var label="";
|
||
|
||
if(''!=equipmentName){
|
||
label = new BMap.Label(equipmentName, {
|
||
offset : new BMap.Size(20, -10)
|
||
});
|
||
// 创建文本标注对象
|
||
label.setStyle({
|
||
border: "0",
|
||
fontWeight :"bold",
|
||
backgroundColor: "0.05",
|
||
fontFamily:"微软雅黑"
|
||
});
|
||
|
||
}else{
|
||
label = new BMap.Label("id=" + 1, {
|
||
offset : new BMap.Size(20, -10)
|
||
});
|
||
// 创建文本标注对象
|
||
label.setStyle({
|
||
border: "0",
|
||
fontWeight :"bold",
|
||
backgroundColor: "0.05",
|
||
fontFamily:"微软雅黑"
|
||
});
|
||
|
||
}
|
||
|
||
addMarker(point, label);
|
||
}
|
||
//单击获取点击的经纬度
|
||
/*
|
||
map.addEventListener("click", function(e) {
|
||
if (pointData.length == 0) {
|
||
alert(e.point.lng + "," + e.point.lat);
|
||
document.getElementById("lng").value = e.point.lng;
|
||
document.getElementById("lat").value = e.point.lat;
|
||
pointData.push(e.point.lng, e.point.lat);
|
||
var point = new BMap.Point(e.point.lng, e.point.lat);
|
||
var label = new BMap.Label("id=" + 1, {
|
||
offset : new BMap.Size(20, -10)
|
||
});
|
||
addMarker(point, label);
|
||
|
||
} else {
|
||
map.removeEventListener("click", function(e) {
|
||
});
|
||
}
|
||
});
|
||
*/
|
||
|
||
// 编写自定义函数,创建标注
|
||
function addMarker(point, label) {
|
||
marker = new BMap.Marker(point);
|
||
//设置标记点并显示再地图上
|
||
map.addOverlay(marker);
|
||
//设置标记的文本信息
|
||
marker.setLabel(label);
|
||
//设置标注点可以拖动
|
||
//marker.enableDragging();
|
||
//跳动的动画
|
||
marker.setAnimation(BMAP_ANIMATION_BOUNCE);
|
||
//marker.addEventListener("click", getMarkerAttr);
|
||
// 开启事件监听
|
||
/*
|
||
marker.addEventListener("dragend", function(e) {
|
||
var x = e.point.lng; //经度
|
||
var y = e.point.lat; //纬度
|
||
alert("拖到的地点的经纬度:" + x + "," + y);
|
||
document.getElementById("lng").value = e.point.lng;
|
||
document.getElementById("lat").value = e.point.lat;
|
||
});
|
||
*/
|
||
}
|
||
|
||
/*
|
||
function getMarkerAttr() {
|
||
//获取marker的位置
|
||
var p = marker.getPosition();
|
||
alert("marker的位置是" + p.lng + "," + p.lat);
|
||
}
|
||
*/
|
||
|
||
/*
|
||
//清除覆盖物
|
||
function removeOverlay() {
|
||
map.clearOverlays();
|
||
pointData = [];
|
||
document.getElementById("lng").value = "";
|
||
document.getElementById("lat").value = "";
|
||
}
|
||
*/
|
||
</script>
|