日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

arcgis api 动态显示鼠标位置经纬度

發(fā)布時間:2023/12/14 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 arcgis api 动态显示鼠标位置经纬度 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

動態(tài)顯示鼠標位置經(jīng)緯度,主要是監(jiān)聽鼠標移動事件 “mouse-move”,獲取經(jīng)緯度信息,在當前鼠標位置用文本標注出來即可。添加了個監(jiān)聽鼠標點擊事件 “mouse-down”,在鼠標點擊后才開始監(jiān)聽鼠標移動事件。
實現(xiàn)效果:

代碼較為簡單,注釋里有,復(fù)制可直接打開:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>arcgis api實現(xiàn)動態(tài)顯示當前鼠標經(jīng)緯度</title><link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css"><style>body,html {margin: 0;padding: 0;width: 100%;height: 100%;font-family: Arial;}#map {width: 100%;height: 100%;margin: 0;padding: 0;border: 0px dashed black;background-color: rgb(0, 38, 48);}</style> </head> <body><button type="button" onclick="mouseStart()">開始</button><button type="button" onclick="mouseStop()">停止</button><div id="map"></div> </body> <script src="https://cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script src="https://js.arcgis.com/3.20"></script> <script type="text/javascript">var map, mouseStart, mouseStop, mouseDown, mouseMove;require(["esri/map",'esri/Color','esri/geometry/Point',"esri/geometry/Polyline","esri/symbols/TextSymbol","esri/layers/GraphicsLayer","esri/layers/ArcGISTiledMapServiceLayer",'esri/graphic','esri/symbols/SimpleMarkerSymbol','esri/symbols/SimpleLineSymbol',"esri/geometry/Extent","dojo/domReady!"], function(Map,Color,Point,Polyline,TextSymbol,GraphicsLayer,ArcGISTiledMapServiceLayer,Graphic,SimpleMarkerSymbol,SimpleLineSymbol,Extent) {//地圖范圍var mapExtent = new Extent({xmax: 113.799760210539,xmin: 106.57095767482662,ymax: 20.459116202966324,ymin: 18.27952992162579,spatialReference: {wkid: 4326}})map = new Map("map", {extent: mapExtent,sliderStyle: "small",logo: false,});map.on('load', function () {map.hideZoomSlider()map.hidePanArrows()map.disableDoubleClickZoom() //禁用雙擊縮放})//arcgis 在線切片底圖圖var myTileLayer = new ArcGISTiledMapServiceLayer("http://cache1.arcgisonline.cn/arcgis/rest/services/ChinaOnlineCommunity/MapServer");map.addLayer(myTileLayer)var graphicLayer = new GraphicsLayer() //繪制圖層map.addLayer(graphicLayer)var markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 6, //點樣式new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([0, 0, 0]), 1),new Color([47, 79, 79, 0.5]))//開始監(jiān)聽鼠標點擊和移動事件mouseStart = function() {console.log("開始監(jiān)聽鼠標點擊和移動事件")mouseDown = map.on("mouse-down", function() { //鼠標點擊事件mouseMove = map.on("mouse-move", function(evt) { //鼠標移動事件let lon = evt.mapPoint.getLongitude().toFixed(4) //當前數(shù)據(jù)經(jīng)度let lat = evt.mapPoint.getLatitude().toFixed(4) //當前鼠標緯度let point = new Point(lon, lat)graphicLayer.clear() //清除上次移動數(shù)據(jù)let pointGraphic = new Graphic(point, markerSymbol)//鼠標位置graphicLayer.add(pointGraphic) let text = "經(jīng)度:"+ lon + " 緯度:" + lat //標注內(nèi)容let textSymbol = new TextSymbol(text) //標注實例textSymbol.setOffset(0, 5) //標注偏移let textGraphic = new Graphic(point, textSymbol) //鼠標位置即標注點graphicLayer.add(textGraphic) //添加標注到地圖})})}//移除鼠標單擊和移動事件mouseStop = function() {console.log("移除鼠標點擊和移動事件")mouseDown.remove()mouseMove.remove()}}); </script> </html>

總結(jié)

以上是生活随笔為你收集整理的arcgis api 动态显示鼠标位置经纬度的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。