以下是父页面的内容!!!!
<input type="text" placeholder="活动地点" id="risenemEventplace" onClick="dz()" class="layui-input"/>
<input type="hidden" id="risenemLng" name="risenemLng"/>
<input type="hidden" id="risenemLat" name="risenemLat" />
//弹出地图
function dz(){
layer.open({
type: 2,
title: '活动地点',
shadeClose: true,
shade: 0.8,
anim:0,
area: ['80%', '80%'],
content: '/risen/newdj/page/eventmanage/eventMap.html', //iframe的url
scrollbar: false
});
}
以下是地图页面的内容
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=2lkDOKqrgrUodHwrwvG1Mv6BPbf0Id8Y"></script>
<script src="./assets/js/jquery-1.8.3.min.js"></script>
<span style="width: 50px; font-size:15px;display: inline-block;">搜索:</span><input type="text" id="selectText" style="height: 30px;width: 250px;"/>
<div id="searchResultPanel" style="position:absolute;z-index:999;background-color:#fff;border:1px solid #C0C0C0;height:auto;left: 50px;"></div>
<!--地图容器-->
<div id="allmap"></div>
var map;
$(function () {
init();
});
function init() {
var geocoder= new BMap.Geocoder();
map = new BMap.Map("allmap"); // 创建Map实例
var point = new BMap.Point(102.846837,24.95393); // 创建点坐标
map.addControl(new BMap.MapTypeControl());
map.centerAndZoom(point,11);
map.setCurrentCity("云南省");
map.enableScrollWheelZoom(); //启用滚轮放大缩小
var myIcon = new BMap.Icon("/risen/dj/home/index/images/dq.png", new BMap.Size(30,32),
{
// offset: new BMap.Size(0,0), // 指定定位位置
// imageOffset: new BMap.Size(140,40) // 设置图片偏移
anchor: new BMap.Size(10, 30),
infoWindowAnchor: new BMap.Size(10, 0)
});
//没有设置党组织坐标
map.addEventListener("click",function(e){
//alert(e.point.lng + "," + e.point.lat);
map.clearOverlays();
var marker = new BMap.Marker(new BMap.Point(e.point.lng,e.point.lat),{icon:myIcon}); // 创建点
marker.disableDragging();
map.addOverlay(marker);
var _iframe = window.parent;//获取父页面中的窗口对象(index1.html
var risenemLng =_iframe.document.getElementById("risenemLng").value=e.point.lng;
var risenemLat =_iframe.document.getElementById("risenemLat").value=e.point.lat;
$('input[name="risenpoXindex"]').val(e.point.lng);
$('input[name="risenpoYindex"]').val(e.point.lat);
geocoder.getLocation(e.point,function(rs){
var risenemEventplace =_iframe.document.getElementById("risenemEventplace").value=rs.address;
});
});
}
//百度地图API功能 检索 str
//************地图位置搜索 str
var ac = new BMap.Autocomplete( //建立一个自动完成的对象
{"input" : "selectText"
,"location" : map
});
ac.addEventListener("onhighlight", function(e) { //鼠标放在下拉列表上的事件
var str = "";
var _value = e.fromitem.value;
var value = "";
if (e.fromitem.index > -1) {
value = _value.province + _value.city + _value.district + _value.street + _value.business;
}
str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
value = "";
if (e.toitem.index > -1) {
_value = e.toitem.value;
value = _value.province + _value.city + _value.district + _value.street + _value.business;
}
str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
$("searchResultPanel").innerHTML = str;
});
var myValue;
ac.addEventListener("onconfirm", function(e) { //鼠标点击下拉列表后的事件
var _value = e.item.value;
myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
$("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
setPlace();
});
function setPlace(){
map.clearOverlays(); //清除地图上所有覆盖物
var geocoder= new BMap.Geocoder();
function myFun(){
var pp = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
map.centerAndZoom(pp, 17);
map.addOverlay(new BMap.Marker(pp)); //添加标注
var _iframe = window.parent;//获取父页面中的窗口对象(index1.html
var risenemLng =_iframe.document.getElementById("risenemLng").value=pp.lng;
var risenemLat =_iframe.document.getElementById("risenemLat").value=pp.lat;
$('input[name="risenpoXindex"]').val(pp.lng);
$('input[name="risenpoYindex"]').val(pp.lat);
var risenemEventplace = $("#selectText").val();
var risenemEventplace =_iframe.document.getElementById("risenemEventplace").value=risenemEventplace;
}
var local = new BMap.LocalSearch(map, { //智能搜索
onSearchComplete: myFun
});
local.search(myValue);
}
//************地图位置搜索 end
//百度地图API功能 检索 end
//============== 地图坐标 END