MapABC Flex地図公式APIアプリケーション整理
24489 ワード
公式に提供されているAPIを集めてGISの開発を行います.以下は公式MapABC Flex APIアプリケーションの整理です.参考にしてください.役に立つことを望んでいます.
テストコードは次のとおりです.
MapABCテスト実行効果図:
テストコードは次のとおりです.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import com.mapabc.maps.api.basetypes.MLngLatBounds;
import com.mapabc.maps.api.basetypes.MLngLat;
import com.mapabc.maps.api.events.MMapEvent;
import com.mapabc.maps.api.constants.MDisplayState;
import com.mapabc.maps.api.constants.MToolbars;
import mx.controls.Alert;
import com.mapabc.maps.api.overlays.MPolyline;
import com.mapabc.maps.api.basetypes.MSize;
import com.mapabc.maps.api.basetypes.MPixelBounds;
import com.mapabc.maps.api.constants.MDirection;
import com.mapabc.maps.api.overlays.MMarker;
import com.mapabc.maps.api.overlays.options.MMarkerOptions;
import com.mapabc.maps.api.overlays.options.MLineOptions;
import com.mapabc.maps.api.overlays.MPolygon;
import com.mapabc.maps.api.overlays.options.MAreaOptions;
import com.mapabc.maps.api.layers.MTileLayer;
import com.mapabc.maps.api.constants.MGPSFocus;
import com.mapabc.maps.api.overlays.options.MLabelOptions;
import com.mapabc.maps.api.events.MMapMouseEvent;
import com.mapabc.maps.api.events.MMapEvent;
import com.mapabc.maps.api.basetypes.MLngLatBounds;
import com.mapabc.maps.api.overlays.options.MClusterOptions;
import com.mapabc.maps.api.overlays.options.MTipOptions;
import com.mapabc.maps.api.styles.MFontStyle;
private function mapReady(e:MMapEvent):void {
// , 。
// var lngLat1:MLngLat=new MLngLat(116.36890411376953,39.9134230048868661);
// var lngLat2:MLngLat=new MLngLat(116.38212203979492,39.9011768955094);
// var lngLat3:MLngLat=new MLngLat(116.38727188110351,39.91250133090293);
// var lngLat4:MLngLat=new MLngLat(116.39825820922851,39.904600759441024);
// var arr:Array = new Array();
// arr.push(lngLat1);
// arr.push(lngLat2);
// arr.push(lngLat3);
// arr.push(lngLat4);
// var line:MPolyline=new MPolyline(arr); // ,
// mapObj.addOverlay(line,true); //
// mapObj.addOverlay(line,true);
mapObj.setZoomAndCenter(13,new MLngLat(116.397428,39.90923));
}
function getCenterDemo():void {
var center:MLngLat=mapObj.getCenter();
Alert.show(" :"+center.lngX+";"+center.latY);
}
function getScaleDemo():void {
var scale:int=mapObj.getScale();
Alert.show(" :"+scale+" ");
}
function getZoomLevelDemo():void {
var zoomLevel:int=mapObj.getZoomLevel();
Alert.show(" :"+zoomLevel);
}
function getSizeDemo():void {
var size:MSize=mapObj.getSize();
var height:int=size.height;
var width:int=size.width;
Alert.show(" :"+width+"
"+" :"+height+" ");
}
function getPixelBoundsDemo():void {
var pixelBounds:MPixelBounds=mapObj.getPixelBounds();
var minX:int=pixelBounds.minX;
var minY:int=pixelBounds.minY;
var maxX:int=pixelBounds.maxX;
var maxY:int=pixelBounds.maxY;
Alert.show(" :("+minX+","+minY+"),
"+" :("+maxX+","+maxY+")");
}
function getLngLatBoundsDemo():void {
var lnglatBounds:MLngLatBounds=mapObj.getLngLatBounds();
var southWest:MLngLat=lnglatBounds.southWest;
var northEast:MLngLat=lnglatBounds.northEast;
Alert.show(" :"+southWest+"
"+" :"+northEast);
}
//
function zoomInDemo():void {
mapObj.zoomIn();
}
function zoomOutDemo():void {
mapObj.zoomOut();
}
//
function setZoomAndCenterDemo():void {
mapObj.setZoomAndCenter(12,new MLngLat("117.397464","39.908666"));
}
//
function setLngLatBoundsDemo():void {
mapObj.setLngLatBounds(new MLngLatBounds(new MLngLat('115.468496','39.78743'),new MLngLat('116.747589','40.01972')));
}
//
function savePositionDemo():void {
mapObj.savePosition();
}
//
function returnToSavedPositionDemo():void {
mapObj.returnToSavedPosition();
}
//panTo
function panToDemo():void {
mapObj.panTo(new MLngLat("116.497464","39.908666"));//
}
function panByDemo():void {
mapObj.panBy(new MSize(30,40));//
}
function panDirectionDemo():void {
mapObj.panDirection(MDirection.EAST, MDirection.SOUTH);// 。
}
// 、 、
function hideOverviewDemo():void {
mapObj.setCtrlPanelState(MFlexMap.OVERVIEW_CTRL, MDisplayState.HIDE);
}
function showOverviewDemo():void {
mapObj.setCtrlPanelState(MFlexMap.OVERVIEW_CTRL,MDisplayState.SHOW);
}
function minimizeOverviewDemo():void {
mapObj.setCtrlPanelState(MFlexMap.OVERVIEW_CTRL,MDisplayState.MINIMIZE);
}
function hideToolbarDemo():void {
mapObj.setCtrlPanelState(MFlexMap.TOOLBAR_CTRL,MDisplayState.HIDE);
}
function showToolbarDemo():void {
mapObj.setCtrlPanelState(MFlexMap.TOOLBAR_CTRL,MDisplayState.SHOW);
}
function hideScaleDemo():void{
mapObj.setCtrlPanelState(MFlexMap.SCALE_CTRL,MDisplayState.HIDE);
}
function showScaleDemo():void {
mapObj.setCtrlPanelState(MFlexMap.SCALE_CTRL,MDisplayState.SHOW);
}
//
function loadCtrlPanelDemo():void {
var toolbarOpt:Object={};
toolbarOpt.toolbarPos=new Point(20,50); //
toolbarOpt.toolbarUrl="http://api.mapabc.com/flexmap/2.3.3/v2.3ToolbarNew.swf"; // URL
mapObj.loadCtrlPanel(MFlexMap.TOOLBAR_CTRL,toolbarOpt);// ,
}
//
function setMapColorDemo():void {
mapObj.setMapColor("#ff0000");
}
//
function setContinuousZoomDemo():void {
mapObj.setContinuousZoom(true); //
}
//
function setUnContinunousZoomDemo():void {
mapObj.setContinuousZoom(false); //
}
//
function setZoomEnabledDemo():void {
mapObj.setZoomEnabled(true);
}
function setZoomDisabledDemo():void {
mapObj.setZoomEnabled(false); // 、 、
}
//
function setDragEnabledDemo():void {
mapObj.setDragEnabled(true);
}
function setDragDisabledDemo():void {
mapObj.setDragEnabled(false); // ,
}
//
function setKBEnabledDemo():void {
mapObj.setKeyboardEnabled(true); // :+ - ,
}
function setKBDisabledDemo():void {
mapObj.setKeyboardEnabled(false);
}
// /
function addOverlaysAndLayer():void {
mapObj.setZoomAndCenter(11,new MLngLat(116.397428,39.90923));//
var arr:Array=new Array();
var markerOption:MMarkerOptions = new MMarkerOptions();
markerOption.imageUrl ="http://code.mapabc.com/images/lan_1.png";
markerOption.picAgent = false;
var ll:MLngLat = new MLngLat("116.39718532562256","39.913850920735");
var Mmarker:MMarker = new MMarker(ll,markerOption);
Mmarker.id="point1";
arr.push(Mmarker);
var arrline:Array = new Array(); //
arrline.push(new MLngLat("116.25389099121094 ","39.861526631585534"));
arrline.push(new MLngLat("116.26212203979492","39.8311768955094"));
arrline.push(new MLngLat("116.30401611328125","39.81433799896189"));
arrline.push(new MLngLat("116.30825820922851 ","39.824600759441024"));
var line:MPolyline = new MPolyline(arrline);
line.id = "line1";
arr.push(line);
var arrpolygon:Array = new Array(); //
arrpolygon.push(new MLngLat("116.40332221984863","39.96025505675715"));
arrpolygon.push(new MLngLat("116.41070365905762","39.92755531478615"));
arrpolygon.push(new MLngLat("116.40229225158691","39.942353073034826"));
arrpolygon.push(new MLngLat("116.38984680175781","39.92136526100842"));
var polygon:MPolygon = new MPolygon(arrpolygon);
polygon.id="polygon1";
arr.push(polygon);
mapObj.addOverlays(arr,false);
var t1:MTileLayer = new MTileLayer(); //
t1.layerType=MTileLayer.TL_MASS_TRANSIT;
mapObj.addTileLayer(t1);
}
function clearMapDemo():void {
mapObj.removeTileLayer(MTileLayer.TL_MASS_TRANSIT);
mapObj.clearMap();
}
var marker:MMarker;
function addMarkerDemo():void {
var markerOption:MMarkerOptions=new MMarkerOptions(); //
markerOption.imageUrl="http://code.mapabc.com/images/lan_1.png";
markerOption.picAgent=false;
marker=new MMarker(new MLngLat("116.24839782714844","39.968174500886306"),markerOption);
marker.id="marker";
var markerOption1:MMarkerOptions=new MMarkerOptions();
markerOption1.imageUrl="http://code.mapabc.com/images/zd.png"; //
markerOption1.picAgent=false;
var labelOption:MLabelOptions=new MLabelOptions();
labelOption.content=" ";
markerOption1.labelOption=labelOption;
var lnglat:MLngLat = new MLngLat('117.675023' ,'39.6758345');
var marker1:MMarker = new MMarker(lnglat,markerOption1);
marker1.id="targetMarker";
var array:Array=new Array();
array.push(marker);
array.push(marker1);
mapObj.addOverlays(array,true);
}
function setGPSFocusDemo():void { // :
var array:Array=new Array();
array.push("marker");
mapObj.setGPSFocus(MGPSFocus.GPS_TYPE_MAPCENTER_FOCUS,array);
}
function moveToDemo():void { //
marker.moveTo( new MLngLat('117.675023' ,'39.6758345'),30, 1);
}
function addMarkers():void {//
mapObj.removeAllOverlays();
var Mmarker:MMarker;
var bounds:MLngLatBounds;
var southWest:MLngLat ;
var northEast:MLngLat ;
var lngSpan:Number;
var latSpan:Number;
var lngX:Number;
var latY:Number;
var lngX1:Number;
var latY1:Number;
for (var i:int=1;i<=30;i++){
bounds=mapObj.getLngLatBounds();
southWest = bounds.southWest;
northEast = bounds.northEast;
lngSpan= northEast.lngX-southWest.lngX;
latSpan=northEast.latY-southWest.latY;
lngX=southWest.lngX;
latY=southWest.latY;
lngX1=southWest.lngX+lngSpan*Math.random();
latY1=southWest.latY+latSpan*Math.random();
var ll:MLngLat = new MLngLat(lngX1, latY1,1);
var markerOption:MMarkerOptions=new MMarkerOptions();
//markerOption.attributeValue=30;
var tipOptions:MTipOptions=new MTipOptions();
tipOptions.borderStyle.color=0x16589a;
tipOptions.borderStyle.thickness=2;
tipOptions.title=" ";
tipOptions.titleFillStyle.color=0x16589a;
tipOptions.titleFontStyle.bold=true;
tipOptions.titleFontStyle.color=0xffffff;
tipOptions.titleFontStyle.size=14;
tipOptions.content="MapABC !";
tipOptions.contentFontStyle.bold=true;
tipOptions.contentFontStyle.size=12;
tipOptions.hasShadow=true;
tipOptions.roundRectSize=0;
markerOption.tipOption=tipOptions;
markerOption.canShowTip=false;
if(i<15){
markerOption.imageUrl="http://code.mapabc.com/images/lan_1.png";
markerOption.picAgent=false;
}
if((i<=30)&&(i>=15))
markerOption.imageUrl="http://code.mapabc.com/images/apin/hong_1.png";
markerOption.picAgent=false;
Mmarker = new MMarker(ll,markerOption);
Mmarker.id=i.toString();
mapObj.addOverlay(Mmarker,false);
}
}
function setNormalCluster():void {//
var clusterOptions:MClusterOptions=new MClusterOptions();
clusterOptions.gridSize=40;
clusterOptions.maxZoom=12;
mapObj.setClusterState(MClusterOptions.NORMAL_CLUSTER, clusterOptions) ;
}
function addClickEvent():void {//
mapObj.addEventListener(MMapMouseEvent.CLUSTER_MOUSE_CLICK,onClick);
mapObj.addEventListener(MMapEvent.CLUSTER_CLOSED,onClose);
}
function addOverEvent():void {//
mapObj.addEventListener(MMapMouseEvent.CLUSTER_MOUSE_OVER,onClick);
mapObj.addEventListener(MMapEvent.CLUSTER_CLOSED,onClose);
}
function onClick(e:MMapMouseEvent):void{//
if(e.clusterOverlayIds.length==1){// id 1,
// id,
var marker:MMarker=mapObj.getOverlayById(e.clusterOverlayIds[0]) as MMarker;
marker.option.tipOption.title=" id";
marker.option.tipOption.content=" id "+e.clusterOverlayIds[0]+" ";
// tip
mapObj.openTip(e.eventXY,marker.tipOption);
}else{// id 1,
var tipOptions:MTipOptions=new MTipOptions();
tipOptions.borderStyle.color=0x16589a;
tipOptions.borderStyle.thickness=2;
tipOptions.title=" id ";
tipOptions.content=e.clusterOverlayIds.toString();
tipOptions.titleFillStyle.color=0x16589a;
tipOptions.titleFontStyle.bold=true;
tipOptions.titleFontStyle.color=0xffffff;
tipOptions.titleFontStyle.size=14;
tipOptions.contentFontStyle.bold=true;
tipOptions.contentFontStyle.size=12;
mapObj.openTip(e.eventXY,tipOptions);
}
}
function onClose(e:MMapEvent):void{
mapObj.closeTip();// tip
}
function setFlareClusterDemo():void {//
var clusterOptions:MClusterOptions=new MClusterOptions();
clusterOptions.gridSize=40;
clusterOptions.maxZoom=16;
clusterOptions.isUseMarkerIcon=false;// marker
clusterOptions.centerMarkerURL="http://code.mapabc.com/images/m1.png";
clusterOptions.aroundMarkerURL="http://code.mapabc.com/images/point.png";
clusterOptions.attributeValue=MClusterOptions.TOTAL_NUMBER;
clusterOptions.flareDistance=50;
clusterOptions.fontStyle=new MFontStyle();
clusterOptions.fontStyle.color=0xfff000;
clusterOptions.fontStyle.size=20;
mapObj.setClusterState(MClusterOptions.FLARE_CLUSTER, clusterOptions) ;
}
function clickUpdateIconDemo():void {//
var id="10";
var marker:MMarker=mapObj.getOverlayById(id) as MMarker;
marker.option.tipOption.content=" ";
marker.option.imageUrl="http://api.mapabc.com/flexmap/2.3.3/images/m3.png";
marker.update();
mapObj.updateClusterByMarkerId(id,"http://api.mapabc.com/flexmap/2.3.3/images/m2.png");
}
function setNoClusterDemo():void {//
var clusterOptions:MClusterOptions=new MClusterOptions();
clusterOptions.gridSize=40;
clusterOptions.maxZoom=12;
mapObj.setClusterState(MClusterOptions.NORMAL_CLUSTER, clusterOptions) ;
}
]]>
</mx:Script>
<mx:Panel width="100%" height="100%" y="0" title="JpMapWebGIS" id="MapWebGIS">
<mx:HBox height="100%" width="100%">
<mapabcMap:MFlexMap xmlns:mapabcMap="com.mapabc.maps.api.*" id="mapObj" t="flexmap" v="2.3.3"
key="{['b0a7db0b3a30f944a21c3682064dc70ef5b738b062f6479a5eca39725798b1ee300bd8d5de3a4ae3']}"
overviewMap="{MDisplayState.SHOW}" toolbar="{MToolbars.ROUND}"
minZoomLevel="3" maxZoomLevel="17" totalLevel="17"
viewBounds="{new MLngLatBounds(new MLngLat(116.068496,39.787433),new MLngLat(116.747589,40.019727))}"
width="100%" height="100%" MapReady="mapReady(event)" />
<mx:VBox>
<mx:Button x="10" y="10" label=" " fontWeight="normal" fontSize="12" click="getCenterDemo()"/>
<mx:Button x="10" y="40" label=" " fontWeight="normal" fontSize="12" click="getScaleDemo()"/>
<mx:Button x="10" y="70" label=" " fontWeight="normal" fontSize="12" click="getZoomLevelDemo()"/>
<mx:Button x="10" y="100" label=" " fontWeight="normal" fontSize="12" click="getSizeDemo()"/>
<mx:Button x="10" y="130" label=" " fontWeight="normal" fontSize="12" click="getPixelBoundsDemo()"/>
<mx:Button x="10" y="160" label=" " fontWeight="normal" fontSize="12" click="getLngLatBoundsDemo()"/>
<mx:Button x="10" y="180" width="110" label=" " fontWeight="normal" fontSize="12" click="zoomInDemo()"/>
<mx:Button x="10" y="210" width="110" label=" " fontWeight="normal" fontSize="12" click="zoomOutDemo()"/>
<mx:Button x="10" y="240" label=" " fontWeight="normal" fontSize="12" click="setZoomAndCenterDemo()"/>
<mx:Button x="10" y="270" label=" " fontWeight="normal" fontSize="12" click="setLngLatBoundsDemo()"/>
<mx:Button x="10" y="300" label=" " fontWeight="normal" fontSize="12" click="savePositionDemo()"/>
<mx:Button x="10" y="330" label=" " fontWeight="normal" fontSize="12" click="returnToSavedPositionDemo()"/>
<mx:Button x="10" y="360" width="155" label="panTo " fontWeight="normal" fontSize="12" click="panToDemo()"/>
<mx:Button x="10" y="390" width="155" label="panBy " fontWeight="normal" fontSize="12" click="panByDemo()"/>
<mx:Button x="10" y="420" width="155" label="panDirection " fontWeight="normal" fontSize="12" click="panDirectionDemo()"/>
<mx:Button x="10" y="10" width="135" label=" " fontWeight="normal" fontSize="12" click="hideOverviewDemo()"/>
<mx:Button x="10" y="35" width="135" label=" " fontWeight="normal" fontSize="12" click="showOverviewDemo()"/>
<mx:Button x="10" y="60" width="135" label=" " fontWeight="normal" fontSize="12" click="minimizeOverviewDemo()"/>
<mx:Button x="10" y="85" width="135" label=" " fontWeight="normal" fontSize="12" click="hideToolbarDemo()"/>
<mx:Button x="10" y="110" width="135" label=" " fontWeight="normal" fontSize="12" click="showToolbarDemo()"/>
<mx:Button x="10" y="135" width="135" label=" " fontWeight="normal" fontSize="12" click="hideScaleDemo()"/>
<mx:Button x="10" y="160" width="135" label=" " fontWeight="normal" fontSize="12" click="showScaleDemo()"/>
<mx:Button x="10" y="10" fontSize="12" width="105" label=" " fontWeight="normal" click="loadCtrlPanelDemo()"/>
<mx:Button x="10" y="10" width="105" label=" " fontWeight="normal" fontSize="12" click="setMapColorDemo()"/>
<mx:Button x="10" y="10" fontSize="12" width="125" label=" " fontWeight="normal" click="setContinuousZoomDemo()"/>
<mx:Button x="10" y="35" fontSize="12" width="125" label=" " fontWeight="normal" click="setUnContinunousZoomDemo()"/>
</mx:VBox>
<mx:VBox>
<mx:Button x="10" y="10" fontSize="12" width="110" label=" " fontWeight="normal" click="setZoomEnabledDemo()"/>
<mx:Button x="10" y="35" fontSize="12" width="110" label=" " fontWeight="normal" click="setZoomDisabledDemo()"/>
<mx:Button x="10" y="10" width="110" label=" " fontWeight="normal" fontSize="12" click="setDragEnabledDemo()"/>
<mx:Button x="10" y="35" width="110" label=" " fontWeight="normal" fontSize="12" click="setDragDisabledDemo()"/>
<mx:Button x="10" y="10" fontSize="12" width="125" label=" " fontWeight="normal" click="setKBEnabledDemo()"/>
<mx:Button x="10" y="35" fontSize="12" width="125" label=" " fontWeight="normal" click="setKBDisabledDemo()"/>
<mx:Button x="10" y="10" width="110" label=" / " fontWeight="normal" fontSize="12" click="addOverlaysAndLayer()"/>
<mx:Button x="10" y="35" width="110" label=" " fontWeight="normal" fontSize="12" click="clearMapDemo()"/>
<mx:Button x="10" y="10" width="110" label=" " fontWeight="normal" fontSize="12" click="addMarkerDemo()"/>
<mx:Button x="10" y="60" width="160" label=" " fontWeight="normal" fontSize="12" click="setGPSFocusDemo()"/>
<mx:Button x="10" y="35" width="110" label=" " fontWeight="normal" fontSize="12" click="moveToDemo()"/>
<mx:Button x="0" y="10" width="130" label=" " fontWeight="normal" fontSize="12" click="addMarkers()"/>
<mx:Button x="0" y="35" width="130" label=" " fontWeight="normal" fontSize="12" click="setNormalCluster()"/>
<mx:Button x="0" y="70" width="130" label=" " fontWeight="normal" fontSize="12" click="addClickEvent()"/>
<mx:Button x="0" y="95" width="130" label=" " fontWeight="normal" fontSize="12" click="addOverEvent()"/>
<mx:Button x="0" y="120" width="130" label=" " fontWeight="normal" fontSize="12" click="setFlareClusterDemo()"/>
<mx:Button x="0" y="145" width="110" label=" " fontWeight="normal" fontSize="12" click="clickUpdateIconDemo()"/>
<mx:Button x="0" y="180" width="130" label=" " fontWeight="normal" fontSize="12" click="setNoClusterDemo()"/>
</mx:VBox>
</mx:HBox>
</mx:Panel>
</mx:Application>
MapABCテスト実行効果図: