//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get MapFeature at given mapInfoID. * @param mapInfoID the index of the record(MapInfoID). * @return MapFeature at given mapInfoID. */ public MapFeature GetMapFeatureByID(int mapInfoID) { MapFeature mapFeature; int mapObjectIDKey = mapInfoID; if (_mapObjectCache.ContainsKey(mapObjectIDKey)) { mapFeature = (MapFeature)_mapObjectCache[mapObjectIDKey]; } else { mapFeature = new MapFeature(); mapFeature.MapInfoID = mapInfoID; mapFeature.MapObject = GetMapObjectByID(mapInfoID); mapFeature.DataRowValue = GetDataRowValueByID(mapInfoID); mapFeature.MapObject.Name = mapFeature.DataRowValue.GetString(_keyFieldIndex); StoreToCache(mapObjectIDKey, mapFeature); } return(mapFeature); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Store the mapFeature to cache. * @param mapObjectIDKey the mapInfo ID key. * @param mapFeature the map feature to be cached. */ private void StoreToCache(int mapObjectIDKey, MapFeature mapFeature) { if (_mapObjectCache.Count >= CACHE_SIZE) { MapFeature[] mapFeatures = new MapFeature[CACHE_SIZE]; ICollection enuValues = _mapObjectCache.Values; int index = 0; foreach (var o in enuValues) { mapFeatures[index++] = (MapFeature)o; } SortMapFeature(mapFeatures); for (int i = 0; i < CACHE_SIZE / 2; i++) { int deleteMapObjectID = mapFeatures[i].MapInfoID; _mapObjectCache.Remove(deleteMapObjectID); } } _mapObjectCache.Add(mapObjectIDKey, mapFeature); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * sort the map feature array. */ private static void SortMapFeature(MapFeature[] mapFeatures) { int n = mapFeatures.Length; int i, j; MapFeature ai; for (i = 1; i < n; i++) { j = i - 1; ai = mapFeatures[i]; while (mapFeatures[j].MapObject.CacheAccessTime > ai.MapObject.CacheAccessTime) { mapFeatures[j + 1] = mapFeatures[j]; j--; if (j < 0) break; } mapFeatures[j + 1] = ai; } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get MapFeature at given mapInfoID. * @param mapInfoID the index of the record(MapInfoID). * @return MapFeature at given mapInfoID. */ public MapFeature GetMapFeatureByID(int mapInfoID) { MapFeature mapFeature; int mapObjectIDKey = mapInfoID; if (_mapObjectCache.ContainsKey(mapObjectIDKey)) { mapFeature = (MapFeature)_mapObjectCache[mapObjectIDKey]; } else { mapFeature = new MapFeature(); mapFeature.MapInfoID = mapInfoID; mapFeature.MapObject = GetMapObjectByID(mapInfoID); mapFeature.DataRowValue = GetDataRowValueByID(mapInfoID); mapFeature.MapObject.Name = mapFeature.DataRowValue.GetString(_keyFieldIndex); StoreToCache(mapObjectIDKey, mapFeature); } return mapFeature; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * @inheritDoc */ public override void GetImage(int mtype, int x, int y, int zoomLevel) { lock (VectorMapAbstractCanvas.GRAPHICS_MUTEX) { int shiftWidth = 32; GeoPoint pt1 = new GeoPoint(x * MapLayer.MAP_TILE_WIDTH - shiftWidth, y * MapLayer.MAP_TILE_WIDTH - shiftWidth); GeoPoint pt2 = new GeoPoint((x + 1) * MapLayer.MAP_TILE_WIDTH + shiftWidth, (y + 1) * MapLayer.MAP_TILE_WIDTH + shiftWidth); GeoLatLng latLng1 = MapLayer.FromPixelToLatLng(pt1, zoomLevel); GeoLatLng latLng2 = MapLayer.FromPixelToLatLng(pt2, zoomLevel); double minY = Math.Min(latLng1.Lat(), latLng2.Lat()); double maxY = Math.Max(latLng1.Lat(), latLng2.Lat()); double minX = Math.Min(latLng1.Lng(), latLng2.Lng()); double maxX = Math.Max(latLng1.Lng(), latLng2.Lng()); double width = 0.00; double height = 0.00; //width = width < 0.06 ? 0.06 : width; //height = height < 0.06 ? 0.06 : height; GeoLatLngBounds geoBounds = new GeoLatLngBounds(minX - width / 2.0, minY - height / 2.0, maxX - minX + width, maxY - minY + height); try { Hashtable[] mapFeatures = _geoSet.Search(geoBounds); int totalSize = 0; for (int i = 0; i < mapFeatures.Length; i++) { Hashtable mapFeaturesInLayer = mapFeatures[i]; totalSize += mapFeaturesInLayer.Count; } totalSize += 1; int mapObjectIndex = 0; _vectorMapCanvas.ClearCanvas(0xffffff); for (int i = 0; i < mapFeatures.Length; i++) { int zOrder = mapFeatures.Length - 1 - i; Hashtable mapFeaturesInLayer = mapFeatures[zOrder]; ICollection enuKeys = mapFeaturesInLayer.Keys; MapFeatureLayer mapLayer = _geoSet.GetMapFeatureLayer(zOrder); foreach (var o in enuKeys) { int mapInfoID = (int)o; MapFeature mapFeature = mapLayer .GetMapFeatureByID(mapInfoID); mapObjectIndex++; _vectorMapCanvas.SetFont(GetFont(mapLayer.FontName)); _vectorMapCanvas.SetFontColor(mapLayer.FontColor); _vectorMapCanvas.DrawMapObject(mapFeature.MapObject, geoBounds, zoomLevel); if (_readListener != null) { _readListener.readProgress(mapObjectIndex, totalSize); } } } _vectorMapCanvas.DrawMapText(); ImageArray = PNGEncoder.GetPngrgb(MapLayer.MAP_TILE_WIDTH, MapLayer.MAP_TILE_WIDTH, _vectorMapCanvas.GetRGB()); ImageArraySize = ImageArray.Length; IsImagevalid = true; if (ImageArraySize == 1933) { ImageArray = null; IsImagevalid = false; ImageArraySize = 0; } if (_readListener != null) { _readListener.readProgress(totalSize, totalSize); } } catch (Exception e) { } } }