Home > front end >  Baidu map of how to implement drag when the set point mark can be automatically moved to the center
Baidu map of how to implement drag when the set point mark can be automatically moved to the center

Time:10-05

As shown in figure:






As my js code below: please the great god and see how to modify?

& lt; Div id="allmap" style="width: 100%; Height: 100%; Overflow - y: scroll; Position: absolute;"> & lt;/div>
& lt; Div id="searchResultPanel" style="border: 1 px solid # C0C0C0; width:100%; Height: auto; Display: none;"> & lt;/div>
& lt; The script type="text/javascript" & gt;
//baidu map API function
Require ([zepto ""," the underscore ", "frozen"], function ($, _, fz) {
Var map=new BMap. The map (" allmap ");
Var addr=null;
Var LNG="& lt; LNG} {$& gt; ";
Var lat="& lt; {$lat} & gt; ";
if (! LNG & amp; & ! Lat) {
Map. CenterAndZoom (" & lt; {$city} & gt;" );
Var point=new BMap. Point (117.260852, 31.825717);
} else {
Map. CenterAndZoom (new BMap. Point (LNG, lat), 15);
LNG, var point=new BMap. Point (lat);
}
Map. CenterAndZoom (point, 17);
Var marker=new BMap. Marker (point);//create annotation
Map. ClearOverlays ();
The map. The addOverlay (marker);//add annotation to the map in the

Marker. SetAnimation (BMAP_ANIMATION_BOUNCE);/beat/animation
The function showPoint (e) {
Var p=new BMap. Point (e.p oint, LNG, e.p oint. Lat);
$(' # lat). Val (e.p oint. Lat);
$(' # LNG). Val (e.p oint. LNG);
Var mk=new BMap. Marker (p);

Map. ClearOverlays ();
//removeOverlay (overlay: overlay);
The map. The addOverlay (mk);
//mk. SetAnimation (BMAP_ANIMATION_BOUNCE);/beat/animation
Var geoc=new BMap. Geocoder ();
Geoc. GetLocation (p, function (rs) {
Var addComp=rs. AddressComponents;
Addr=addComp. Province + addComp. City + addComp. District + addComp. Street + addComp. StreetNumber;
//alert (addr);
$(" # suggestId "). Val (addr);
});
}
Map. EnableScrollWheelZoom (true);
Map. AddControl (new BMap. NavigationControl ());//add default zoom translational control
The map. The addEventListener (" click ", showPoint);

The function G (id) {
Return the document. The getElementById (id);
}

Var ac=new BMap. Autocomplete (//set up an automatic object
{" input ":" suggestId
", "location" : the map
});

Ac. AddEventListener (" the onhighlight ", function (e) {//mouse on an event in the drop-down list
Var STR="";
Var _value=https://bbs.csdn.net/topics/e.fromitem.value;
Var valuehttps://bbs.csdn.net/topics/="";
If (e.f romitem. Index & gt; 1) {
Value=https://bbs.csdn.net/topics/_value.province + _value. City + _value. District + _value. Street + _value. Business;
}
STR="FromItem

valuehttps://bbs.csdn.net/topics/="";
If (e. oitem. Index & gt; 1) {
_value=https://bbs.csdn.net/topics/e.toitem.value;
Value=https://bbs.csdn.net/topics/_value.province + _value. City + _value. District + _value. Street + _value. Business;
}
STR +="& lt; Br/& gt; ToItem
G (" searchResultPanel "). The innerHTML=STR;
});

Var myValue;
Ac. AddEventListener (" onconfirm ", function (e) {//event after the mouse to click the drop-down list
Var _value=https://bbs.csdn.net/topics/e.item.value;
MyValue=https://bbs.csdn.net/topics/_value.province + _value. City + _value. District + _value. Street + _value. Business;
G (" searchResultPanel "). The innerHTML="onconfirm
CodePudding user response:

The require an error
  • Related