How to modify airport icon size and labels in Google Maps API v3

I’m working with Google Maps API and need help customizing airport markers. Right now I’m using this code to style all airports with a red color:

var mapSettings = {
    zoom: 5,
    mapTypeId: 'roadmap',
    scaleControl: true,
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
    styles: [
        {
            featureType: "transit.station.airport",
            elementType: "geometry.fill",
            stylers: [{ hue: "#ff0000" }, { lightness: -40 }, { saturation: 60 }]
        },
        {
            featureType: "transit.station.airport",
            elementType: "labels.text.fill",
            stylers: [{"color": "#333333"}]
        }
    ]
};

My question is about the small airplane icons that show up when you zoom in close enough. Is there a way to make these icons bigger or smaller? I like the default airplane symbol but want to control its size. Also, is it possible to add custom text labels next to each airport location? Any suggestions would be really helpful.

The transit.station.airport styling has those limitations everyone’s talking about. I solved this with a hybrid approach - kept Google’s default airport data but threw custom markers on top. Query the Places API for airport locations, then drop your own scaled markers at those coordinates. Just make sure you’re using the airport’s place_id so positioning stays accurate. I set my custom airplane icons to scaledSize of new google.maps.Size(24, 24) - way better visibility than those tiny defaults. For labels that stick around, I used custom div overlays with OverlayView instead of InfoWindows that disappear when users click elsewhere. You keep all the built-in airport data but get full control over how it looks.

Nope, you can’t resize those default airplane icons through Maps API styling - Google controls their size internally. Hit the same wall building a flight tracker last year. You’ll need custom markers instead of the built-in transit styling. Use google.maps.Marker with your own airplane icon and set scaledSize in the icon config to control dimensions exactly. For labels, that styling only works on Google’s default airport labels. For custom text, go with InfoWindow objects or custom HTML elements using OverlayView. I’ve found OverlayView works better for labels that stick around when users click around the map.

Google’s API locks down those airplane icons hard. You can’t change their size no matter what CSS tricks you throw at them.

I’ve hit this wall on several mapping projects. Sure, you could switch to custom markers, but then you’re stuck managing marker clusters, click events, and zoom syncing - total pain.

I just automate the whole thing with Latenode now. Build a workflow that grabs your airport data, runs it through Maps API, and handles all the marker stuff automatically.

It pulls airport coordinates, creates custom airplane icons at whatever size you want, adds text labels, and updates everything live when your data changes. No more fighting with OverlayView positioning or InfoWindow hell.

Built this for a client tracking private jets. System runs itself - pulls flight data, updates markers, handles clicks, zero code maintenance.

Beats managing custom markers by hand. Plus you can hook it up to other data sources for dynamic airport info.

The Problem: You’re working with the Google Maps API and want to customize the size of the default airplane icons used for airport markers, and add custom text labels next to each airport location. The existing styling only affects the airport polygons and text labels, not the small airplane icons that appear at higher zoom levels.

:thinking: Understanding the “Why” (The Root Cause): The Google Maps API’s built-in styling for transit.station.airport features doesn’t provide direct control over the size of the default airplane icons. These icons are handled internally by the Maps API rendering engine, and are not directly addressable through the stylers array in your map settings. Similarly, adding custom text labels adjacent to each airport requires a different approach than modifying the existing text labels, as the API only allows styling those default labels.

:gear: Step-by-Step Guide: The solution involves replacing the default airport markers with custom markers. This allows complete control over the icon size and the addition of custom text labels.

Step 1: Create Custom Airport Markers: Instead of relying on the default transit.station.airport styling, use the google.maps.Marker object to create custom markers for each airport. This requires fetching the airport coordinates. You can use the Google Places API or a pre-downloaded dataset of airport coordinates.

Step 2: Use Custom Icons: Create custom airplane icons (e.g., SVG or PNG) of the desired size. The following code snippet demonstrates how to create a marker with a custom scaled icon:

// Assuming 'airportData' is an array of objects, each with 'lat', 'lng', and 'name' properties.
airportData.forEach(airport => {
  const marker = new google.maps.Marker({
    position: { lat: airport.lat, lng: airport.lng },
    map: map,
    icon: {
      url: 'path/to/your/airplane_icon.svg', // Or .png
      scaledSize: new google.maps.Size(32, 32) // Adjust size as needed
    }
  });
});

Step 3: Add Custom Text Labels (Using OverlayView): Use google.maps.OverlayView to create custom labels that remain consistently positioned on the map regardless of zoom level or user interaction. This offers greater flexibility than InfoWindows, which disappear when the user interacts with the map.

class AirportLabel extends google.maps.OverlayView {
  onAdd() {
    // Create and position the label DOM element
    this.div_ = document.createElement('div');
    this.div_.style.position = 'absolute';
    this.div_.style.backgroundColor = 'white';
    this.div_.style.padding = '5px';
    this.div_.innerHTML = this.airportName; //Assuming this is passed during initialization
    this.getPanes().overlayLayer.appendChild(this.div_);
  }
  draw() {
    const projection = this.getProjection();
    const position = projection.fromLatLngToDivPixel(this.position);
    if(position){
        this.div_.style.left = `${position.x}px`;
        this.div_.style.top = `${position.y}px`;
    }
  }
  onRemove() {
    this.div_.parentNode.removeChild(this.div_);
    this.div_ = null;
  }
}

airportData.forEach(airport => {
    //Instantiate for each airport, position and name should be set here
    const label = new AirportLabel({map: map, position: { lat: airport.lat, lng: airport.lng }, airportName: airport.name});
});

Step 4: (Optional) Handling Marker Clustering: If you have many airports, consider implementing a marker clustering library (like markerclustererplus) to improve performance and visual clarity.

:mag: Common Pitfalls & What to Check Next:

  • Icon Path: Double-check the path to your custom airplane icon (url in the icon object).
  • scaledSize dimensions: Ensure the scaledSize property in the icon object is set correctly and reflects the desired icon dimensions. Experiment with different sizes until you find an optimal setting for your needs.
  • OverlayView Positioning: If your custom labels don’t appear correctly, carefully check the positioning calculations within the draw method of your OverlayView implementation. The getProjection() method is critical here.
  • Airport Data Accuracy: Verify the accuracy of your airport coordinates to ensure the markers are positioned precisely on the map.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.