//--------------------------------------------------------------------------- public bool GenereItem( object obj, double fLat, double fLong, CMapLayer layer) { CResultAErreur result = CResultAErreur.True; CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(this.m_mapItemGenerator); if (FormuleCondition != null && !(FormuleCondition is C2iExpressionVrai)) { result = FormuleCondition.Eval(ctx); if (!result || result.Data == null) { return(false); } bool?bResult = CUtilBool.BoolFromString(result.Data.ToString()); if (bResult == null || !bResult.Value) { return(false); } } string strLibelle = ""; if (FormuleToolTip != null) { result = FormuleToolTip.Eval(ctx); if (result && result.Data != null) { strLibelle = result.Data.ToString(); } } IMapItem item = null; if (MarkerType != EMapMarkerType.none) { item = new CMapItemSimple(layer, fLat, fLong, MarkerType); } else if (Image != null) { if (layer.Database.GetImage(m_strImageId) == null) { layer.Database.AddImage(m_strImageId, Image); } item = new CMapItemImage(layer, fLat, fLong, m_strImageId); } else { item = new CMapItemSimple(layer, fLat, fLong, EMapMarkerType.green); } item.Tag = obj; item.ToolTip = strLibelle; item.PermanentToolTip = PermanentToolTip; if (ItemGenerator.ActionSurClick != null) { item.MouseClicked += new MapItemClickEventHandler(OnMouseClick); } return(true); }
//------------------------------------------------------------------ public CWin32MapItemGoogleStd(CMapItemSimple item) : base(new PointLatLng(item.Latitude, item.Longitude), GetGoogleType(item.SimpleMarkerType)) { m_item = item; ToolTipText = item.ToolTip; if (!item.PermanentToolTip) { ToolTipMode = MarkerTooltipMode.OnMouseOver; } else { ToolTipMode = MarkerTooltipMode.Always; } }
//--------------------------------------------------------------------------- public IEnumerable <IMapItem> UpdateMapItems(CMapDatabase database, List <IMapItem> itemsToDelete) { CMapItemPoint mapItem = database.FindItemFromTag(this) as CMapItemPoint; if (mapItem != null) { CMapLayer layer = mapItem.Layer; //Vérifie le type du mapItem if (TypePoint != null && TypePoint.Image != null) { if (!(mapItem is CMapItemImage)) { itemsToDelete.Add(mapItem); mapItem.Layer.RemoveItem(mapItem); layer.Database.AddImage(TypePoint.IdUniversel, TypePoint.Image); mapItem = new CMapItemImage(layer, Latitude, Longitude, TypePoint.IdUniversel); } ((CMapItemImage)mapItem).ImageId = TypePoint.IdUniversel; } else { if (!(mapItem is CMapItemSimple)) { itemsToDelete.Add(mapItem); mapItem.Layer.RemoveItem(mapItem); mapItem = new CMapItemSimple(layer, Latitude, Longitude, MarkerType); } ((CMapItemSimple)mapItem).SimpleMarkerType = MarkerType == EMapMarkerType.none?EMapMarkerType.blue_dot:MarkerType; } mapItem.Tag = this; mapItem.Latitude = Latitude; mapItem.Longitude = Longitude; mapItem.ToolTip = Libelle; mapItem.PermanentToolTip = PermanentToolTip; return(new IMapItem[] { mapItem }); } return(new IMapItem[0]); }
//--------------------------------------------------------------------------- public IEnumerable <IMapItem> CreateMapItems(CMapLayer layer) { CMapItemPoint point = null; if (MarkerType == EMapMarkerType.none) { if (TypePoint != null && TypePoint.Image != null) { layer.Database.AddImage(TypePoint.IdUniversel, TypePoint.Image); point = new CMapItemImage(layer, Latitude, Longitude, TypePoint.IdUniversel); } } if (point == null) { EMapMarkerType type = MarkerType == EMapMarkerType.none ? EMapMarkerType.blue_dot : MarkerType; point = new CMapItemSimple(layer, Latitude, Longitude, type); } point.ToolTip = Libelle; point.PermanentToolTip = PermanentToolTip; point.Tag = this; return(new IMapItem[] { point }); }
//--------------------------------------------- public CResultAErreur GenereItems(CMapDatabase database, CContexteDonnee ctxDonnee) { CResultAErreur result = CResultAErreur.True; //Calcule les éléments à générer DataTable table = Query.GetTable(NomTableSource, m_listeSources); double? fLastLat = null; double? fLastLong = null; CMapLayer layer = database.GetLayer(Generator.LayerId, true); if (table != null) { DataColumn colLat = null; DataColumn colLong = null; DataColumn colLib = null; DataColumn colElt = null; foreach (DataColumn col in table.Columns) { if (col.ColumnName == ChampCleElement) { colElt = col; } if (col.ColumnName == ChampLatitude) { colLat = col; } if (col.ColumnName == ChampLibelle) { colLib = col; } if (col.ColumnName == ChampLongitude) { colLong = col; } } if (colLong == null || colLat == null) { result.EmpileErreur(I.T("Can not find columns @1 and @2 in data source|20024", ChampLongitude, ChampLatitude)); } Dictionary <object, List <DataRow> > dicRowsParElement = new Dictionary <object, List <DataRow> >(); if (colElt != null) { object lastElt = null; List <DataRow> lstRows = null; foreach (DataRow row in table.Rows) { object v = row[colElt]; if (v != lastElt || lstRows == null) { lastElt = v; if (!dicRowsParElement.TryGetValue(v, out lstRows)) { lstRows = new List <DataRow>(); dicRowsParElement[v] = lstRows; } } lstRows.Add(row); } } else { List <DataRow> lstRows = new List <DataRow>(); foreach (DataRow row in table.Rows) { lstRows.Add(row); } dicRowsParElement[DBNull.Value] = lstRows; } foreach (KeyValuePair <object, List <DataRow> > kv in dicRowsParElement) { List <DataRow> lstRows = kv.Value; List <SLatLong> lstPoints = new List <SLatLong>(); int nNb = kv.Value.Count; int nIndex = 0; foreach (DataRow row in kv.Value) { try { double fLat = Convert.ToDouble(row[colLat]); double fLong = Convert.ToDouble(row[colLong]); string strLabel = colLib != null ?row[colLib] as string:null; if (strLabel == null || strLabel.Length == 0) { strLabel = ""; } bool bPrendre = true; if (strLabel == "" && fLastLong != null && fLastLat != null && MetresEntrePoints > 0) { //contrôle la distance double fDist = GetGpsDist(fLastLong.Value, fLong, fLastLat.Value, fLat); bPrendre = fDist >= MetresEntrePoints; } if (nIndex == nNb - 1) { bPrendre = true; } if (bPrendre) { fLastLat = fLat; fLastLong = fLong; SLatLong pt = new SLatLong(fLat, fLong); lstPoints.Add(pt); } if (strLabel != null && strLabel.Trim().Length > 0) { CMapItemSimple item = new CMapItemSimple(layer, fLat, fLong, EMapMarkerType.blue_dot); item.ToolTip = strLabel; layer.AddItem(item); } } catch { } } CMapItemPath path = new CMapItemPath(layer); path.Points = lstPoints.ToArray(); layer.AddItem(path); } } return(result); }