arcgis api for flex 地图选点画线 可拖动变色【写给已逝去的arcgis flex】



<?xml version="1.0" encoding="utf-8"?>
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
				   xmlns:s="library://ns.adobe.com/flex/spark"
				   xmlns:mx="library://ns.adobe.com/flex/mx"
				   xmlns:viewer="com.esri.viewer.*"
				   xmlns:esri="http://www.esri.com/2008/ags"
				   layout="absolute"
				   creationComplete="init()"
				   width="414"
				   height="214">

	<fx:Script source="script/Pathpoint.as"/>

	<fx:Declarations>
		<esri:PictureMarkerSymbol id="picStation3"
								  source="assets/images/widget/vehicle/stop.png"/>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>

	<mx:ColorPicker id="cpLine" selectedColor="{defaultDrawColor}" change="cpLine_changeHandler(event)" 
x="134" y="93" width="31" height="31"/>
</viewer:BaseWidget>
import com.adobe.serialization.json.JSONDecoder;
import com.esri.ags.Graphic;
import com.esri.ags.Map;
import com.esri.ags.SpatialReference;
import com.esri.ags.events.*;
import com.esri.ags.geometry.Geometry;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.geometry.Polyline;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.symbols.PictureMarkerSymbol;
import com.esri.ags.symbols.SimpleLineSymbol;
import com.esri.ags.utils.WebMercatorUtil;


import flash.events.MouseEvent;
import flash.utils.*;

import mx.collections.*;
import mx.controls.*;
import mx.core.UIComponent;
import mx.effects.Glow;
import mx.events.*;
import mx.events.ListEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;

import spark.events.*;
import spark.primitives.Line;

private static var _instance:Pathpoint;

private var _map:Map;
[Bindable]
private var _mapChanged:Boolean=false;

[Bindable]
private var defaultDrawColor:uint;


private var pArray:Array=new Array;
private var line:Polyline=new Polyline;
private var candraw:Boolean=true;
private var panoGraphic:Graphic;
private var pointLayer:GraphicsLayer;
private var lineLayer:GraphicsLayer;
private var currentLineGraphic:Graphic;

//--------------------------------------------------------------------------
//  map
//--------------------------------------------------------------------------

public static function getInstance():Pathpoint
{
	if (_instance == null)
		_instance=new Pathpoint();
	return _instance;
}

private function init():void
{
	getInstance();
	widgetInit();
}


/**
 * 窗体初始化函数
 */
private function widgetInit():void
{
	defaultDrawColor=0x3FAFDC;
	lineLayer=new GraphicsLayer();
	pointLayer=new GraphicsLayer();
	this.map.addLayer(lineLayer);
	this.map.addLayer(pointLayer);
	this.map.addEventListener(MapMouseEvent.MAP_CLICK, test_clickHandler);
}

protected function drag(event:DragEvent):void
{
	this.map.addEventListener(MapMouseEvent.MAP_CLICK, test_clickHandler);
}

protected function clear(event:MouseEvent):void
{
	pArray.length=0;
	lineLayer.clear();
	pointLayer.clear();
}

protected function test_clickHandler(event:MapMouseEvent):void
{
	var mouseMapPoint:MapPoint=map.toMapFromStage(event.stageX, event.stageY);

	map.infoWindow.label="当前位置 共:" + (pArray.length + 1) + "个点";
	map.infoWindow.show(mouseMapPoint);
	var pointGraphic:Graphic=new Graphic(mouseMapPoint, picStation3);
	pointGraphic.toolTip=mouseMapPoint.x + "," + mouseMapPoint.y;
	pointGraphic.name="point";
	pArray.push(mouseMapPoint);
	line.addPath(pArray);
	pointLayer.add(pointGraphic);
	//0x22DD92
	var lineGraphic:Graphic=lineLayer.getChildByName("line") as Graphic || new Graphic();
	lineGraphic.name="line";
	lineGraphic.geometry=line;
	lineGraphic.symbol=new SimpleLineSymbol('solid', defaultDrawColor, 1, 5);
	if (!lineLayer.getChildByName("line"))
		lineLayer.add(lineGraphic);

	pointGraphic.addEventListener(MouseEvent.MOUSE_UP, enddrag);
	pointGraphic.addEventListener(MouseEvent.MOUSE_DOWN, startdrag);
	//	map.removeEventListener(MapMouseEvent.MAP_CLICK,test_clickHandler);
}



/**
 * 开始拖动
 * @param event
 */
private function startdrag(event:MouseEvent):void
{
	map.removeEventListener(MapMouseEvent.MAP_CLICK, test_clickHandler);
	var component:UIComponent=event.currentTarget as UIComponent;
	component.startDrag();
}

/**
 * 结束拖动
 * @param event
 */
private function enddrag(event:MouseEvent):void
{
	var component:Graphic=event.currentTarget as Graphic
	component.stopDrag();
	var m:MapPoint=map.toMapFromStage(event.stageX, event.stageY);
	component.toolTip=m.x + "," + m.y;
	map.infoWindow.show(m);
	component.geometry=m;
	trace(component.name);
	var idx:int=pointLayer.getChildIndex(component);
	idx=idx < 1 ? 0 : idx;
	line.setPoint(idx, idx, m);
	//	lineGraphic.symbol=new SimpleLineSymbol('solid', 0x0000FF, 1, 5);
	pointLayer.refresh();
	lineLayer.refresh();
	map.addEventListener(MapMouseEvent.MAP_CLICK, test_clickHandler);
}



/**
 * 改变颜色
 * @param event
 */
protected function cpLine_changeHandler(event:ColorPickerEvent):void
{
	defaultDrawColor=cpLine.selectedColor;
	if (lineLayer.getChildByName("line"))
	{
		(lineLayer.getChildByName("line") as Graphic).symbol=new SimpleLineSymbol('solid', defaultDrawColor, 1, 5);
		lineLayer.refresh();
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值