//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Remove a map layer from map's layer collection. * @param mapLayer map layer to be removed. */ public void RemoveMapFeatureLayer(MapFeatureLayer mapLayer) { if (_geoSet != null) { _geoSet.RemoveMapFeatureLayer(mapLayer); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Inserts the specified map layer to map's layer collection at the * specified index. Each map layer in map's layer collection with an index * greater or equal to the specified index is shifted upward to have an * index one greater than the value it had previously. * @param mapLayer the map layer to insert. * @param index where to insert the new map layer. */ public void InsertMapFeatureLayer(MapFeatureLayer mapLayer, int index) { if (_geoSet != null) { _geoSet.InsertMapFeatureLayer(mapLayer, index); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get all records based on given rectangle. * @param rectGeo the boundary.. * @return a hashtable array Contains of all matched record. * the key is the mapInfo ID. the value is the MBR of map object. * @ */ public Hashtable[] Search(GeoLatLngBounds rectGeo) { lock (_mapFeatureLayers) { Hashtable[] retTable = new Hashtable[_mapFeatureLayers.Count]; GeoLatLng pt1 = new GeoLatLng(rectGeo.Y, rectGeo.X); GeoLatLng pt2 = new GeoLatLng(rectGeo.Y + rectGeo.Height, rectGeo.X + rectGeo.Width); double distance = GeoLatLng.Distance(pt1, pt2); if (_mapUnit == MAPUNIT_MILE) { distance /= 1.632; } for (int i = 0; i < _mapFeatureLayers.Count; i++) { MapFeatureLayer mapLayer = (MapFeatureLayer)_mapFeatureLayers[i]; if (mapLayer.CanBeShown(distance)) { retTable[i] = mapLayer.Search(rectGeo); } else { retTable[i] = new Hashtable(); } } return(retTable); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Open the map. * @ */ public void Open() { lock (_mapFeatureLayers) { int layerCount = _mapFeatureLayers.Count; if (layerCount > 0) { ((MapFeatureLayer)_mapFeatureLayers[0]).Open(); _bounds = ((MapFeatureLayer)_mapFeatureLayers[0]).Bounds; } else { _bounds = new GeoLatLngBounds(); } for (int i = 1; i < layerCount; i++) { MapFeatureLayer mapLayer = (MapFeatureLayer)_mapFeatureLayers[i]; mapLayer.Open(); GeoBounds.Union(mapLayer.Bounds, _bounds, _bounds); } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Add a map layer to map's layer collection. * @param mapLayer a layer to be added. */ public void AddMapFeatureLayer(MapFeatureLayer mapLayer) { if (_geoSet != null) { _geoSet.AddMapFeatureLayer(mapLayer); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Remove a map layer from map's layer collection. * @param mapLayer map layer to be removed. */ public void RemoveMapFeatureLayer(MapFeatureLayer mapLayer) { lock (_mapFeatureLayers) { if (_mapFeatureLayers.Contains(mapLayer)) { _mapFeatureLayers.Remove(mapLayer); } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Inserts the specified map layer to map's layer collection at the * specified index. Each map layer in map's layer collection with an index * greater or equal to the specified index is shifted upward to have an * index one greater than the value it had previously. * @param mapLayer the map layer to insert. * @param index where to insert the new map layer. */ public void InsertMapFeatureLayer(MapFeatureLayer mapLayer, int index) { lock (_mapFeatureLayers) { if (!_mapFeatureLayers.Contains(mapLayer)) { _mapFeatureLayers.Insert(index, mapLayer); } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Add a map layer to map's layer collection. * @param mapLayer a map feature layer to be added. */ public void AddMapFeatureLayer(MapFeatureLayer mapLayer) { lock (_mapFeatureLayers) { if (!_mapFeatureLayers.Contains(mapLayer)) { _mapFeatureLayers.Add(mapLayer); } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * return the count of layers in the map. * @param index the index of the map layer. * @return the number of map layers in the map layer collection. */ public MapFeatureLayer GetMapFeatureLayer(int index) { lock (_mapFeatureLayers) { MapFeatureLayer mapLayer = null; if (index >= 0 && index < _mapFeatureLayers.Count) { mapLayer = (MapFeatureLayer)_mapFeatureLayers[index]; } return(mapLayer); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get all records based on given rectangle in give map layer. * @param index the index of given map layer. * @param rectGeo the boundary.. * @return a hashtable of all matched record.the key is the mapInfo ID. * @ */ public Hashtable Search(int index, GeoLatLngBounds rectGeo) { lock (_mapFeatureLayers) { MapFeatureLayer mapLayer = GetMapFeatureLayer(index); if (mapLayer != null) { return(mapLayer.Search(rectGeo)); } return(null); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Close the map. * @ */ public void Close() { lock (_mapFeatureLayers) { int layerCount = _mapFeatureLayers.Count; for (int i = 0; i < layerCount; i++) { MapFeatureLayer mapLayer = (MapFeatureLayer)_mapFeatureLayers[i]; mapLayer.Close(); } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get all records based on search condition in give map layer. * @param index the index of given map layer. * @param findConditions the search condition. * @return a hashtable of all matched record.the key is the mapInfo ID. * @ */ public Hashtable Search(int index, FindConditions findConditions) { lock (_mapFeatureLayers) { MapFeatureLayer mapLayer = GetMapFeatureLayer(index); if (mapLayer != null) { return(mapLayer.Search(findConditions)); } return(null); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Get the map layer collection. * @return the map layer collection. */ public MapFeatureLayer[] GetMapFeatureLayers() { lock (_mapFeatureLayers) { if (_mapFeatureLayers.Count > 0) { MapFeatureLayer[] copiedFeatureLayers = new MapFeatureLayer[_mapFeatureLayers.Count]; _mapFeatureLayers.CopyTo(copiedFeatureLayers); return(copiedFeatureLayers); } } return(null); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get all records based on given string. the seach will search based on * map layer's key field. * @param matchString * @return a hashtable array Contains of all matched record. * the key is the mapInfo ID. the value is the matched string. * @ */ public Hashtable[] Search(string matchString) { lock (_mapFeatureLayers) { Hashtable[] retTable = new Hashtable[_mapFeatureLayers.Count]; for (int i = 0; i < _mapFeatureLayers.Count; i++) { MapFeatureLayer mapLayer = (MapFeatureLayer)_mapFeatureLayers[i]; FindConditions findConditions = new FindConditions(); findConditions.AddCondition(mapLayer.DataTable.GetFieldIndex(mapLayer.KeyField.GetName()), matchString); retTable[i] = mapLayer.Search(findConditions); } return(retTable); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Moves a layer in the Layer collection to change the order in which * layers are drawn. * @param from Index number of the layer to move. The topmost layer is 0. * @param to New location for the layer. For example, if you want it to be * the second layer, use 1 */ public void MoveMapFeatureLayer(int from, int to) { lock (_mapFeatureLayers) { if (from < 0 || from >= _mapFeatureLayers.Count || to < 0 || to >= _mapFeatureLayers.Count) { return; } MapFeatureLayer mapLayerFrom = (MapFeatureLayer)_mapFeatureLayers[from]; MapFeatureLayer mapLayerTo = (MapFeatureLayer)_mapFeatureLayers[to]; _mapFeatureLayers[from] = mapLayerTo; _mapFeatureLayers[to] = mapLayerFrom; } }
//public MapTileVectorDataSource(string url) //{ // Uri = url; // _geoStream = new FileStream(url, FileMode.Open); // byte[] bufferGeo = new byte[_geoStream.Length]; // _geoStream.Read(bufferGeo, 0, bufferGeo.Length); // _geoStream.Close(); // MemoryStream baisGeo = new MemoryStream(bufferGeo); // _getSet = new GeoSet(new BinaryReader(baisGeo)); // string filePath = Path.GetDirectoryName(url); // string[] layerNames = _getSet.GetLayerNames(); // _layerStreams = new FileStream[layerNames.Length]; // for (int i = 0; i < layerNames.Length; i++) // { // string layerName = filePath + "\\" + layerNames[i]; // _layerStreams[i] = new FileStream(layerName, FileMode.Open); // MapFeatureLayer layer = new MapFeatureLayer(new BinaryReader(_layerStreams[i])); // layer.FontColor = 0x000000; // GeoSet.MapFeatureLayerInfo layerInfo = _getSet.GetMapMapFeatureLayerInfo(layerNames[i]); // if (layerInfo != null) // { // layer.ZoomLevel = layerInfo.ZoomLevel; // layer.ZoomMin = layerInfo.ZoomMin; // layer.ZoomMax = layerInfo.ZoomMax; // layer.Description = layerInfo.Description; // layer.Visible = layerInfo.Visible; // layer.LayerName = layerInfo.LayerName; // } // _getSet.AddMapFeatureLayer(layer); // } // _vectorMapRenderer = new VectorMapRenderer(_getSet); // Font font = new Font(FontFamily.GenericSansSerif, 13, FontStyle.Regular); // IFont newFont = MapLayer.GetAbstractGraphicsFactory().CreateFont(font); // _vectorMapRenderer.SetFont(newFont); // _getSet.Open(); //} public MapTileVectorDataSource(string url) { Uri = url; _geoStream = new FileStream(url, FileMode.Open); byte[] bufferGeo = new byte[_geoStream.Length]; _geoStream.Read(bufferGeo, 0, bufferGeo.Length); _geoStream.Close(); MemoryStream baisGeo = new MemoryStream(bufferGeo); _getSet = new GeoSet(); string filePath = @"C:\shenjing\map"; string[] layerNames = new string[] {"3.lyr","1.lyr", "2.lyr" }; _layerStreams = new FileStream[layerNames.Length]; for (int i = 0; i < layerNames.Length; i++) { string layerName = filePath + "\\" + layerNames[i]; _layerStreams[i] = new FileStream(layerName, FileMode.Open); MapFeatureLayer layer = new MapFeatureLayer(new BinaryReader(_layerStreams[i])); layer.FontColor = 0x000000; GeoSet.MapFeatureLayerInfo layerInfo = _getSet.GetMapMapFeatureLayerInfo(layerNames[i]); if (layerInfo != null) { layer.ZoomLevel = layerInfo.ZoomLevel; layer.ZoomMin = layerInfo.ZoomMin; layer.ZoomMax = layerInfo.ZoomMax; layer.Description = layerInfo.Description; layer.Visible = layerInfo.Visible; layer.LayerName = layerInfo.LayerName; } _getSet.AddMapFeatureLayer(layer); } _vectorMapRenderer = new VectorMapRenderer(_getSet); Font font = new Font(FontFamily.GenericSansSerif, 13, FontStyle.Regular); IFont newFont = MapLayer.GetAbstractGraphicsFactory().CreateFont(font); _vectorMapRenderer.SetFont(newFont); _getSet.Open(); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- 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) { } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Get the map layer collection. * @return the map layer collection. */ public MapFeatureLayer[] GetMapFeatureLayers() { lock (_mapFeatureLayers) { if (_mapFeatureLayers.Count > 0) { MapFeatureLayer[] copiedFeatureLayers = new MapFeatureLayer[_mapFeatureLayers.Count]; _mapFeatureLayers.CopyTo(copiedFeatureLayers); return copiedFeatureLayers; } } return null; }