首页 / 浏览问题 / 云GIS / 问题详情
轨迹联动问题
6EXP 2017年12月25日

一个点是个要素vector,设置成标注的图片的,线也是一个vector,然后现在设置了点的dragFeature控件,可以拖动了,想做的是让这个点只能在这一条线上拖动,别的地方都不能拖,怎么做啊

1个回答

iClient js目前不支持。
但是可以自己实现,下载iClient js源码,扩展handler或者重写相关方法即可,
比如重写SuperMap.Handler.PointmodifyFeature方法,该方法在鼠标移动等事件时在图层上绘制点,鼠标移动事件及modifyFeature方法源码如下:


​​​​​​

   /**
     * Method: move
     * Handle mousemove and touchmove.  Adjust the geometry and redraw.
     * Return determines whether to propagate the event on the map.
     * 
     * Parameters:
     * evt - {Event} The browser event
     *
     * Returns: 
     * {Boolean} Allow event propagation
     */
    move: function (evt) {
        if(!this.touch // no point displayed until up on touch devices
           && (!this.mouseDown || this.stoppedDown)) {
            this.modifyFeature(evt.xy);
        }
        return true;
    }, 
   /**
     * Method: modifyFeature
     * Modify the existing geometry given a pixel location.
     *
     * Parameters:
     * pixel - {<SuperMap.Pixel>} A pixel location on the map.
     */
    modifyFeature: function(pixel) {
        if(!this.point) {
            this.createFeature(pixel);
        }
        var lonlat = this.layer.getLonLatFromViewPortPx(pixel);
        if(this.control.snap){
            lonlat=this.control.snap.beginSnap(lonlat);
        }
        this.point.geometry.x = lonlat.lon;
        this.point.geometry.y = lonlat.lat;
        this.callback("modify", [this.point.geometry, this.point, false]);
        this.point.geometry.clearBounds();
        this.drawFeature();
    },

iClient js GitHub地址:https://github.com/SuperMap/iClient-JavaScript-Classic

1,780EXP 2017年12月25日
...