Dynamic display
CustomLayerBase.cpp
// Copyright 2011 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

  
  
#include <stdio.h>
#include <iostream>
#include "CustomLayerBase.h"
  
extern "C" const GUID CLSID_TemporalFeatureLayer={0x3334ce40,0x1a1d,0x11d5,{0xb7,0xcf,0x00,0x01,0x02,0x65,0xad,0xc5}};
  
CustomLayerBase::CustomLayerBase():
  m_MinScale(0),
  m_MaxScale(0),
  m_Visibile(VARIANT_TRUE),
  m_ShowTips(VARIANT_FALSE),
  m_Cache(VARIANT_FALSE),
  m_RefCount(0)
{
  m_ipExtent.CreateInstance(CLSID_Envelope);
  m_ipExtent->SetEmpty();
    
  m_SpatialRef.CreateInstance(CLSID_UnknownCoordinateSystem);  
}
  
CustomLayerBase::~CustomLayerBase()
{
  m_RefCount = 0;
}
  
// IUnknown
HRESULT CustomLayerBase::QueryInterface(REFIID riid, void** ppv) 
{
  if      (IsEqualIID(riid,IID_IUnknown     )) *ppv = static_cast<IUnknown*>    ( (IGeoDataset*)(this));
  else if (IsEqualIID(riid,IID_IDynamicLayer)) *ppv = static_cast<IDynamicLayer*>(this);
  else if (IsEqualIID(riid,IID_ILayer       )) *ppv = static_cast<ILayer       *>(this);
  else if (IsEqualIID(riid,IID_IGeoDataset  )) *ppv = static_cast<IGeoDataset  *>(this);
  else
  {
    *ppv = 0;
    return E_NOINTERFACE;;
  }
  
  AddRef();
  return S_OK;
}
  
ULONG CustomLayerBase::AddRef()  
{ 
  m_RefCount++; 
  return m_RefCount;
}
  
ULONG CustomLayerBase::Release() 
{ 
  m_RefCount--;
  int refCount = m_RefCount;
  if (refCount == 0)
    delete this;
      
  return refCount;
}
  
// IGeoDataset
HRESULT CustomLayerBase::get_Extent(IEnvelope** Extent)
{
  if(!Extent)
    return E_POINTER;

  *Extent = m_ipExtent;
  (*Extent)->AddRef();

  return S_OK;
}
  
HRESULT CustomLayerBase::get_SpatialReference(ISpatialReference** SpatialReference)
{
  if (!SpatialReference)
    return E_POINTER;

  *SpatialReference = m_SpatialRef;
  (*SpatialReference)->AddRef();
  return S_OK;
}
  
// ILayer
HRESULT CustomLayerBase::get_Name(BSTR* Name) 
{ 
  if (Name == NULL)
    return E_POINTER;    
    
  *Name = m_bstrNomeLyr.Copy();
  
  return S_OK; 
}
  
HRESULT CustomLayerBase::put_Name(BSTR Name) 
{ 
  m_bstrNomeLyr = Name;
  return S_OK; 
}
  
HRESULT CustomLayerBase::get_Valid(VARIANT_BOOL* Valid) 
{
  *Valid = VARIANT_TRUE;   
  return S_OK; 
}
  
HRESULT CustomLayerBase::get_AreaOfInterest(IEnvelope** aoi) 
{ 
  if (aoi == NULL)
    return E_POINTER;
      
  *aoi = m_ipExtent; 
  (*aoi)->AddRef();
          
  return S_OK;
}
  
HRESULT CustomLayerBase::get_MinimumScale(double* MinScale) 
{ 
  if (!MinScale)
    return E_POINTER;

  *MinScale = m_MinScale;

  return S_OK; 
}
  
HRESULT CustomLayerBase::put_MinimumScale(double MinScale) 
{ 
  m_MinScale = MinScale;

  return S_OK; 
}
  
HRESULT CustomLayerBase::get_MaximumScale(double* MaxScale) 
{ 
  if (!MaxScale)
    return E_POINTER;

  *MaxScale = m_MaxScale;

  return S_OK; 
}
  
HRESULT CustomLayerBase::put_MaximumScale(double MaxScale) 
{ 
  m_MaxScale = MaxScale;

  return S_OK; 
}
  
HRESULT CustomLayerBase::get_Visible(VARIANT_BOOL* Visible) 
{
  if (Visible == NULL)
    return E_POINTER;
     
  *Visible = m_Visibile;  
  return S_OK; 
}
  
HRESULT CustomLayerBase::put_Visible(VARIANT_BOOL Visible)
{ 
  m_Visibile = Visible;

  return S_OK; 
}
  
HRESULT CustomLayerBase::get_ShowTips(VARIANT_BOOL* show)
{ 
  if (!show)
    return E_POINTER;

  *show = m_ShowTips;

  return S_OK; 
}
  
HRESULT CustomLayerBase::put_ShowTips(VARIANT_BOOL show)
{ 
  show = m_ShowTips;

  return S_OK; 
}
  
HRESULT CustomLayerBase::get_TipText(double x, double y, double Tolerance, BSTR* Text) 
{ 
  if (Text == NULL)
    return E_POINTER;

  *Text = NULL;
  
  return S_OK;
}
  
HRESULT CustomLayerBase::get_Cached(VARIANT_BOOL* Cached) 
{ 
  if (!Cached)
    return E_POINTER;

  *Cached = m_Cache;

  return S_OK; 
}
  
HRESULT CustomLayerBase::put_Cached(VARIANT_BOOL Cached) 
{ 

  m_Cache = Cached;  

  return S_OK; 
}

HRESULT CustomLayerBase::get_SupportedDrawPhases(long* drawPhases) 
{ 
  if (!drawPhases)
    return E_POINTER;

  *drawPhases = esriDPGeography;
    
  return S_OK; 
}
  
HRESULT CustomLayerBase::putref_SpatialReference(ISpatialReference* pSpRef) 
{ 
  m_SpatialRef = pSpRef;
  return S_OK; 
}
  
HRESULT CustomLayerBase::Draw(esriDrawPhase DrawPhase, IDisplay* Display, ITrackCancel* TrackCancel) 
{ 
  return S_OK;
}