//------------------------------------------------------------------------ private void MouseDownAddLine(EarthMouseEventArgs args) { args.IsProcessed = true; if (args.Buttons == System.Windows.Forms.MouseButtons.Left) { if (m_lineEnCoursEdition == null) { m_lineEnCoursEdition = new CGPSLine(m_carteEditee.ContexteDonnee); m_lineEnCoursEdition.CreateNewInCurrentContexte(); m_lineEnCoursEdition.Libelle = I.T("New line|20056"); m_lineEnCoursEdition.Carte = m_carteEditee; CGPSLineTrace trace = m_lineEnCoursEdition.DetailLigne; trace.PointDepart = new SLatLong(args.Latitude, args.Longitude); TreeNode node = new TreeNode(); FillNode(node, m_lineEnCoursEdition); m_arbreCartographie.Nodes[0].Nodes.Add(node); m_arbreCartographie.SelectedNode = node; m_wndMap.ShowMouseMarker(args.Latitude, args.Longitude); } else { CGPSLineSegment segment = new CGPSLineSegment(m_lineEnCoursEdition.DetailLigne); segment.PointDestination = new SLatLong(args.Latitude, args.Longitude); CGPSLineTrace trace = m_lineEnCoursEdition.DetailLigne; if (trace.Segments.Count() > 0) { CGPSLineSegment lastSeg = trace.Segments.ElementAt(trace.Segments.Count() - 1); segment.Width = lastSeg.Width; segment.Couleur = lastSeg.Couleur; } m_wndMap.ShowMouseMarker(args.Latitude, args.Longitude); trace.AddSegment(segment); foreach (IMapItem item in m_lineEnCoursEdition.FindMapItems(m_mapDatabase)) { item.Layer.RemoveItem(item); m_wndMap.DeleteItem(item); } foreach (IMapItem item in m_lineEnCoursEdition.CreateMapItems(m_mapDatabase.GetLayer(m_carteEditee.IdUniversel, true))) { m_wndMap.AddMapItem(item); } TreeNode node = FindNode(m_lineEnCoursEdition); if (node != null) { FillNode(node, m_lineEnCoursEdition); } node = FindNode(segment); if (node != null) { m_arbreCartographie.SelectedNode = node; } } } }
//-------------------------------------------------------------------- public IEnumerable <CMapLayer> GenereItems(CMapDatabase database) { List <CMapLayer> lstLayers = new List <CMapLayer>(); CMapLayer layer = database.GetLayer(IdUniversel, true); layer.ClearItems(); lstLayers.Add(layer); foreach (IElementDeGPSCarte element in ElementsDeCarte) { element.CreateMapItems(layer); } return(lstLayers); }
//----------------------------------------------- private void ShowLayers() { int nZOrder = 0; foreach (CRuntimeConfigMapView runtime in GetRuntimesOrdered()) { CMapLayer layer = m_mapDatabase.GetLayer(runtime.Generator.LayerId); if (runtime.IsVisible) { if (!runtime.IsCalculated) { if (layer != null) { layer.ClearItems(); } using (sc2i.win32.common.CWaitCursor waiter = new sc2i.win32.common.CWaitCursor()) { runtime.Generator.ElementEdite = m_objetSource; runtime.Generator.FillMapDatabase(m_objetSource, m_mapDatabase, runtime.Generator.ContexteDonnee); runtime.IsCalculated = true; if (runtime.Generator.ExecuteurAction != m_executeActionDelegate) { runtime.Generator.ExecuteurAction = m_executeActionDelegate; } } } if (layer != null) { layer.IsVisible = true; } } else if (layer != null) { layer.IsVisible = false; } if (layer != null) { layer.ZOrder = nZOrder++; } } foreach (CGPSCarte carte in m_listeCartes) { carte.GenereItems(m_mapDatabase); } SetMapDatabase(m_mapDatabase); }
//------------------------------------------------------------- public CResultAErreur GenereItems(CMapDatabase database, CContexteDonnee ctxDonnee) { CResultAErreur result = CResultAErreur.True; //Calcule les éléments à générer if (Filtre == null || Filtre.TypeElements == null) { return(result); } if (FormuleLatitude1 == null || FormuleLongitude1 == null || FormuleLatitude2 == null || FormuleLatitude2 == null) { return(result); } result = Filtre.GetFiltreData(); if (!result) { return(result); } CFiltreData filtre = result.Data as CFiltreData; CListeObjetsDonnees lstObjets = new CListeObjetsDonnees(ctxDonnee, Filtre.TypeElements); lstObjets.Filtre = filtre; lstObjets.ModeSansTri = true; CMapLayer layer = null; if (lstObjets.Count > 0) { layer = database.GetLayer(Generator.LayerId, true); } else { return(result); } Dictionary <int, double> dicValeursLatitude = new Dictionary <int, double>(); Dictionary <int, double> dicValeursLongitude = new Dictionary <int, double>(); foreach (object obj in lstObjets) { DateTime dt = DateTime.Now; m_currentGeneratedItem = obj; CContexteEvaluationExpression ctxEval = new CContexteEvaluationExpression(obj); double?fLat1 = null; double?fLong1 = null; double?fLat2 = null; double?fLong2 = null; result = FormuleLatitude1.Eval(ctxEval); if (result) { try { fLat1 = Convert.ToDouble(result.Data); } catch { } } if (fLat1 != null) { result = FormuleLongitude1.Eval(ctxEval); if (result) { try { fLong1 = Convert.ToDouble(result.Data); } catch { } } } if (fLat1 != null && fLong1 != null) { result = FormuleLatitude2.Eval(ctxEval); if (result) { try { fLat2 = Convert.ToDouble(result.Data); } catch { } } } if (fLat1 != null && fLong1 != null && fLat2 != null) { result = FormuleLongitude2.Eval(ctxEval); if (result) { try { fLong2 = Convert.ToDouble(result.Data); } catch { } } } TimeSpan sp = DateTime.Now - dt; if (obj is CObjetDonnee) { //Console.WriteLine("Coord "+((CObjetDonnee)obj).DescriptionElement + " : " + sp.TotalMilliseconds); } if (fLat1 != null && fLat2 != null && fLong1 != null && fLong2 != null) { foreach (CMapLineDessin mapLineDessin in LinesDessin) { if (mapLineDessin.GenereItem( obj, fLat1.Value, fLong1.Value, fLat2.Value, fLong2.Value, layer)) { break; } } } sp = DateTime.Now - dt; if (obj is CObjetDonnee) { //Console.WriteLine(((CObjetDonnee)obj).DescriptionElement + " : " + sp.TotalMilliseconds); } } return(result); }
//------------------------------------------------------------- public CResultAErreur GenereItems(CMapDatabase database, CContexteDonnee ctxDonnee) { CResultAErreur result = CResultAErreur.True; //Calcule les éléments à générer if (Filtre == null || Filtre.TypeElements == null) { return(result); } if (FormuleLatitude == null || FormuleLongitude == null) { return(result); } result = Filtre.GetFiltreData(); if (!result) { return(result); } CFiltreData filtre = result.Data as CFiltreData; CListeObjetsDonnees lstObjets = new CListeObjetsDonnees(ctxDonnee, Filtre.TypeElements); lstObjets.Filtre = filtre; lstObjets.ModeSansTri = true; CMapLayer layer = null; if (lstObjets.Count > 0) { layer = database.GetLayer(Generator.LayerId, true); } else { return(result); } int?nIdChampLatitude = null; int?nIdChampLongitude = null; Dictionary <int, double> dicValeursLatitude = new Dictionary <int, double>(); Dictionary <int, double> dicValeursLongitude = new Dictionary <int, double>(); if (typeof(IObjetDonneeAChamps).IsAssignableFrom(lstObjets.TypeObjets)) { nIdChampLatitude = GetIdChampOptimFromFormule(FormuleLatitude); nIdChampLongitude = GetIdChampOptimFromFormule(FormuleLongitude); List <int> lst = new List <int>(); if (nIdChampLatitude != null) { lst.Add(nIdChampLatitude.Value); } if (nIdChampLongitude != null) { lst.Add(nIdChampLongitude.Value); } if (lst.Count > 0) { CUtilElementAChamps.ReadChampsCustom(lstObjets, lst.ToArray()); } DataTable table = ctxDonnee.Tables[((IObjetDonneeAChamps)lstObjets[0]).GetNomTableRelationToChamps()]; if (table != null && (nIdChampLatitude != null || nIdChampLatitude != null)) { string strCle = ((CObjetDonneeAIdNumerique)lstObjets[0]).GetChampId(); string strFiltre = ""; if (nIdChampLatitude != null) { strFiltre = CChampCustom.c_champId + "=" + nIdChampLatitude.Value; } if (nIdChampLongitude != null) { if (strFiltre.Length > 0) { strFiltre += " or "; } strFiltre += CChampCustom.c_champId + "=" + nIdChampLongitude.Value; } DataRow[] rows = table.Select(strFiltre); foreach (DataRow row in table.Rows) { if ((int)row[CChampCustom.c_champId] == nIdChampLatitude) { dicValeursLatitude[(int)row[strCle]] = (double)row[CRelationElementAChamp_ChampCustom.c_champValeurDouble]; } else if ((int)row[CChampCustom.c_champId] == nIdChampLongitude) { dicValeursLongitude[(int)row[strCle]] = (double)row[CRelationElementAChamp_ChampCustom.c_champValeurDouble]; } } } } else { nIdChampLatitude = null; nIdChampLongitude = null; } foreach (object obj in lstObjets) { DateTime dt = DateTime.Now; m_currentGeneratedItem = obj; CContexteEvaluationExpression ctxEval = new CContexteEvaluationExpression(obj); double?fLat = null; double?fLong = null; if (nIdChampLatitude != null) { double fTmp = 0; if (dicValeursLatitude.TryGetValue(((CObjetDonneeAIdNumerique)obj).Id, out fTmp)) { fLat = fTmp; } } else { result = FormuleLatitude.Eval(ctxEval); if (result) { try { fLat = Convert.ToDouble(result.Data); } catch { } } } if (fLat != null) { if (nIdChampLongitude != null) { double fTmp = 0; if (dicValeursLongitude.TryGetValue(((CObjetDonneeAIdNumerique)obj).Id, out fTmp)) { fLong = fTmp; } } else { result = FormuleLongitude.Eval(ctxEval); if (result) { try { fLong = Convert.ToDouble(result.Data); } catch { } } } } TimeSpan sp = DateTime.Now - dt; if (obj is CObjetDonnee) { //Console.WriteLine("Coord "+((CObjetDonnee)obj).DescriptionElement + " : " + sp.TotalMilliseconds); } if (fLong != null && fLat != null) { foreach (CMapItemDessin mapItemDessin in ItemsDessin) { if (mapItemDessin.GenereItem( obj, fLat.Value, fLong.Value, layer)) { break; } } } sp = DateTime.Now - dt; if (obj is CObjetDonnee) { //Console.WriteLine(((CObjetDonnee)obj).DescriptionElement + " : " + sp.TotalMilliseconds); } } return(result); }
//--------------------------------------------- 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); }