首页 / 浏览问题 / 云GIS / 问题详情
PlottingLayer 获取鼠标绘画坐标
17EXP 2018年05月30日
var plottingEditMap, baseLayer, plottingLayer, plottingEdit, drawFeature;
        var mapurl ="http://localhost:8090/iserver/services/map-ShunYiQuPeiTu/rest/maps/顺义区配图";
        var serverUrl ="http://localhost:8090/iserver/services/plot-jingyong/rest/plot/";

        function init_() {
            plottingEditMap = new SuperMap.Map("plottingEditMap", {
                controls: [
                    new SuperMap.Control.LayerSwitcher(),
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    })]
            });
            baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("顺义区配图", mapurl, {
                transparent: true,
                cacheEnabled: true
            }, {maxResolution: "auto"});
            baseLayer.events.on({"layerInitialized": addLayer});
            plottingLayer = new SuperMap.Layer.PlottingLayer("PlottingLayer", serverUrl);
            plottingEdit = new SuperMap.Control.PlottingEdit(plottingLayer);
            drawFeature = new SuperMap.Control.DrawFeature(plottingLayer, SuperMap.Handler.GraphicObject);
            drawFeature.events.on({"featureadded": drawCompleted});
            plottingEditMap.addControls([plottingEdit, drawFeature]);
            
            
            console.log("init:初始化方法");
        }

        function addLayer(){
             console.log("addLayer:添加图层");
            plottingEditMap.addLayers([baseLayer, plottingLayer]);
            plottingEditMap.setCenter(new SuperMap.LonLat(116.63505 , 40.17000), 3);         
        }

        function drawCompleted(){
            drawFeature.deactivate();
            plottingEdit.activate();
        }

        function editableChanges(){
            plottingLayer.isEditable = document.getElementById("editable").selectedIndex;
        }

        function lockedChanges(){
            plottingLayer.isLocked = document.getElementById("locked").selectedIndex;
        }

        function drawPolygon()
        {
            drawFeature.handler.serverUrl = serverUrl;
            drawFeature.handler.libID = 0;
            drawFeature.handler.symbolCode = 32;
            drawFeature.deactivate();
            drawFeature.activate();
        }

        document.oncontextmenu = function(evt){
            drawFeature.deactivate();
            return false;
        }
        

这是参考代码里面的模板  怎么获取鼠标绘画的坐标

1个回答

您用的什么产品?看起来不是我们三维产品啊?是否分类有误,麻烦你把产品全称说一下
5,985EXP 2018年05月30日
全称是这个  

SuperMap_iClient_8C(2017)_SP1_for_JavaScript

用的是这个 plottingLayer  类

您好,获取鼠标位置经纬度可以参考范例地图-地图操作-坐标转换

我参考了代码是可以获取坐标可是和 图层编辑的实例有冲突,俩个都是获取鼠标事件。  开始执行drawPolygon() 的候plottingEditMap.events.on({"click":getMousePositionPx});

就获取不到事件信息了 也就是没有坐标了。

我想的是在使用图层编辑实例的时候获取它绘画点的坐标保存到数据库

function getMousePositionPx(e)
        {
             var lonlat=   plottingEditMap.getLonLatFromPixel(new SuperMap.Pixel(e.xy.x,e.xy.y));                         
             console.log("lon="+ lonlat.lon.toFixed(5));
             console.log("lat="+lonlat.lat.toFixed(5));             
                                     
        }
       function addHandler(element,type,handler){
           if(element.addEventListener){
               element.addEventListener(type,handler,false);
           }else if(element.attachEvent){
               element.attachEvent("on"+type,handler);
           } else{
               element["on"+type] =handler;
           }
       }

      function setposition(){
          var width= plottingEditMap.getSize().w;
          document.getElementById("plottingEditMap").style.left=width/2-160+"px" ;
      }
找到方法了
function getMousePositionPx(e)
        {
             plottingLayer.removeAllFeatures();
             show_locationPointWCs();
             var lonlat=   plottingEditMap.getLonLatFromPixel(new SuperMap.Pixel(e.xy.x,e.xy.y));                                                        
             locationPointWCs.push(new SuperMap.Geometry.Point(lonlat.lon.toFixed(5) ,lonlat.lat.toFixed(5)));  
             var coor = lonlat.lon.toFixed(5)+","+lonlat.lat.toFixed(5);
           
             coordinates.push(coor);
             plottingLayer.createSymbolWC(0,SuperMap.Plot.SymbolType.POLYLINESYMBOL,locationPointWCs);  
        }
...