Mobile SDK - Ground overlays - CARTO
文章推薦指數: 80 %
Ground overlays project a bitmap (PNG, JPG) image of a defined coordinate over a basemap. For example, a ground overlay bitmap may be used to show an indoor ... gettingstarted mapview layersanddatasources vectorobjectsonmap offlinemaps packagemanager mobilegeocoding mobilerouting CARTOintegrations clustering groundoverlays performanceenhancements APIkeys gettingstarted mapview layersanddatasources vectorobjectsonmap offlinemaps packagemanager mobilegeocoding mobilerouting CARTOintegrations clustering groundoverlays performanceenhancements APIkeys GroundOverlays Groundoverlaysprojectabitmap(PNG,JPG)imageofadefinedcoordinateoverabasemap.Forexample,agroundoverlaybitmapmaybeusedtoshowanindoorfloorplanoverabuildingmap. Note:YourbitmapmustdefinegeographicalmapcoordinateswithGroundControlPoints.Currently,MobileSDKsupportsthreeorfourpointsonabitmapimage. GroundOverlayRequirements ThefollowingrequirementsallowyoutogroundoverlayswiththeMobileSDK. linearaffinetransformationenablesyoutosetthreecontrolpointstosetthelocation,size,androtationofthebitmap perspectivetransformationenablesyoutocontrolfourcontrolpointsforthebitmap Ifyouhavemorecontrolpointsinyourdata,itissuggestedtochoosethreeorfourofyourbestones,andselectthoseasyourgroundcontrolsettings Controlpointsmustbedefinedintheappcode.MobileSDKdoesnotautomaticallygathercontrolpointsfromthesourcefilemetadata Forexample,ifyouneedGeoTIFF,ESRIWorldFile,MapInfoTAB,GeospatialPDF,orotherreferenceddata,youwillgetthisfromtheGISExtension(seebelow). Theentirebitmapmustfittodevicememory(RAM).Dependingonthetargetdevice,themaximumsizecouldvary.Forexample,thetargetdevicemaximumsizemightbe2000x2000pixels. Tip:Forlargerrasters,theSDKExtensionsallowyoutodisplayanysizebitmap,uptohundredsofmegabytes.ThesebitmapsarereaddirectlyfromcommonGISrasterformats(suchasGeoTIFF,BSB,ECW,MrSID,JPEG2000,andsoon).Additionally,thesourcedatacanbeenteredusingdifferentcoordinatesystems.PleasecontactusifyouareinterestedinenablingSDKExtensionsaspartofyouraccount. CodeSamples Thisexampleusesonlyonegeographicalcoordinate.Thebuildingsizeisknown,andthebuildingdirectionisfacingnorth.Thisallowsustocalculateothergroundpointswiththecode.Fourgroundcontrolpointsaresettothecornersofthebitmap,whichtypicallyreturnsthemostaccurateresult. Tip:Thefollowingsamplecodeassumesthatyouhavethejefferson-building-ground-floor.jpgbitmapfileaspartofyourapplicationproject. ForAndroid,thisimageislocatedunderassets IniOS,itcanbelocatedanywhereinyourproject Java C# Objective-C Swift Kotlin 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 com.carto.graphics.BitmapoverlayBitmap=BitmapUtils.loadBitmapFromAssets("jefferson-building-ground-floor.jpg"); //1.Createtwovectorcontaininggeographicalpositionsandcorrespondingrasterimagepixelcoordinates MapPospos=proj.fromWgs84(newMapPos(-77.004590,38.888702)); doublesizeNS=110,sizeWE=100; MapPosVectormapPoses=newMapPosVector(); mapPoses.add(newMapPos(pos.getX()-sizeWE,pos.getY()+sizeNS)); mapPoses.add(newMapPos(pos.getX()+sizeWE,pos.getY()+sizeNS)); mapPoses.add(newMapPos(pos.getX()+sizeWE,pos.getY()-sizeNS)); mapPoses.add(newMapPos(pos.getX()-sizeWE,pos.getY()-sizeNS)); ScreenPosVectorbitmapPoses=newScreenPosVector(); bitmapPoses.add(newScreenPos(0,0)); bitmapPoses.add(newScreenPos(0,overlayBitmap.getHeight())); bitmapPoses.add(newScreenPos(overlayBitmap.getWidth(),overlayBitmap.getHeight())); bitmapPoses.add(newScreenPos(overlayBitmap.getWidth(),0)); //2.Createbitmapoverlayrastertiledatasource BitmapOverlayRasterTileDataSourcerasterDataSource=newBitmapOverlayRasterTileDataSource(0,20,overlayBitmap,proj,mapPoses,bitmapPoses); RasterTileLayerrasterLayer=newRasterTileLayer(rasterDataSource); mapView.getLayers().add(rasterLayer); //3.Applyzoomlevelbiastotherasterlayer //-Bydefault,bitmapsareupsampledonhigh-DPIscreens //4.Correctthisbyapplyingappropriatebias floatzoomLevelBias=(float)(Math.log(mapView.getOptions().getDPI()/160.0f)/Math.log(2)); rasterLayer.setZoomLevelBias(zoomLevelBias*0.75f); rasterLayer.setTileSubstitutionPolicy(TileSubstitutionPolicy.TILE_SUBSTITUTION_POLICY_VISIBLE); mapView.setFocusPos(pos,0); mapView.setZoom(16f,0); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 varoverlayBitmap=BitmapUtils.LoadBitmapFromAssets("jefferson-building-ground-floor.jpg"); //1.Createtwovectorgeographicalpositions,andcorrespondingrasterimagepixelcoordinates varpos=proj.FromWgs84(newMapPos(-77.004590,38.888702)); varsizeNS=110; varsizeWE=100; varmapPoses=newMapPosVector(); mapPoses.Add(newMapPos(pos.X-sizeWE,pos.Y+sizeNS)); mapPoses.Add(newMapPos(pos.X+sizeWE,pos.Y+sizeNS)); mapPoses.Add(newMapPos(pos.X+sizeWE,pos.Y-sizeNS)); mapPoses.Add(newMapPos(pos.X-sizeWE,pos.Y-sizeNS)); varbitmapPoses=newScreenPosVector(); bitmapPoses.Add(newScreenPos(0,0)); bitmapPoses.Add(newScreenPos(0,overlayBitmap.Height)); bitmapPoses.Add(newScreenPos(overlayBitmap.Width,overlayBitmap.Height)); bitmapPoses.Add(newScreenPos(overlayBitmap.Width,0)); //2.Createbitmapoverlayrastertiledatasource varrasterDataSource=newBitmapOverlayRasterTileDataSource(0,20,overlayBitmap,proj,mapPoses,bitmapPoses); varrasterLayer=newRasterTileLayer(rasterDataSource); MapView.Layers.Add(rasterLayer); //3.Applyzoomlevelbiastotherasterlayer //-Bydefault,bitmapsareupsampledonhigh-DPIscreens //4.Correctthisbyapplyingappropriatebias floatzoomLevelBias=(float)(Math.Log(MapView.Options.DPI/160.0f)/Math.Log(2)); rasterLayer.ZoomLevelBias=zoomLevelBias*0.75f; rasterLayer.TileSubstitutionPolicy=TileSubstitutionPolicy.TileSubstitutionPolicyVisible; MapView.SetFocusPos(pos,0); MapView.SetZoom(16f,0); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 //1.Loadgroundoverlaybitmap NTBitmap*overlayBitmap=[NTBitmapUtilsloadBitmapFromAssets:@"jefferson-building-ground-floor.jpg"]; //2.Createtwovectorgeographicalpositions,andcorrespondingrasterimagepixelcoordinates NTMapPos*pos=[projfromWgs84:[[NTMapPosalloc]initWithX:-77.004590y:38.888702]]; doublesizeNS=110,sizeWE=100; NTMapPosVector*mapPoses=[[NTMapPosVectoralloc]init]; [mapPosesadd:[[NTMapPosalloc]initWithX:[posgetX]-sizeWEy:[posgetY]+sizeNS]]; [mapPosesadd:[[NTMapPosalloc]initWithX:[posgetX]+sizeWEy:[posgetY]+sizeNS]]; [mapPosesadd:[[NTMapPosalloc]initWithX:[posgetX]+sizeWEy:[posgetY]-sizeNS]]; [mapPosesadd:[[NTMapPosalloc]initWithX:[posgetX]-sizeWEy:[posgetY]-sizeNS]]; NTScreenPosVector*bitmapPoses=[[NTScreenPosVectoralloc]init]; [bitmapPosesadd:[[NTScreenPosalloc]initWithX:0y:0]]; [bitmapPosesadd:[[NTScreenPosalloc]initWithX:0y:[overlayBitmapgetHeight]]]; [bitmapPosesadd:[[NTScreenPosalloc]initWithX:[overlayBitmapgetWidth]y:[overlayBitmapgetHeight]]]; [bitmapPosesadd:[[NTScreenPosalloc]initWithX:[overlayBitmapgetWidth]y:0]]; //3.Createbitmapoverlayrastertiledatasource NTBitmapOverlayRasterTileDataSource*rasterDataSource=[[NTBitmapOverlayRasterTileDataSourcealloc]initWithMinZoom:0maxZoom:20bitmap:overlayBitmapprojection:projmapPoses:mapPosesbitmapPoses:bitmapPoses]; NTRasterTileLayer*rasterLayer=[[NTRasterTileLayeralloc]initWithDataSource:rasterDataSource]; [[mapViewgetLayers]add:rasterLayer]; //4.Applyzoomlevelbiastotherasterlayer //-Bydefault,bitmapsareupsampledonhigh-DPIscreens //5.Correctthisbyapplyingappropriatebias floatzoomLevelBias=log([[mapViewgetOptions]getDPI]/160.0f)/log(2); [rasterLayersetZoomLevelBias:zoomLevelBias*0.75f]; [rasterLayersetTileSubstitutionPolicy:NT_TILE_SUBSTITUTION_POLICY_VISIBLE]; [mapViewsetFocusPos:posdurationSeconds:0]; [mapViewsetZoom:16fdurationSeconds:0]; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 letoverlayBitmap=NTBitmapUtils.createBitmap(from:UIImage(named:"jefferson-building-ground-floor.jpg")) //1.Createtwovectorcontaininggeographicalpositionsandcorrespondingrasterimagepixelcoordinates letpos=projection!.fromWgs84(NTMapPos(x:-77.004590,y:38.888702))! letsizeNS=110.0 letsizeWE=100.0 letmapPoses=NTMapPosVector(); mapPoses?.add(NTMapPos(x:pos.getX()-sizeWE,y:pos.getY()+sizeNS)) mapPoses?.add(NTMapPos(x:pos.getX()+sizeWE,y:pos.getY()+sizeNS)) mapPoses?.add(NTMapPos(x:pos.getX()+sizeWE,y:pos.getY()-sizeNS)) mapPoses?.add(NTMapPos(x:pos.getX()-sizeWE,y:pos.getY()-sizeNS)) letbitmapPoses=NTScreenPosVector() bitmapPoses?.add(NTScreenPos(x:0,y:0)) bitmapPoses?.add(NTScreenPos(x:0,y:Float(overlayBitmap!.getHeight()))) bitmapPoses?.add(NTScreenPos(x:Float(overlayBitmap!.getWidth()),y:Float(overlayBitmap!.getHeight()))) bitmapPoses?.add(NTScreenPos(x:Float(overlayBitmap!.getWidth()),y:0)) //2.Createbitmapoverlayrastertiledatasource letrasterDataSource=NTBitmapOverlayRasterTileDataSource(minZoom:0,maxZoom:20,bitmap:overlayBitmap,projection:projection,mapPoses:mapPoses,bitmapPoses:bitmapPoses) letrasterLayer=NTRasterTileLayer(dataSource:rasterDataSource); mapView?.getLayers()?.add(rasterLayer) //3.Applyzoomlevelbiastotherasterlayer //-Bydefault,bitmapsareupsampledonhigh-DPIscreens //4.Correctthisbyapplyingappropriatebias letzoomLevelBias=UIKit.log(mapView!.getOptions().getDPI()/160.0)/UIKit.log(2.0) rasterLayer?.setZoomLevelBias(zoomLevelBias*0.75) rasterLayer?.setTileSubstitutionPolicy(NTTileSubstitutionPolicy.TILE_SUBSTITUTION_POLICY_VISIBLE) mapView?.setFocus(pos,durationSeconds:0) mapView?.setZoom(16,durationSeconds:0) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 valoverlayBitmap=BitmapUtils.loadBitmapFromAssets("jefferson-building-ground-floor.jpg"); //1.Createtwovectorcontaininggeographicalpositionsandcorrespondingrasterimagepixelcoordinates valpos=projection!!.fromWgs84(MapPos(-77.004590,38.888702)) valsizeNS=110 valsizeWE=100 valmapPoses=MapPosVector(); mapPoses.add(MapPos(pos.x-sizeWE,pos.y+sizeNS)) mapPoses.add(MapPos(pos.x+sizeWE,pos.y+sizeNS)) mapPoses.add(MapPos(pos.x+sizeWE,pos.y-sizeNS)) mapPoses.add(MapPos(pos.x-sizeWE,pos.y-sizeNS)) valbitmapPoses=ScreenPosVector() bitmapPoses.add(ScreenPos(0F,0F)) bitmapPoses.add(ScreenPos(0F,overlayBitmap.height.toFloat())) bitmapPoses.add(ScreenPos(overlayBitmap.width.toFloat(),overlayBitmap.height.toFloat())) bitmapPoses.add(ScreenPos(overlayBitmap.width.toFloat(),0F)) //2.Createbitmapoverlayrastertiledatasource valrasterDataSource=BitmapOverlayRasterTileDataSource(0,20,overlayBitmap,projection,mapPoses,bitmapPoses) valrasterLayer=RasterTileLayer(rasterDataSource); mapView?.layers?.add(rasterLayer) //3.Applyzoomlevelbiastotherasterlayer //-Bydefault,bitmapsareupsampledonhigh-DPIscreens //4.Correctthisbyapplyingappropriatebias valzoomLevelBias=(Math.log(mapView!!.options.dpi/160.0)/Math.log(2.0)).toFloat() rasterLayer.zoomLevelBias=zoomLevelBias*0.75f rasterLayer.tileSubstitutionPolicy=TileSubstitutionPolicy.TILE_SUBSTITUTION_POLICY_VISIBLE mapView?.setFocusPos(pos,0F) mapView?.setZoom(16f,0F)
延伸文章資訊
- 1GroundOverlay — React Google Maps Style Guide
Returns the opacity of this ground overlay. getUrl(). Gets the url of the projected image.
- 2GroundOverlay | Android Developers - MIT
Class Overview. A ground overlay is an image that is fixed to a map. A ground overlay has the fol...
- 3Mobile SDK - Ground overlays - CARTO
Ground overlays project a bitmap (PNG, JPG) image of a defined coordinate over a basemap. For exa...
- 4Edit KML ground overlay | ArcGIS Runtime API for .NET
KML ground overlays are used for showing aerial imagery, symbology, or other images draped over a...
- 5Ground overlay disappearing unexpectedly on map ...
ground overlay will stop moving with the map and will slide out of view until the map is dragged ...