Openscales 入门


 对于开源WebGIS :我首选GeoServer+PostGIS+Openscales

 

 

下面开始Openscales1.2应用的简单入门

 

FlexApp.mxml

 

<?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"
      width="100%" height="100%"
      xmlns:os="http://openscales.org"
      creationComplete="initMap();" resize="resizeMap()">
 <fx:Style source="FlexApp.css"/>

 <fx:Declarations>
 </fx:Declarations>
 
 <os:Map id="fxmap" width="100%" height="100%" zoom="5" center="4.833,45.767">
  <os:WMSC name="Nasa" url="http://openscales.org/geoserver/gwc/service/wms" layers="bluemarble"
   format="image/jpeg" maxExtent="-180,-90,180,90"/>
  
  <os:WheelHandler/>
  <!--图层管理器 -->
  <os:ControlPanel title="图层管理器" x="{width - 225}" y="10" width="215">
   <os:LayerManager />
  </os:ControlPanel>
  <!-- 鹰眼-->
  <s:Panel id="miniMapPanel" title="Overview map" x="{width-miniMapPanel.width-10}" y="{height-miniMapPanel.height-10}">
   <s:layout>
    <s:HorizontalLayout/>
   </s:layout>
   <os:OverviewMap id="miniMap" width="100%" height="100%" extentColor="0xFF3300" newExtentColor="0x00FF33">
    <os:CycleMap name="cyclemap" proxy="http://openscales.org/proxy.php?url="/>
   </os:OverviewMap>
  </s:Panel>
  <!-- 比例尺 -->
  <os:ScaleLine x="{10}" y="{height-80}" />

  <!-- 显示鼠标坐标 -->
  <os:MousePosition x="{fxmap.width / 2}"
        y="{fxmap.height-20}"
        displayProjection="EPSG:4326"/>
  <!-- 导航控件1 -->
  <os:PanZoom map="{map}"
     x="{fxmap.x+10}"
     y="{fxmap.y+10}" width="112" height="126"/>
 </os:Map>
 
 <!--导航控件2
 <os:ControlPanel x="10" y="200" width="140" title="Navigation2">
  <os:Pan map="{map}"/>
  <mx:HBox width="100%" paddingLeft="5" paddingRight="5">
   <os:Zoom map="{map}"/>
   <mx:Spacer width="100%" />
   <os:ZoomBox map="{map}" width="32" height="32"/>
  </mx:HBox>
 </os:ControlPanel>
 -->
 
 <!-- 工具栏 -->
 <os:ControlPanel  x="100" height="57" y="10" title="工具栏">
  <os:layout>
   <s:HorizontalLayout/>
  </os:layout>
  <mx:Button id="zoomInBtn" click="doMap('zoomin')" label="放大"/>
  <mx:Button id="zoomOutBtn" click="doMap('zoomout')" label="缩小"/>
  <mx:Button id="fullExtentBtn" click="{map.zoomToMaxExtent()}" label="全屏"/>
  <mx:Button id="panBtn" click="doMap('pan')" label="漫游"/>
  <mx:Button id="prevExtentBtn" click="{navToolbar.zoomToPrevExtent()}" label="前一视图"/>
  <mx:Button id="nextExtentBtn" click="{navToolbar.zoomToNextExtent()}" label="后一视图"/>
 </os:ControlPanel>

 
 <fx:Script>
  <![CDATA[
   import org.openscales.core.Map;
   import org.openscales.core.Trace;
   import org.openscales.core.feature.Marker;
   import org.openscales.core.feature.CustomMarker;
   import org.openscales.core.feature.PointFeature;
   import org.openscales.core.layer.FeatureLayer;
   import org.openscales.core.popup.Anchored;
   import org.openscales.core.style.Style;
   import org.openscales.geometry.Point;
   import org.openscales.geometry.basetypes.Location;
   import org.openscales.proj4as.ProjProjection;
   import toolbars.Navigation;
   
   [Bindable] private var map:Map = null;
   public var markLyon:Marker;
   [Bindable] public var displayTrace:Boolean=false;
   [Bindable] public var displayFirebugTrace:Boolean=false;
   private var navToolbar:Navigation=new Navigation();
   
   private function initMap():void {
    Trace.useFireBugConsole=displayFirebugTrace;
    map = fxmap.map;
    this.navToolbar.map=map;
    
    var markers:FeatureLayer = new FeatureLayer("customMarkerLayer");
    //添加默认标记
    markers.projection = new ProjProjection("EPSG:4326");
    markers.generateResolutions(19);
    markers.style = Style.getDefaultPointStyle();
    var marker:PointFeature = PointFeature.createPointFeature(new Location(-94.49783,40.51800));
    markers.addFeature(marker);
    
    //markers.addFeature(CustomMarker.createUrlBasedMarker("http://earth.google.com/intl/en_uk/outreach/images/add_placemark.png",new Location(-94.49783,40.51800)));

    //添加标记,绑定事件弹出气泡
    var lonlat:Location = new Location(-95.49783,42.51800, ProjProjection.getProjProjection("EPSG:4326"));
    markLyon = new Marker(new org.openscales.geometry.Point(lonlat.lon, lonlat.lat), {popupContentHTML: "This is a popup<br /><b>Bold text</b><br /><u>Link to <a href=\"http://openscales.org\" target=\"_new\">OpenScales</a></u>"});
    markLyon.addEventListener(MouseEvent.CLICK, showPopup);
    markers.addFeature(markLyon);
    
    map.addLayer(markers);
    
    var vect:FeatureLayer = new FeatureLayer("Reprojected vector");
    vect.projection = ProjProjection.getProjProjection("EPSG:4326");
    vect.style = Style.getDefaultPointStyle();
    var p:org.openscales.geometry.Point = new org.openscales.geometry.Point(lonlat.lon, lonlat.lat);
    vect.generateResolutions(19);
    vect.addFeature(new PointFeature(p));
    map.addLayer(vect);
   }
   
   private function doMap(tool:String):void{
    navToolbar.activate(tool);
   }
   
   private function resizeMap():void {
    miniMap.height = 0.2 * this.height;
    miniMap.width = this.width * miniMap.height / this.height;
   }
   
   private function showPopup(e:MouseEvent):void {
    var popup:Anchored = new Anchored();
    popup.feature = markLyon;
    map.addPopup(popup, true);
   }
   
  ]]>
 </fx:Script>
</s:Application>

效果如图:

 
Openscales 入门_第1张图片
 

 

本例实现了地图的基本功能包括:导航栏、工具栏、图层管理器、鹰眼、比例尺、鼠标坐标显示、标注气泡显示等。

 

 

 

 

你可能感兴趣的:(PHP,css,OS,Flex,Adobe)