arcgis jsapi接口入門系列(1):地圖 原

地圖相關

        //地圖相關demo
        mapFun: function () {
            //獲取地圖中心點
            let center = this.mapView.center;
            //地圖中心點座標(同地圖座標系)
            let x = center.x;
            let y = center.y;
            //地圖中心點座標(經緯度座標系)
            //PS:此經緯度座標是地圖自動投影轉換而來,因爲不一定準確(投影轉換不一定準)
            let longitude = center.longitude;
            let latitude = center.latitude;

            //設置地圖中心點
            this.mapView.center = [113.5411, 22.2399];

            //獲取地圖縮放級別
            let zoom = this.mapView.zoom;
            //設置地圖縮放級別
            this.mapView.zoom = 12;

            //獲取地圖比例尺
            let scale = this.mapView.scale;
            //設置地圖比例尺
            this.mapView.scale = 5000;

            //獲取地圖範圍
            let extent = this.mapView.extent;
            //地圖範圍座標
            let xmax = extent.xmax;
            let xmin = extent.xmin;
            let ymax = extent.ymax;
            let ymin = extent.ymin;
            //地圖範圍寬高(注意此寬高是地圖單位,而不是屏幕像素)
            let width = extent.width;
            let height = extent.height;

            //設置地圖範圍
            this.mapView.extent = new this.apiInstance.Extent({
                xmin: -9177882,
                ymin: 4246761,
                xmax: -9176720,
                ymax: 4247967,
                spatialReference: {
                    wkid: 102100
                }
            });

            //屏幕座標轉地圖座標
            //PS:參數1類型是ScreenPoint
            let mapPoint1 = this.mapView.toMap(new this.apiInstance.ScreenPoint(10, 10));

            //地圖座標轉屏幕座標
            let screenPoint1 = this.mapView.toScreen(mapPoint1);
        },

地圖點擊事件,同時圖形(graphic)點擊在此實現

                    //mapView綁定點擊事件
                    this.mapView.on("click", function (event) {
                        this.mapView.hitTest(event).then(function (response) {
                            //圖形(graphic)點擊事件的實現
                            if (response.results[0]) {
                                //獲取到點擊的圖形
                                var graphic = response.results[0].graphic;

                                //由於所有圖形都在此事件,實際需求可能需要判斷圖形是哪個圖形,或者圖形所在哪個圖層,可以通過uid和圖層id來判斷
                                let uid = graphic.uid;
                                //圖層不一定有,例如在mapView的graphics下的就沒有
                                if (graphic.layer) {
                                    let layerId = graphic.layer.id;
                                }
                            }
                        }.bind(this))
                    }.bind(this));

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章