


About the display of the basic controls of the WEB version of Gaode Map
This article mainly introduces the display of the basic controls of the WEB version of the Gaode map. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
I recently studied Gaode. The use of the web version of the map summarizes the application of the basic controls of Amap. The Amap map is open source and editable. The method is not difficult. Friends who are interested can try to edit it by themselves.
I thought before I was working on a travel navigation project. I searched the Internet and found the AMAP open platform. I found out that Amap can be easily applied to my own project. I immediately applied for a key to learn about it and studied it carefully. After a while, I found it quite difficult. I searched online for cases and so on. After these few days, the editor has almost done some basic controls of AutoNavi. The renderings are as shown below:
Without further ado, let’s go directly to the source code. The following is the js code:
<script language="javascript" src="http://webapi.amap.com/maps?v=1.2&key=3c5ca12a5778fde874e9959c7fbdf516">//引入高德地图API</script> <script language="javascript"> var mapObj; var scale; var mapType; var toolBar; var overView; var circleEditor; var circle; var polygonEditor; var polygon; var homeControl; var controlUI; var ruler; var mousetool; //刷新页面 function reload(){ location.reload(); } function mapInit(){ mapObj = new AMap.Map("iCenter",{ center:new AMap.LngLat(116.397728,39.90423), //地图中心点 level:13, //地图显示的比例尺级别 }); mapObj.plugin(["AMap.ToolBar"],function(){ //在地图中添加ToolBar插件 toolBar = new AMap.ToolBar(); mapObj.addControl(toolBar); }); mapObj.plugin(["AMap.Scale"],function(){ //加载比例尺插件 scale = new AMap.Scale(); mapObj.addControl(scale); scale.show(); }); mapObj.plugin(["AMap.OverView"],function(){ //在地图中添加鹰眼插件 //加载鹰眼 overView = new AMap.OverView({ visible:true //初始化显示鹰眼 }); mapObj.addControl(overView); overView.open(); //展开鹰眼 }); mapObj.plugin(["AMap.RangingTool"],function(){ ruler = new AMap.RangingTool(mapObj); AMap.event.addListener(ruler,"end",function(e){ ruler.turnOff(); }); }); mapObj.plugin(["AMap.MouseTool"],function(){ //鼠标工具插件 mousetool = new AMap.MouseTool(mapObj); }); } function Coordinate(){ AMap.event.addListener(mapObj,'click',getLnglat); //点击事件 } function toolBarShow(){ toolBar.show(); toolBar.showRuler(); toolBar.showDirection(); } function toolBarDirection(){ toolBar.show(); toolBar.showDirection(); toolBar.hideRuler(); } function toolBarLong(){ toolBar.show(); toolBar.hideDirection(); toolBar.showRuler(); } function toolBarShot(){ toolBar.show(); toolBar.hideRuler(); toolBar.hideDirection(); } function iMapType(){ mapObj.plugin(["AMap.MapType"],function(){ //添加地图类型切换插件 //地图类型切换 mapType= new AMap.MapType({defaultType:1,showRoad:true}); mapObj.addControl(mapType); }); } function removeMapType(){ mapObj.removeControl(mapType); } function iCircleEditor(){ //圆形编辑器 circle = new AMap.Circle({ //圆形编辑器的样式 map: mapObj, center:new AMap.LngLat("116.40332221984863","39.90025505675715"), radius:1000, strokeColor: "#F33", strokeOpacity: 1, strokeWeight: 3, fillColor: "ee2200", fillOpacity: 0.35 }); mapObj.plugin(["AMap.CircleEditor"],function(){ circleEditor = new AMap.CircleEditor(mapObj,circle); //创建圆形编辑器对象 circleEditor.open(); //打开圆形编辑器 }); } function removeCicleEditor(){ //关闭圆形编辑器,隐藏圆形 circleEditor.close(); circle.hide(); } function iPloygonEditor(){ //编辑多边形 var arr=new Array();//经纬度坐标数组 arr.push(new AMap.LngLat("116.403322","39.920255")); arr.push(new AMap.LngLat("116.410703","39.897555")); arr.push(new AMap.LngLat("116.402292","39.892353")); arr.push(new AMap.LngLat("116.389846","39.891365")); polygon = new AMap.Polygon({ path:arr, //设置多边形轮廓的节点数组 strokeColor:"#0000ff", strokeOpacity:0.2, strokeWeight:3, fillColor: "#f5deb3", fillOpacity: 0.35 }); //地图上添加多边形 mapObj.addOverlays(polygon); //构造多边形编辑对象,并开启多边形的编辑状态 mapObj.plugin(["AMap.PolyEditor"],function(){ polygonEditor = new AMap.PolyEditor(mapObj,polygon); polygonEditor.open(); }); } function removePloygonEditor(){ polygonEditor.close(); polygon.hide(); } AMap.homeControlp = function(){} AMap.homeControlp.prototype = { addTo: function(map, dom){ dom.appendChild(this._getHtmlDom(map)); }, _getHtmlDom:function(map){ this.map=map; // 创建一个能承载控件的<p>容器 controlUI = document.createElement("p"); controlUI.style.width='80px'; //设置控件容器的宽度 controlUI.style.height='20px'; //设置控件容器的高度 controlUI.style.backgroundColor='white'; controlUI.style.borderStyle='solid'; controlUI.style.borderWidth='2px'; controlUI.style.cursor='pointer'; controlUI.style.textAlign='center'; // 设置控件的位置 controlUI.style.position='absolute'; controlUI.style.left='120px'; //设置控件离地图的左边界的偏移量 controlUI.style.top='5px'; //设置控件离地图上边界的偏移量 controlUI.style.zIndex='300'; //设置控件在地图上显示 // 设置控件字体样式 controlUI.style.fontFamily='Arial,sens-serif'; controlUI.style.fontSize='12px'; controlUI.style.paddingLeft='4px'; controlUI.style.paddingRight='4px'; controlUI.innerHTML="换中心点"; // 设置控件响应点击onclick事件 controlUI.onclick = function(){ map.setCenter(new AMap.LngLat(116.234404, 39.12915)); } return controlUI; } } AMap.event.trigger(homeControlp,"hide"); AMap.event.addListener(homeControlp,"hide",function(){ controlUI.style.display = 'none'; }) function myControl(){ homeControl = new AMap.homeControlp(mapObj); //新建自定义插件对象 mapObj.addControl(homeControl); //地图上添加插件 } function removeMyControl(){ homeControl.hide(); //controlUI.style.display='none'; } function iRangingTool(){ ruler.turnOn(); } function removeRangingTool(){ ruler.turnOff(); mapObj.clearMap(); //ruler.hide(); //ruler.setMap(null); //mapObj.removeControl(ruler); } function iMarker(){ mousetool.marker(); //使用鼠标工具,在地图上画标记点 } function iMeasureArea(){ mousetool.measureArea(); } function iRectZoomIn(){ mousetool.rectZoomIn(); } function iRectZoomOut(){ mousetool.rectZoomOut(); } function iPolyline(){ mousetool.polyline(); } function iPolygon(){ mousetool.polygon(); } function iCircle(){ mousetool.circle(); } function iRectangle(){ mousetool.rectangle(); } function iRule(){ mousetool.rule(); } function removeMouseTool(){ mousetool.close(true); } function geocoder() { var MGeocoder; //加载地理编码插件 mapObj.plugin(["AMap.Geocoder"], function() { MGeocoder = new AMap.Geocoder({ radius: 1000, extensions: "all" }); //返回地理编码结果 AMap.event.addListener(MGeocoder, "complete", geocoder_CallBack); //逆地理编码 MGeocoder.getAddress(lnglatXY); }); //加点 var marker = new AMap.Marker({ map:mapObj, icon: new AMap.Icon({ image: "http://api.amap.com/Public/images/js/mark.png", size:new AMap.Size(58,30), imageOffset: new AMap.Pixel(-32, -0) }), position: lnglatXY, offset: new AMap.Pixel(-5,-30) }); // mapObj.setFitView(); } //回调函数 function geocoder_CallBack(data) { var address; //返回地址描述 address = data.regeocode.formattedAddress; //返回结果拼接输出 document.getElementById("iAddress").innerHTML = address; } //鼠标点击,获取经纬度坐标 function getLnglat(e){ mapObj.clearMap(); var x = e.lnglat.getLng(); var y = e.lnglat.getLat(); document.getElementById("lnglat").innerHTML = x + "," + y; lnglatXY = new AMap.LngLat(x,y); geocoder(); } </script>
The following is the HTML code:
<body onLoad="mapInit()"> <p id="iCenter"></p> <p id="iControlbox"> <ul> <li><button onclick="javascript:toolBarShow();">显示完整鱼骨</button><button onclick="javascript:toolBar.hide();">隐藏鱼骨</button><button onclick="javascript:toolBarDirection();">方向盘</button><button onclick="javascript:toolBarLong();">长标尺</button><button onclick="javascript:toolBarShot();">短标尺</button></li> <li><button onclick="javascript:scale.show();">显示比例尺</button><button onclick="javascript:scale.hide();">隐藏比例尺</button></li> <li><button onclick="javascript:overView.show();">显示鹰眼</button><button onclick="javascript:overView.hide();">隐藏鹰眼</button></li> <li><button onclick="javascript:iMapType();">添加地图类型切换</button><button onclick="javascript:removeMapType();">移除地图类型切换</button></li> <li><button onclick="javascript:iCircleEditor();">添加圆形编辑器</button><button onclick="javascript:removeCicleEditor();">删除圆形编辑器</button></li> <li><button onclick="javascript:iPloygonEditor();">添加多边形编辑器</button><button onclick="javascript:removePloygonEditor();">删除多边形编辑器</button></li> <li><button onclick="javascript:iMarker();">鼠标打点工具</button><button onclick="javascript:removeMouseTool();">清除</button></li> <li><button onclick="javascript:iPolyline();">鼠标画折线工具</button><button onclick="javascript:removeMouseTool();">清除</button></li> <li><button onclick="javascript:iPolygon();">鼠标画多边形工具</button><button onclick="javascript:removeMouseTool();">清除</button></li> <li><button onclick="javascript:iCircle();">鼠标画圆形工具</button><button onclick="javascript:removeMouseTool();">清除</button></li> <li><button onclick="javascript:iRectangle();">鼠标画矩形工具</button><button onclick="javascript:removeMouseTool();">清除</button></li> <li><button onclick="javascript:iRule();">鼠标测距工具</button><button onclick="javascript:removeMouseTool();">清除</button></li> <li><button onclick="javascript:iMeasureArea();">鼠标测面积</button><button onclick="javascript:removeMouseTool();">移除</button></li> <li><button onclick="javascript:iRectZoomIn();">鼠标框选缩小</button><button onclick="javascript:iRectZoomOut();">鼠标框选放大</button><button onclick="javascript:removeRangingTool();">关闭鼠标放大缩小</button></li> <li><button onclick="javascript:iRangingTool();">测距插件</button><button onclick="javascript:removeRangingTool();">隐藏测距</button></li> <li><button onclick="javascript:myControl();">添加自定义控件</button><button onclick="javascript:removeMyControl();">移除自定义控件</button></li> <li><p class="detail"><p><span id="lnglat"> </span></p><p><span id="iAddress"> </span></p></p></li> <li><button onclick="javascript:Coordinate();">坐标拾取控件</button><button onclick="javascript:reload();">取消坐标拾取</button></li> </ul> </p> </body>
In the first line of js, introduce the Amap API. The key value is created by myself in the Amap and can be used. You can also open it on Amap. The platform can apply for a key value on its own and give it a try.
AMAP Open Platform: developer.amap.com/
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
html uses table layout to implement user registration form examples
Click the button text to become an input box , click Save to turn it into text implementation
The above is the detailed content of About the display of the basic controls of the WEB version of Gaode Map. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The default map on the iPhone is Maps, Apple's proprietary geolocation provider. Although the map is getting better, it doesn't work well outside the United States. It has nothing to offer compared to Google Maps. In this article, we discuss the feasible steps to use Google Maps to become the default map on your iPhone. How to Make Google Maps the Default Map in iPhone Setting Google Maps as the default map app on your phone is easier than you think. Follow the steps below – Prerequisite steps – You must have Gmail installed on your phone. Step 1 – Open the AppStore. Step 2 – Search for “Gmail”. Step 3 – Click next to Gmail app

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

If you don't have control over the zoom level in Safari, getting things done can be tricky. So if Safari looks zoomed out, that might be a problem for you. Here are a few ways you can fix this minor zoom issue in Safari. 1. Cursor magnification: Select "Display" > "Cursor magnification" in the Safari menu bar. This will make the cursor more visible on the screen, making it easier to control. 2. Move the mouse: This may sound simple, but sometimes just moving the mouse to another location on the screen may automatically return it to normal size. 3. Use Keyboard Shortcuts Fix 1 – Reset Zoom Level You can control the zoom level directly from the Safari browser. Step 1 – When you are in Safari

When we use word documents to edit files, sometimes there are many pages. We want to display them side by side and check the overall effect. However, because we don’t know how to operate, we often need to scroll for a long time to view page by page. I don’t know if you have ever encountered a similar situation. In fact, we can easily solve it at this time as long as we learn how to set the word zoom pages side by side. Below, let’s take a look and learn together. First, we create and open a new page in the Word document, and then enter some simple content to make it easier to distinguish. 2. For example, if we want to realize word zoom and side-by-side display, we need to find [View] in the menu bar, and then select [Multiple Pages] in the view tool options, as shown in the figure below: 3. Find [Multiple Pages] and click,

How to use map and positioning functions in uniapp 1. Background introduction With the popularity of mobile applications and the rapid development of positioning technology, map and positioning functions have become an indispensable part of modern mobile applications. uniapp is a cross-platform application development framework developed based on Vue.js, which can facilitate developers to share code on multiple platforms. This article will introduce how to use maps and positioning functions in uniapp and provide specific code examples. 2. Use the uniapp-amap component to implement the map function

In Microsoft Word documents, you often encounter the situation of merging two pages of content into one page, especially when you need to save paper or when you need to print a double-sided document. Several common methods to achieve this goal will be introduced below. Method 1: Adjust the page margins. First open the Word document and find the "Page Layout" option in the menu bar. After clicking, the page layout settings menu will pop up. Here you can adjust the page margins, including the top, bottom, left, and right margins. Generally speaking, making the top and bottom margins smaller will allow the content to fit within one page. you can taste

As Xiaohongshu becomes more and more popular among young people, more and more people choose to open stores on Xiaohongshu. Many novice sellers encounter difficulties when setting up their store address and do not know how to add the store address to the map. 1. How to add the store address to the map in Xiaohongshu? 1. First, make sure your store has a registered account on Xiaohongshu and has successfully opened a store. 2. Log in to your Xiaohongshu account, enter the store backend, and find the "Store Settings" option. 3. On the store settings page, find the "Store Address" column and click "Add Address". 4. In the address adding page that pops up, fill in the detailed address information of the store, including province, city, district, county, street, house number, etc. 5. After filling in, click the "Confirm Add" button. Xiaohongshu will provide you with the address

The development of computer technology, network technology, and software technology has provided great prospects for office automation. Our current office operation processes can all be carried out electronically, which greatly saves operation time. Excel tables are commonly used software operations. Sometimes based on paper or typesetting problems, we need to enlarge or reduce the entire excel table. Settings, if there are any operation methods that can meet our needs, let’s take a look at the following course. 1. First open the excel software and enter relevant information, as shown in the figure below. 2. Then click the icon in the lower right corner and move it left or right. The plus sign can zoom in and the minus sign can zoom out, as shown in the figure below. 3. The second method can also use ctrl + mouse wheel.
