Black flash issue when toggle the visibility of symbol pin on azure map

So, I created a Vue project and added the azure-maps-control

npm install azure-maps-control

added the css in main.ts

import "azure-maps-control/dist/atlas.min.css";

Now, this is how I load the pins once map is ready

const labelId = 'label-'+r.pinname;
await map?.imageSprite.add(labelId, icons.Label.replace("{stroke}", r.pincolor));
await map?.imageSprite.createFromTemplate(r.pinname, 'marker-thick', r.pincolor, '#fff');
const stops = r.stops.map(m => m.coordinates);
stops.forEach(coord => {
  var dataSource = new atlas.source.DataSource();
  map?.sources.add(dataSource);

  var shape = new atlas.Shape(new atlas.data.Point(coord), r.pinname);
  dataSource.add(shape);

  const symbolLayerLabel = new atlas.layer.SymbolLayer(dataSource, '', {
    iconOptions: {
      image: labelId,
      allowOverlap: true,
      ignorePlacement: true
    },
  });
  map?.layers.add(symbolLayerLabel);

  const symbolLayer = new atlas.layer.SymbolLayer(dataSource, '', {
    iconOptions: {
      image: r.pinname,
      allowOverlap: true,
      ignorePlacement: true
    },
    textOptions: {
      allowOverlap: true,
      ignorePlacement: true,
      anchor: 'top',
      textField: r.pinname,
      offset: [0, -3.9],
      size: 13
    }
  });
  map?.layers.add(symbolLayer);

  dataSources.value.push(dataSource);
  symbolLayers.value.push(symbolLayer);
});

Then I created a function to toggle the visibility of that pins

symbolLayers.value.forEach(layer => {
  const opts = layer.getOptions() as LayerOptions;
  if (opts.iconOptions.image==pinname) {
    layer.setOptions({visible: visible});
    return;
  }
});

So there’s a click button on the top left of this screenshot where I use the function for toggle the visibility of pins.

Did I miss anything?

Recognized by Microsoft Azure Collective

3

Black flash issue when toggle the visibility of symbol pin on azure map

The black flash occurs because adding/removing or manipulating layers at scale triggers frequent redraws or re-renders of the map.

You are creating a new DataSource for every pin and two SymbolLayers per pin (one for label and one for the marker), which adds complexity and rendering overhead.

Group all pins under a single DataSource.

  • One layer for the marker icon and one for the label. Instead of adding multiple layers, we filter the shapes using their properties.

Revised code:

const dataSource = new atlas.source.DataSource();
map?.sources.add(dataSource);

// Add all pins to a single DataSource
r.stops.forEach(coord => {
  const shape = new atlas.Shape(new atlas.data.Point(coord), {
    id: r.pinname,
    labelColor: r.pincolor,
    iconColor: r.pincolor
  });
  dataSource.add(shape);
});

// Add SymbolLayer for icons
const symbolLayer = new atlas.layer.SymbolLayer(dataSource, null, {
  iconOptions: {
    image: 'marker-thick',
    allowOverlap: true,
    ignorePlacement: true
  }
});
map?.layers.add(symbolLayer);

// Add SymbolLayer for labels
const symbolLayerLabel = new atlas.layer.SymbolLayer(dataSource, null, {
  textOptions: {
    textField: ['get', 'id'],
    anchor: 'top',
    offset: [0, -3.9],
    size: 13
  },
  iconOptions: {
    allowOverlap: true,
    ignorePlacement: true
  }
});
map?.layers.add(symbolLayerLabel);

// Toggle visibility function
function togglePinVisibility(pinname: string, visible: boolean) {
  const filter = visible
    ? ['==', ['get', 'id'], pinname] // Show specific pin
    : ['!=', ['get', 'id'], pinname]; // Hide specific pin

  symbolLayer.setOptions({ filter });
  symbolLayerLabel.setOptions({ filter });
}

If you want to toggle visibility for specific pins, use the filter property to hide/show pins by their ID.

symbolLayer.setOptions({
  filter: visible ? ['==', ['get', 'id'], pinname] : ['!=', ['get', 'id'], pinname]
});

symbolLayerLabel.setOptions({
  filter: visible ? ['==', ['get', 'id'], pinname] : ['!=', ['get', 'id'], pinname]
});
  • ['get', 'id']: Retrieves the id property of each shape.
  • Dynamically filters pins based on their id.

Result:

Recognized by Microsoft Azure Collective

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Black flash issue when toggle the visibility of symbol pin on azure map

So, I created a Vue project and added the azure-maps-control

npm install azure-maps-control

added the css in main.ts

import "azure-maps-control/dist/atlas.min.css";

Now, this is how I load the pins once map is ready

const labelId = 'label-'+r.pinname;
await map?.imageSprite.add(labelId, icons.Label.replace("{stroke}", r.pincolor));
await map?.imageSprite.createFromTemplate(r.pinname, 'marker-thick', r.pincolor, '#fff');
const stops = r.stops.map(m => m.coordinates);
stops.forEach(coord => {
  var dataSource = new atlas.source.DataSource();
  map?.sources.add(dataSource);

  var shape = new atlas.Shape(new atlas.data.Point(coord), r.pinname);
  dataSource.add(shape);

  const symbolLayerLabel = new atlas.layer.SymbolLayer(dataSource, '', {
    iconOptions: {
      image: labelId,
      allowOverlap: true,
      ignorePlacement: true
    },
  });
  map?.layers.add(symbolLayerLabel);

  const symbolLayer = new atlas.layer.SymbolLayer(dataSource, '', {
    iconOptions: {
      image: r.pinname,
      allowOverlap: true,
      ignorePlacement: true
    },
    textOptions: {
      allowOverlap: true,
      ignorePlacement: true,
      anchor: 'top',
      textField: r.pinname,
      offset: [0, -3.9],
      size: 13
    }
  });
  map?.layers.add(symbolLayer);

  dataSources.value.push(dataSource);
  symbolLayers.value.push(symbolLayer);
});

Then I created a function to toggle the visibility of that pins

symbolLayers.value.forEach(layer => {
  const opts = layer.getOptions() as LayerOptions;
  if (opts.iconOptions.image==pinname) {
    layer.setOptions({visible: visible});
    return;
  }
});

So there’s a click button on the top left of this screenshot where I use the function for toggle the visibility of pins.

Did I miss anything?

Recognized by Microsoft Azure Collective

3

Black flash issue when toggle the visibility of symbol pin on azure map

The black flash occurs because adding/removing or manipulating layers at scale triggers frequent redraws or re-renders of the map.

You are creating a new DataSource for every pin and two SymbolLayers per pin (one for label and one for the marker), which adds complexity and rendering overhead.

Group all pins under a single DataSource.

  • One layer for the marker icon and one for the label. Instead of adding multiple layers, we filter the shapes using their properties.

Revised code:

const dataSource = new atlas.source.DataSource();
map?.sources.add(dataSource);

// Add all pins to a single DataSource
r.stops.forEach(coord => {
  const shape = new atlas.Shape(new atlas.data.Point(coord), {
    id: r.pinname,
    labelColor: r.pincolor,
    iconColor: r.pincolor
  });
  dataSource.add(shape);
});

// Add SymbolLayer for icons
const symbolLayer = new atlas.layer.SymbolLayer(dataSource, null, {
  iconOptions: {
    image: 'marker-thick',
    allowOverlap: true,
    ignorePlacement: true
  }
});
map?.layers.add(symbolLayer);

// Add SymbolLayer for labels
const symbolLayerLabel = new atlas.layer.SymbolLayer(dataSource, null, {
  textOptions: {
    textField: ['get', 'id'],
    anchor: 'top',
    offset: [0, -3.9],
    size: 13
  },
  iconOptions: {
    allowOverlap: true,
    ignorePlacement: true
  }
});
map?.layers.add(symbolLayerLabel);

// Toggle visibility function
function togglePinVisibility(pinname: string, visible: boolean) {
  const filter = visible
    ? ['==', ['get', 'id'], pinname] // Show specific pin
    : ['!=', ['get', 'id'], pinname]; // Hide specific pin

  symbolLayer.setOptions({ filter });
  symbolLayerLabel.setOptions({ filter });
}

If you want to toggle visibility for specific pins, use the filter property to hide/show pins by their ID.

symbolLayer.setOptions({
  filter: visible ? ['==', ['get', 'id'], pinname] : ['!=', ['get', 'id'], pinname]
});

symbolLayerLabel.setOptions({
  filter: visible ? ['==', ['get', 'id'], pinname] : ['!=', ['get', 'id'], pinname]
});
  • ['get', 'id']: Retrieves the id property of each shape.
  • Dynamically filters pins based on their id.

Result:

Recognized by Microsoft Azure Collective

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật