예제 #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Map> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                // Unsubscribe
            }

            if (e.NewElement != null)
            {
                formsMap  = (CommonMap)e.NewElement;
                nativeMap = Control as MapControl;

                routeCoordinates = formsMap.RouteCoordinates;
                lastCoordinates  = formsMap.LastCoordinates;
                positionCount    = formsMap.positionCount;
                refreshRoud      = formsMap.refreshRoud;

                if (formsMap.platformRoad.GetType() == typeof(object))
                {
                    formsMap.platformRoad = new List <BasicGeoposition>();
                }

                wholeRoad = (List <BasicGeoposition>)formsMap.platformRoad;
            }
        }
        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs <Map> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                // Unsubscribe
            }

            if (e.NewElement != null)
            {
                formsMap         = (CommonMap)e.NewElement;
                routeCoordinates = formsMap.RouteCoordinates;
                lastCoordinates  = formsMap.LastCoordinates;
                positionCount    = formsMap.positionCount;
                refreshRoud      = formsMap.refreshRoud;

                if (formsMap.platformRoad.GetType() == typeof(object))
                {
                    formsMap.platformRoad = new PolylineOptions();
                }

                wholeRoad = (PolylineOptions)formsMap.platformRoad;
                Control.GetMapAsync(this);
            }
        }
예제 #3
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                if (nativeMap != null)
                {
                    nativeMap.RemoveOverlays(nativeMap.Overlays);
                    nativeMap.OverlayRenderer = null;
                }
            }

            if (e.NewElement != null)
            {
                formsMap  = (CommonMap)e.NewElement;
                nativeMap = Control as MKMapView;

                routeCoordinates = formsMap.RouteCoordinates;
                lastCoordinates  = formsMap.LastCoordinates;
                positionCount    = formsMap.positionCount;
                refreshRoud      = formsMap.refreshRoud;

                nativeMap.OverlayRenderer = GetOverlayRenderer;
                nativeMap.AddOverlay(new MKPolyline());


                if (formsMap.platformRoad.GetType() == typeof(object))
                {
                    formsMap.platformRoad = new List <CLLocationCoordinate2D>();
                }

                wholeRoad = (List <CLLocationCoordinate2D>)formsMap.platformRoad;
            }
        }
예제 #4
0
파일: MapMaker.cs 프로젝트: ClaireBrill/GPV
    public MapImageData GetImage()
    {
        StringCollection visibleLayers = null;

        if (_appState.VisibleLayers.ContainsKey(_appState.MapTab))
        {
            visibleLayers = _appState.VisibleLayers[_appState.MapTab];
        }

        string keyExtent = _appState.Extent.ToDelimitedString();
        string keySize   = _width.ToString() + "," + _height.ToString();
        string keyLayers = visibleLayers != null?visibleLayers.ToString('|') : "";

        string key = String.Format("{0}|{1}|{2}|{3}|{4}|{5}", _appState.MapTab, _appState.Level, keyExtent, keySize, _resolution, keyLayers);

        CommonImageType imageType = CommonImageType.Png;

        byte[] image = null;

        MapImageData mapImageData = AppContext.ServerImageCache.Retrieve(key);

        if (mapImageData != null)
        {
            imageType = mapImageData.Type;
            image     = mapImageData.Image;
        }

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.FindByMapTabID(_appState.MapTab);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);

        bool isInteractive = !mapTab.IsInteractiveLegendNull() && mapTab.InteractiveLegend == 1;

        // create the base image if not found in the cache

        if (image == null)
        {
            CommonMap map = dataFrame.GetMap(_width, _height, _extent);

            map.Resolution = _resolution;
            map.ImageType  = CommonImageType.Png;

            double pixelSize = map.Extent.Width / _width;

            Dictionary <int, CommonLayer> layerList      = new Dictionary <int, CommonLayer>();
            Dictionary <int, String>      definitionList = new Dictionary <int, String>();
            List <String> mapTabLayerIds = new List <String>();

            foreach (Configuration.MapTabLayerRow mapTabLayer in mapTab.GetMapTabLayerRows())
            {
                Configuration.LayerRow layer = mapTabLayer.LayerRow;
                mapTabLayerIds.Add(layer.LayerID);

                CommonLayer commonLayer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layer.LayerName, true) == 0);
                int         index       = dataFrame.Layers.IndexOf(commonLayer);

                bool visibleAtScale  = commonLayer.IsWithinScaleThresholds(pixelSize);
                bool shownInLegend   = !mapTabLayer.IsShowInLegendNull() && mapTabLayer.ShowInLegend == 1;
                bool checkedInLegend = !isInteractive || mapTabLayer.IsCheckInLegendNull() || mapTabLayer.CheckInLegend < 0 || (visibleLayers != null && visibleLayers.Contains(layer.LayerID));

                bool validLevel = layer.IsLevelFieldNull() || !String.IsNullOrEmpty(_appState.Level);

                if (!layerList.ContainsKey(index) && visibleAtScale && (!shownInLegend || checkedInLegend) && validLevel)
                {
                    if (commonLayer.Type == CommonLayerType.Image)
                    {
                        map.ImageType = CommonImageType.Jpg;
                    }

                    layerList.Add(index, commonLayer);
                    definitionList.Add(index, layer.GetLevelQuery(commonLayer, _appState.Level));
                }
            }

            if (!mapTab.IsBaseMapIDNull())
            {
                foreach (Configuration.LayerRow layer in config.Layer.Where(o => !o.IsBaseMapIDNull() && o.BaseMapID == mapTab.BaseMapID))
                {
                    if (!mapTabLayerIds.Contains(layer.LayerID))
                    {
                        CommonLayer commonLayer = dataFrame.Layers.FirstOrDefault(o => String.Compare(o.Name, layer.LayerName, true) == 0);
                        int         index       = dataFrame.Layers.IndexOf(commonLayer);

                        bool visibleAtScale = commonLayer.IsWithinScaleThresholds(pixelSize);

                        if (!layerList.ContainsKey(index) && visibleAtScale)
                        {
                            if (commonLayer.Type == CommonLayerType.Image)
                            {
                                map.ImageType = CommonImageType.Jpg;
                            }

                            layerList.Add(index, commonLayer);
                            definitionList.Add(index, layer.GetLevelQuery(commonLayer, _appState.Level));
                        }
                    }
                }
            }

            int[] indexes = new int[layerList.Keys.Count];
            layerList.Keys.CopyTo(indexes, 0);
            List <int> indexList = new List <int>(indexes);
            indexList.Sort();

            for (int i = 0; i < indexList.Count; ++i)
            {
                map.AddLayer(layerList[indexList[i]], definitionList[indexList[i]]);
            }

            imageType = map.ImageType;
            image     = map.GetImageBytes();

            AppContext.ServerImageCache.Store(key, new MapImageData(imageType, image));
        }


        // draw the selected feature graphics and markup

        if (_appState.TargetIds.Count > 0 || _appState.SelectionIds.Count > 0 || _appState.MarkupGroups.Count > 0 || _appState.Markup.Count > 0)
        {
            Bitmap bitmap = new Bitmap(new MemoryStream(image));
            bitmap.SetResolution(dataFrame.Dpi, dataFrame.Dpi);
            Graphics graphics = Graphics.FromImage(bitmap);

            if (_appState.TargetIds.Count > 0 || _appState.SelectionIds.Count > 0)
            {
                StringCollection targetIds;
                StringCollection filteredIds;
                StringCollection selectionIds;

                PrepareIds(out targetIds, out filteredIds, out selectionIds);

                DrawFeatures(graphics, _appState.TargetLayer, filteredIds, AppSettings.FilteredColor, AppSettings.FilteredOpacity, AppSettings.FilteredPolygonMode, AppSettings.FilteredPenWidth, AppSettings.FilteredDotSize);
                DrawFeatures(graphics, _appState.SelectionLayer, selectionIds, AppSettings.SelectionColor, AppSettings.SelectionOpacity, AppSettings.SelectionPolygonMode, AppSettings.SelectionPenWidth, AppSettings.SelectionDotSize);
                DrawFeatures(graphics, _appState.TargetLayer, targetIds, AppSettings.TargetColor, AppSettings.TargetOpacity, AppSettings.TargetPolygonMode, AppSettings.TargetPenWidth, AppSettings.TargetDotSize);
                DrawFeatures(graphics, _appState.TargetLayer, _appState.ActiveMapId, AppSettings.ActiveColor, AppSettings.ActiveOpacity, AppSettings.ActivePolygonMode, AppSettings.ActivePenWidth, AppSettings.ActiveDotSize);

                IGeometry selectionBuffer = _appState.SelectionManager.GetSelectionBuffer();

                if (selectionBuffer != null)
                {
                    Brush bufferBrush = new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * AppSettings.BufferOpacity), AppSettings.BufferColor));
                    Pen   bufferPen   = AppSettings.BufferOutlineOpacity > 0 ? new Pen(new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * AppSettings.BufferOutlineOpacity), AppSettings.BufferOutlineColor)), AppSettings.BufferOutlinePenWidth) : null;

                    switch (selectionBuffer.OgcGeometryType)
                    {
                    case OgcGeometryType.Polygon:
                        DrawPolygon(graphics, (IPolygon)selectionBuffer, bufferBrush, null, bufferPen);
                        break;

                    case OgcGeometryType.MultiPolygon:
                        DrawMultiPolygon(graphics, (IMultiPolygon)selectionBuffer, bufferBrush, null, bufferPen);
                        break;
                    }
                }
            }

            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            DrawMarkup(graphics);

            MemoryStream memoryStream = new MemoryStream();

            if (imageType == CommonImageType.Jpg)
            {
                ImageCodecInfo    imageCodecInfo    = GetEncoderInfo("image/jpeg");
                EncoderParameters encoderParameters = new EncoderParameters(1);
                encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 85L);
                bitmap.Save(memoryStream, imageCodecInfo, encoderParameters);
            }
            else
            {
                bitmap.Save(memoryStream, bitmap.RawFormat);
            }

            image = memoryStream.ToArray();
        }

        return(new MapImageData(imageType, image));
    }