Пример #1
0
        /// <summary>
        /// Create a default layer for creating a preview to another layer
        /// </summary>
        /// <param name="originalMap">The original map.</param>
        /// <param name="originalLayer">The original layer.</param>
        /// <returns>The created layer object.</returns>
        private layerObj InitializeDefaultLayer(mapObj originalMap, layerObj originalLayer)
        {
            // create a new map object
            map = new mapObj(null);
            map.units = MS_UNITS.MS_PIXELS;
            map.setExtent(0, 0, this.Width, this.Height);
            map.width = this.Width;
            map.height = this.Height;
            outputFormatObj format = originalMap.outputformat;
            if (map.getOutputFormatByName(format.name) == null)
                map.appendOutputFormat(format);
            map.selectOutputFormat(originalMap.imagetype);
            // copy symbolset
            for (int i = 1; i < originalMap.symbolset.numsymbols; i++)
            {
                symbolObj origsym = originalMap.symbolset.getSymbol(i);
                map.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
            }
            // copy the fontset
            string key = null;
            while ((key = originalMap.fontset.fonts.nextKey(key)) != null)
                map.fontset.fonts.set(key, originalMap.fontset.fonts.get(key, ""));
            // setting a default font
            //map.fontset.fonts.set("",
            //    originalMap.fontset.fonts.get(originalMap.fontset.fonts.nextKey(null),""));
            // insert a new layer
            layerObj layer = new layerObj(map);
            if (originalLayer != null)
            {
                // the chart type doesn't support having as single class in it
                if (originalLayer.type == MS_LAYER_TYPE.MS_LAYER_CHART)
                    layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                else
                    layer.type = originalLayer.type;
                originalLayer.open();
                // add the sample feature to the layer
                AddSampleFeature(layer, originalLayer.numitems);
                if (originalLayer.getResults() == null)
                    originalLayer.close(); // close only is no query results
            }
            else
            {
                layer.type = MS_LAYER_TYPE.MS_LAYER_ANNOTATION;
                // add the sample feature to the layer
                AddSampleFeature(layer, 0);
            }
            layer.status = mapscript.MS_ON;

            return layer;
        }