Adobe Flex 创建多边形

发布于 2024-08-14 08:16:43 字数 34 浏览 2 评论 0原文

如何在 Adob​​e flex 3.0 中创建多边形

How to create a polygon in Adobe flex 3.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千纸鹤 2024-08-21 08:16:43

您绘制一堆连接多边形点的线。

举个简单的例子:

function drawPolygon(first, ... rest) {
    graphics.moveTo(first.x, first.y);
    for(var i = 0; i < rest.length; i++) {
        graphics.lineTo(rest[i].x, rest[i].y);
    }
    graphics.lineTo(first.x, first.y);
}

可能有一些轻微的语法错误,但你明白了。您可以通过传递一堆指示多边形点的 Point 对象来调用它。

You draw a bunch of lines connecting the points of the polygon.

As a quick example:

function drawPolygon(first, ... rest) {
    graphics.moveTo(first.x, first.y);
    for(var i = 0; i < rest.length; i++) {
        graphics.lineTo(rest[i].x, rest[i].y);
    }
    graphics.lineTo(first.x, first.y);
}

May be some minor syntax errors, but you get the idea. You'd call it by passing a bunch of Point objects indicating the points of the polygon.

惟欲睡 2024-08-21 08:16:43

尝试这个示例

<?xml version="1.0" encoding="utf-8"?>
<s:Application 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:esri="http://www.esri.com/2008/ags">
    <fx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.SpatialReference;
            import com.esri.ags.Units;
            import com.esri.ags.geometry.Geometry;
            import com.esri.ags.geometry.MapPoint;
            import com.esri.ags.geometry.Polygon;
            import com.esri.ags.geometry.Polyline;
            import com.esri.ags.utils.GeometryUtil;

            import mx.utils.StringUtil;

            private const sr:SpatialReference = new SpatialReference(4326);

            protected function onCreatePolyline(event:MouseEvent):void
            {
                addMessage("Create polyline clicked");

                var pts:Array = new Array();
                for (var i:int; i < 10; i++) // add 10 random points to path
                {
                    var pt:MapPoint = new MapPoint(Math.random()*10000, Math.random()*10000, sr);
                    pts.push(pt);
                }

                var pl:Polyline = new Polyline(new Array(pts), sr);

                var lengths:Array = GeometryUtil.geodesicLengths(new Array(pl), Units.KILOMETERS);
                if (lengths != null && lengths.length > 0)
                {

                    addMessage(StringUtil.substitute("polyline created with length {0} km", lengths[0]));
                }

                addGraphic(pl);
            }


            protected function onCreatePolygon(event:MouseEvent):void
            {
                addMessage("Create polygon clicked");
                var pts:Array = new Array();
                for (var i:int; i < 10; i++) // add 10 random points to ring
                {
                    var pt:MapPoint = new MapPoint(Math.random()*10000, Math.random()*10000, sr);
                    pts.push(pt);
                }

                var pg:Polygon = new Polygon(new Array(pts), sr);

                var areas:Array = GeometryUtil.geodesicAreas(new Array(pg), Units.SQUARE_KILOMETERS);
                if (areas != null && areas.length > 0)
                {

                    addMessage(StringUtil.substitute("polygon created with area {0} km²", Math.abs(areas[0])));
                }

                addGraphic(pg);
            }

            private function addMessage(message:String):void
            {
                log.text = StringUtil.substitute("> > > {0}\n{1}", message, log.text); 
            }

            private function addGraphic(geometry:Geometry):void
            {
                var gr:Graphic = new Graphic(geometry);
                grLayer.clear();
                var grId:String = grLayer.add(gr);
                addMessage(StringUtil.substitute("graphic added with id='{0}'", grId));
                map.initialExtent = geometry.extent;
                map.zoomToInitialExtent();
            }

        ]]>
    </fx:Script>

    <s:layout>
        <s:VerticalLayout gap="10" 
                          paddingBottom="10" 
                          paddingLeft="10"
                          paddingRight="10" 
                          paddingTop="10"/>
    </s:layout>

    <s:Button label="Create polyline" 
              click="onCreatePolyline(event)"/>

    <s:Button label="Create polygon" 
              click="onCreatePolygon(event)"/>

    <s:TextArea id="log" 
                width="100%" 
                height="100%"/>

    <esri:Map id="map"
                      zoomSliderVisible="false"
              minHeight="200"
              width="100%">

        <esri:GraphicsLayer id="grLayer" />

    </esri:Map>

</s:Application>

Try this sample

<?xml version="1.0" encoding="utf-8"?>
<s:Application 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:esri="http://www.esri.com/2008/ags">
    <fx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.SpatialReference;
            import com.esri.ags.Units;
            import com.esri.ags.geometry.Geometry;
            import com.esri.ags.geometry.MapPoint;
            import com.esri.ags.geometry.Polygon;
            import com.esri.ags.geometry.Polyline;
            import com.esri.ags.utils.GeometryUtil;

            import mx.utils.StringUtil;

            private const sr:SpatialReference = new SpatialReference(4326);

            protected function onCreatePolyline(event:MouseEvent):void
            {
                addMessage("Create polyline clicked");

                var pts:Array = new Array();
                for (var i:int; i < 10; i++) // add 10 random points to path
                {
                    var pt:MapPoint = new MapPoint(Math.random()*10000, Math.random()*10000, sr);
                    pts.push(pt);
                }

                var pl:Polyline = new Polyline(new Array(pts), sr);

                var lengths:Array = GeometryUtil.geodesicLengths(new Array(pl), Units.KILOMETERS);
                if (lengths != null && lengths.length > 0)
                {

                    addMessage(StringUtil.substitute("polyline created with length {0} km", lengths[0]));
                }

                addGraphic(pl);
            }


            protected function onCreatePolygon(event:MouseEvent):void
            {
                addMessage("Create polygon clicked");
                var pts:Array = new Array();
                for (var i:int; i < 10; i++) // add 10 random points to ring
                {
                    var pt:MapPoint = new MapPoint(Math.random()*10000, Math.random()*10000, sr);
                    pts.push(pt);
                }

                var pg:Polygon = new Polygon(new Array(pts), sr);

                var areas:Array = GeometryUtil.geodesicAreas(new Array(pg), Units.SQUARE_KILOMETERS);
                if (areas != null && areas.length > 0)
                {

                    addMessage(StringUtil.substitute("polygon created with area {0} km²", Math.abs(areas[0])));
                }

                addGraphic(pg);
            }

            private function addMessage(message:String):void
            {
                log.text = StringUtil.substitute("> > > {0}\n{1}", message, log.text); 
            }

            private function addGraphic(geometry:Geometry):void
            {
                var gr:Graphic = new Graphic(geometry);
                grLayer.clear();
                var grId:String = grLayer.add(gr);
                addMessage(StringUtil.substitute("graphic added with id='{0}'", grId));
                map.initialExtent = geometry.extent;
                map.zoomToInitialExtent();
            }

        ]]>
    </fx:Script>

    <s:layout>
        <s:VerticalLayout gap="10" 
                          paddingBottom="10" 
                          paddingLeft="10"
                          paddingRight="10" 
                          paddingTop="10"/>
    </s:layout>

    <s:Button label="Create polyline" 
              click="onCreatePolyline(event)"/>

    <s:Button label="Create polygon" 
              click="onCreatePolygon(event)"/>

    <s:TextArea id="log" 
                width="100%" 
                height="100%"/>

    <esri:Map id="map"
                      zoomSliderVisible="false"
              minHeight="200"
              width="100%">

        <esri:GraphicsLayer id="grLayer" />

    </esri:Map>

</s:Application>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文