Custom Overlays | Maps JavaScript API - Google Developers
文章推薦指數: 80 %
Overlays are objects on the map that are tied to latitude/longitude coordinates, so they move when you drag or zoom the map. For information on predefined ... Google MapsPlatform Overview Products Pricing Documentation GetStarted GetStartedwithGoogleMapsPlatform APIPicker Billing&Pricing Reporting&Monitoring MapIDs FAQ SupportandResources IncidentManagement Maps MapsJavaScriptAPI MapsSDKforAndroid MapsSDKforiOS MapsStaticAPI StreetViewStaticAPI MapsEmbedAPI MapsURLs MapsElevationAPI Routes DirectionsAPI DistanceMatrixAPI RoadsAPI Solutions IndustrySolutions GamingServices TransportationandLogistics Places PlacesAPI PlacesSDKforAndroid PlacesSDKforiOS PlacesLibrary,MapsJavaScriptAPI GeocodingAPI GeolocationAPI TimeZoneAPI AdditionalResources APISecurityBestPractices MapCoverageDetails OptimizationGuide MobileOSandsoftwaresupport Deprecations AssetTrackingPlan RootCAMigrationFAQ URLEncoding WordPressUsers Blog Community StackOverflow GitHub YouTube Discord Twitter IssueTracker Language English BahasaIndonesia Deutsch Español Français Português–Brasil Русский 中文–简体 日本語 한국어 Signin Web MapsJavaScriptAPI GetStarted Contactsales Guides Reference Samples Support Google MapsPlatform Overview Products Pricing Documentation More Guides Reference Samples Support Blog Community More MapsJavaScriptAPI Overview SetupinCloudConsole UsingAPIKeys Tutorials Alltutorials Addamarkertoyourmap Clustermarkers Real-timecollaborativemapping Showcurrentlocation Usedatawithyourmap DisplayingKMLImportingJSONdataVisualizingJSONdataCombiningJSONdata AddingaMapandMarkerstoaReactApplication Concepts Allconcepts Maptypes Mapandtilecoordinates Localizingthemap Versioning URLparameters Bestpractices UsingTypeScript Promises Managemarkerlabelcollisions Customizeamap CustomizewithCloudbasedmapsstyling CustomizewithJSONstyling JSONstylingoverviewJSONstylereference CustomLegends Interactwiththemap Controls Events Controlzoomandpan Drawonthemap Overview Markers Custommarkers Infowindows Shapes Symbols WebGLFeatures OverviewVectorMapsTiltandRotationWebGLOverlayView Deck.gldatavisualizations Groundoverlays Customoverlays Displaydata Overview Data-drivenstyling(Preview) OverviewGetstartedStyleaboundarypolygonMakeachoroplethmapHandleclickeventsUsetheRegionLookupAPIUsetheRegionLookupAPIwithGoogleSheetsUseGeocodingandPlacesAPIswithData-drivenstylingGoogleboundariescoverage Datalayer Heatmap KMLandGeoRSS Traffic,Transit,andBicyclingLayers Services Directions DistanceMatrix Elevation Geocoding MaximumZoomImagery StreetView Libraries Overview DrawingLibrary GeometryLibrary LocalContextLibrary(Beta) OverviewGetStartedSettingLocalContextandMapOptionsHandlingEventsandUserInteractionRefreshingSearchPropertiesStylingtheLocalContextMapViewSupportedPlaceTypesMigratingaMaptoLocalContextMapView PlacesLibrary PlaceAutocomplete VisualizationLibrary OpenSourceLibraries MoreGuides ContentSecurityPolicyGuide GoogleLoaderMigrationGuide PlaceFieldMigration(open_now,utc_offset) PlaceDataFields PlaceIcons PlaceIDs PlaceTypes Upgradingfromv2tov3 PoliciesandTerms Usageandbilling Reportingandmonitoring Termsofservice OtherAPIs MapsStaticAPI StreetViewStaticAPI MapsEmbedAPI MapsURLs GetStarted GetStartedwithGoogleMapsPlatform APIPicker Billing&Pricing Reporting&Monitoring MapIDs FAQ SupportandResources IncidentManagement Maps MapsJavaScriptAPI MapsSDKforAndroid MapsSDKforiOS MapsStaticAPI StreetViewStaticAPI MapsEmbedAPI MapsURLs MapsElevationAPI Routes DirectionsAPI DistanceMatrixAPI RoadsAPI Solutions IndustrySolutions GamingServices TransportationandLogistics Places PlacesAPI PlacesSDKforAndroid PlacesSDKforiOS PlacesLibrary,MapsJavaScriptAPI GeocodingAPI GeolocationAPI TimeZoneAPI AdditionalResources APISecurityBestPractices MapCoverageDetails OptimizationGuide MobileOSandsoftwaresupport Deprecations AssetTrackingPlan RootCAMigrationFAQ URLEncoding WordPressUsers StackOverflow GitHub YouTube Discord Twitter IssueTracker Home Products GoogleMapsPlatform Documentation Web MapsJavaScriptAPI Sendfeedback CustomOverlays Selectplatform: Android iOS JavaScript Introduction Overlaysareobjectsonthemapthataretiedtolatitude/longitudecoordinates, sotheymovewhenyoudragorzoomthemap.Forinformationonpredefined overlaytypes,see Drawingonthemap. TheMapsJavaScriptAPIprovidesan OverlayViewclassfor creatingyourowncustomoverlays.TheOverlayViewisabaseclassthat providesseveralmethodsyoumustimplementwhencreatingyouroverlays.The classalsoprovidesafewmethodsthatmakeitpossibletotranslatebetween screencoordinatesandlocationsonthemap. Addacustomoverlay Hereisasummaryofthestepsrequiredtocreateacustomoverlay: Setyourcustomoverlayobject'sprototypetoanewinstanceof google.maps.OverlayView().Ineffect,thiswillsubclasstheoverlay class. Createaconstructorforyourcustomoverlay,andsetanyinitialization parameters. ImplementanonAdd()methodwithinyourprototype,andattachtheoverlay tothemap.OverlayView.onAdd()willbecalledwhenthemapisreadyfor theoverlaytobeattached. Implementadraw()methodwithinyourprototype,andhandlethevisual displayofyourobject.OverlayView.draw()willbecalledwhentheobject isfirstdisplayed. YoushouldalsoimplementanonRemove()methodtocleanupanyelements youaddedwithintheoverlay. Belowaremoredetailsoneachstep.Youcanseethefull,workingexample code:viewexamplecode. Subclasstheoverlay TheexamplebelowusesOverlayViewtocreateasimpleimageoverlay. NowwecreateaconstructorfortheUSGSOverlayclass,andinitializethe passedparametersaspropertiesofthenewobject. TypeScript /** *ThecustomUSGSOverlayobjectcontainstheUSGSimage, *theboundsoftheimage,andareferencetothemap. */ classUSGSOverlayextendsgoogle.maps.OverlayView{ privatebounds:google.maps.LatLngBounds; privateimage:string; privatediv?:HTMLElement; constructor(bounds:google.maps.LatLngBounds,image:string){ super(); this.bounds=bounds; this.image=image; }index.ts Note:ReadtheguideonusingTypeScriptandGoogleMaps. JavaScript /** *ThecustomUSGSOverlayobjectcontainstheUSGSimage, *theboundsoftheimage,andareferencetothemap. */ classUSGSOverlayextendsgoogle.maps.OverlayView{ bounds; image; div; constructor(bounds,image){ super(); this.bounds=bounds; this.image=image; }index.js Wecan'tyetattachthisoverlaytothemapintheoverlay'sconstructor.First, weneedtoensurethatallofthemap'spanesareavailable,becausethey specifytheorderinwhichobjectsaredisplayedonamap.TheAPIprovidesa helpermethodindicatingthishasoccurred.We'llhandlethatmethodinthenext section. Initializetheoverlay Whentheoverlayisfirstinstantiatedandreadytodisplay,weneedtoattach ittothemapviathebrowser'sDOM.TheAPIindicatesthattheoverlayhasbeen addedtothemapbyinvokingtheoverlay'sonAdd()method.Tohandlethis methodwecreatea
延伸文章資訊
- 1How do I change the google maps overlay?
The Basemaps menu lets you alter the look and feel of the map with a variety of map views. For ex...
- 2Google Map Overlays - HTML Tutorial
The map itself is displayed using a tile overlay. If you own a series of tiles, ... Examples. var...
- 3Creating Image Overlays in Google Earth Desktop
Add an Image Overlay
- 4How to Overlay Polygon Shapes Onto Google Maps - Resources
In this tutorial, you'll learn how to overlay polygon shapes onto Google Maps and embed it into a...
- 5Google Maps Overlays - W3Schools
Google Maps - Overlays. Overlays are objects on the map that are bound to latitude/longitude coor...