示例#1
0
        /// <summary>
        /// Creating a new map.
        /// </summary>
        /// <returns>The wrapper containing the newly created map object.</returns>
        public static MapObjectHolder CreateMap()
        {
            mapObj map = new mapObj(null);

            map.setExtent(0, 0, 100, 100);
            return(new MapObjectHolder(map, null));
        }
示例#2
0
        /// <summary>
        /// Click event handler of the buttonApply control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonApply_Click(object sender, EventArgs e)
        {
            double deltaX  = (map.extent.maxx - map.extent.minx) * zoomFactor / 2;
            double deltaY  = (map.extent.maxy - map.extent.miny) * zoomFactor / 2;
            double centerX = double.Parse(textBoxX.Text);
            double centerY = double.Parse(textBoxY.Text);

            map.setExtent(centerX - deltaX, centerY - deltaY, centerX + deltaX, centerY + deltaY);

            target.RaisePropertyChanged(this);

            double zoom = (map.extent.maxx - map.extent.minx);

            if (mapunits != map.units)
            {
                zoom = zoom * MapUtils.InchesPerUnit(map.units) / MapUtils.InchesPerUnit(mapunits);
            }

            target.RaiseZoomChanged(this, Math.Round(zoom, unitPrecision), map.scaledenom);

            zoomFactor = 1.0;
        }
示例#3
0
 public void Apply(mapObj map)
 {
     map.setExtent(minx, miny, maxx, maxy);
 }
示例#4
0
        /// <summary>
        /// Export a legend image with specific requirements (bug 1015)
        /// </summary>
        /// <param name="map">The map object</param>
        /// <param name="width">The desired legend width</param>
        /// <param name="height">The desired legend height</param>
        /// <returns></returns>
        public static byte[] ExportLegend(mapObj map)
        {
            int      width  = 10;
            int      height = 10;
            Bitmap   bmp    = null;
            Graphics g      = null;

            for (int phase = 0; phase < 2; phase++)
            {
                if (phase == 0)
                {
                    bmp = new Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                }
                else
                {
                    bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                }

                g = Graphics.FromImage(bmp);

                Stack groupPositions = new Stack();              // for storing the group text positions

                Font legendFont = new Font("MS Sans Sherif", 8); // set default font

                g.Clear(Color.White);                            // clear the background

                int xPos    = 5;                                 // padding
                int yPos    = 5;
                int xOffset = 24;                                // legend indent in pixels
                int yOffset = 18;                                // item height in pixels

                // force the recalculation of the current scale
                map.setExtent(map.extent.minx, map.extent.miny, map.extent.maxx, map.extent.maxy);

                // start drawing the legend in reverse layer order
                using (intarray ar = map.getLayersDrawingOrder())
                {
                    for (int i = map.numlayers - 1; i >= 0; i--)
                    {
                        layerObj layer = map.getLayer(ar.getitem(i));

                        if (layer.name == "__embed__scalebar" || layer.name == "__embed__legend" ||
                            layer.status == mapscript.MS_OFF || layer.name.StartsWith("~"))
                        {
                            continue;
                        }


                        if (map.scaledenom > 0)
                        {
                            if (layer.maxscaledenom > 0 && map.scaledenom > layer.maxscaledenom)
                            {
                                continue;
                            }
                            if (layer.minscaledenom > 0 && map.scaledenom <= layer.minscaledenom)
                            {
                                continue;
                            }
                        }

                        if (layer.maxscaledenom <= 0 && layer.minscaledenom <= 0)
                        {
                            if (layer.maxgeowidth > 0 && ((map.extent.maxx - map.extent.minx) > layer.maxgeowidth))
                            {
                                continue;
                            }
                            if (layer.mingeowidth > 0 && ((map.extent.maxx - map.extent.minx) < layer.mingeowidth))
                            {
                                continue;
                            }
                        }

                        // draw raster or WMS layers
                        if (layer.type == MS_LAYER_TYPE.MS_LAYER_RASTER)
                        {
                            if (phase == 1)
                            {
                                g.DrawIcon(global::MapLibrary.Properties.Resources.raster, xPos, yPos);
                                g.DrawString(layer.name, legendFont, Brushes.Black, xPos + 30, yPos + 2);
                            }

                            SizeF size = g.MeasureString(layer.name, legendFont);
                            if (xPos + 30 + size.Width + 5 > width)
                            {
                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                            }

                            yPos += yOffset;
                            continue;
                        }

                        int    numClasses  = 0;
                        Image  legendImage = null;
                        string legendText  = null;

                        for (int j = 0; j < layer.numclasses; j++)
                        {
                            classObj layerclass = layer.getClass(j);

                            if (layerclass.name == "EntireSelection" || layerclass.name == "CurrentSelection")
                            {
                                continue;
                            }

                            if (layerclass.status == mapscript.MS_OFF)
                            {
                                continue;
                            }

                            if (map.scaledenom > 0)
                            {  /* verify class scale here */
                                if (layerclass.maxscaledenom > 0 && (map.scaledenom > layerclass.maxscaledenom))
                                {
                                    continue;
                                }
                                if (layerclass.minscaledenom > 0 && (map.scaledenom <= layerclass.minscaledenom))
                                {
                                    continue;
                                }
                            }

                            if (numClasses == 1)
                            {
                                // draw subclasses
                                xPos += xOffset;

                                if (phase == 1)
                                {
                                    // drawing the first class item (same as the layer)
                                    g.DrawImage(legendImage, xPos, yPos);
                                    g.DrawString(legendText, legendFont,
                                                 Brushes.Black, xPos + 30, yPos + 2);
                                }

                                SizeF size = g.MeasureString(legendText, legendFont);
                                if (xPos + 30 + size.Width + 5 > width)
                                {
                                    width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                }

                                yPos += yOffset;
                            }

                            ++numClasses; // number of visible classes

                            // creating the treeicons
                            using (classObj def_class = new classObj(null)) // for drawing legend images
                            {
                                using (imageObj image = def_class.createLegendIcon(map, layer, 30, 20))
                                {
                                    // drawing the class icons
                                    layerclass.drawLegendIcon(map, layer, 20, 10, image, 5, 5);
                                    byte[] img = image.getBytes();
                                    using (MemoryStream ms = new MemoryStream(img))
                                    {
                                        legendImage = Image.FromStream(ms);
                                        legendText  = layerclass.name;

                                        if (phase == 1)
                                        {
                                            g.DrawImage(legendImage, xPos, yPos);
                                        }
                                        if (numClasses > 1)
                                        {
                                            // draw the class item
                                            if (phase == 1)
                                            {
                                                g.DrawString(layerclass.name, legendFont,
                                                             Brushes.Black, xPos + 30, yPos + 3);
                                            }

                                            SizeF size = g.MeasureString(layerclass.name, legendFont);
                                            if (xPos + 30 + size.Width + 5 > width)
                                            {
                                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                            }
                                        }
                                        else
                                        {
                                            // draw the layer item
                                            if (phase == 1)
                                            {
                                                g.DrawString(layer.name, legendFont,
                                                             Brushes.Black, xPos + 30, yPos + 3);
                                            }

                                            SizeF size = g.MeasureString(layer.name, legendFont);
                                            if (xPos + 30 + size.Width + 5 > width)
                                            {
                                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                            }

                                            if (string.Compare(layer.styleitem, "AUTO", true) == 0)
                                            {
                                                yPos += yOffset;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            yPos += yOffset;
                        }

                        if (numClasses > 1)
                        {
                            xPos -= xOffset;
                        }
                    }
                }
                height = yPos + 5;
            }

            g.Flush();
            MemoryStream ms2 = new MemoryStream();

            bmp.Save(ms2, System.Drawing.Imaging.ImageFormat.Png);
            return(ms2.ToArray());
        }
示例#5
0
 public static void QueryByAttribute(string qstring, mapObj map, bool zoomToResults)
 {
     Console.WriteLine("\nPerforming QueryByAttribute:");
     try
     {
         layerObj layer;
         rectObj  query_bounds = null;
         for (int i = 0; i < map.numlayers; i++)
         {
             layer = map.getLayer(i);
             if (layer.connection != null && IsLayerQueryable(layer))
             {
                 Console.WriteLine("Layer [" + i + "] name: " + layer.name);
                 BuildQuery(layer, qstring);
                 // zoom to the query results
                 using (resultCacheObj results = layer.getResults())
                 {
                     if (results != null && results.numresults > 0)
                     {
                         // calculating the extent of the results
                         if (query_bounds == null)
                         {
                             query_bounds = new rectObj(results.bounds.minx, results.bounds.miny,
                                                        results.bounds.maxx, results.bounds.maxy, 0);
                         }
                         else
                         {
                             if (results.bounds.minx < query_bounds.minx)
                             {
                                 query_bounds.minx = results.bounds.minx;
                             }
                             if (results.bounds.miny < query_bounds.miny)
                             {
                                 query_bounds.miny = results.bounds.miny;
                             }
                             if (results.bounds.maxx > query_bounds.maxx)
                             {
                                 query_bounds.maxx = results.bounds.maxx;
                             }
                             if (results.bounds.maxy > query_bounds.maxy)
                             {
                                 query_bounds.maxy = results.bounds.maxy;
                             }
                         }
                     }
                 }
             }
         }
         // setting the map extent to the result bounds
         if (query_bounds != null)
         {
             if (zoomToResults)
             {
                 map.setExtent(query_bounds.minx, query_bounds.miny, query_bounds.maxx, query_bounds.maxy);
                 map.scaleExtent(1.2, 0, 0);                     // increasing the visible area
                 Console.WriteLine("Current map scale: 1:" + (int)map.scaledenom);
             }
         }
         else
         {
             Console.WriteLine("The query returned 0 results ...");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("QueryByAttribute: " + e.Message);
     }
 }
示例#6
0
    public static void QueryByAttribute(string qstring, mapObj map, bool zoomToResults)
    {
        Console.WriteLine("\nPerforming QueryByAttribute:");
        try
        {
        	layerObj layer;
            rectObj query_bounds = null;
            for (int i = 0; i < map.numlayers; i++)
            {
                layer = map.getLayer(i);
                if (layer.connection != null && IsLayerQueryable(layer))
                {
                    Console.WriteLine("Layer [" + i + "] name: " + layer.name);
                    BuildQuery(layer, qstring);
                    // zoom to the query results
                    using (resultCacheObj results = layer.getResults())
                    {
                        if (results != null && results.numresults > 0)
                        {
                            // calculating the extent of the results
                            if (query_bounds == null)
                                query_bounds = new rectObj(results.bounds.minx, results.bounds.miny,
                                    results.bounds.maxx, results.bounds.maxy,0);
                            else
                            {
                                if (results.bounds.minx < query_bounds.minx) query_bounds.minx = results.bounds.minx;
                                if (results.bounds.miny < query_bounds.miny) query_bounds.miny = results.bounds.miny;
                                if (results.bounds.maxx > query_bounds.maxx) query_bounds.maxx = results.bounds.maxx;
                                if (results.bounds.maxy > query_bounds.maxy) query_bounds.maxy = results.bounds.maxy;
                            }
                        }
                    }
                }
            }
            // setting the map extent to the result bounds
			if (query_bounds != null) 
			{
				if (zoomToResults) 
				{
					map.setExtent(query_bounds.minx, query_bounds.miny, query_bounds.maxx, query_bounds.maxy);
					map.scaleExtent(1.2, 0, 0); // increasing the visible area
					Console.WriteLine("Current map scale: 1:" + (int)map.scaledenom);
				}
			}
			else
				Console.WriteLine("The query returned 0 results ...");
        }
        catch (Exception e)
        {
        	Console.WriteLine("QueryByAttribute: " + e.Message);
        }
    }
示例#7
0
    public static void Main(string[] args)
    {
        if (args.Length < 2) usage();

          // creating a new map from scratch
          mapObj map = new mapObj(null);
          // adding a layer
          layerObj layer = new layerObj(map);
          layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
          layer.status = mapscript.MS_ON;
          layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
          // define the attribute names from the inline layer
          layer.addProcessing("ITEMS=attribute1,attribute2,attribute3");
          // define the class
          classObj classobj = new classObj(layer);
          classobj.template = "query";   // making the layer queryable
          // setting up the text based on multiple attributes
          classobj.setText("('Shape:' + '[attribute1]' + ' Color:' + '[attribute2]' + ' Size:' + '[attribute3]')");
          // define the label
          classobj.label.outlinecolor = new colorObj(255, 255, 255, 0);
          classobj.label.force = mapscript.MS_TRUE;
          classobj.label.size = (double)MS_BITMAP_FONT_SIZES.MS_MEDIUM;
          classobj.label.position = (int)MS_POSITIONS_ENUM.MS_LC;
          classobj.label.wrap = ' ';
          // set up attribute binding
          classobj.label.setBinding((int)MS_LABEL_BINDING_ENUM.MS_LABEL_BINDING_COLOR, "attribute2");
          // define the style
          styleObj style = new styleObj(classobj);
          style.color = new colorObj(0, 255, 255, 0);
          style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_COLOR, "attribute2");
          style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_SIZE, "attribute3");

          Random rand = new Random((int)DateTime.Now.ToFileTime()); ;

          // creating the shapes
          for (int i = 0; i < 10; i++)
          {
          shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT);

          // setting the shape attributes
          shape.initValues(4);
          shape.setValue(0, Convert.ToString(i));
          shape.setValue(1, new colorObj(rand.Next(255), rand.Next(255), rand.Next(255), 0).toHex());
          shape.setValue(2, Convert.ToString(rand.Next(25) + 5));

          lineObj line = new lineObj();
          line.add(new pointObj(rand.Next(400) + 25, rand.Next(400) + 25, 0, 0));
          shape.add(line);
          layer.addFeature(shape);
          }

          map.width = 500;
          map.height = 500;
          map.setExtent(0,0,450,450);
          map.selectOutputFormat(args[0]);
          imageObj image = map.draw();
          image.save(args[1], map);

          //perform a query
          layer.queryByRect(map, new rectObj(0, 0, 450, 450, 0));

          resultObj res;
          shapeObj feature;
          using (resultCacheObj results = layer.getResults())
          {
          if (results != null && results.numresults > 0)
          {
              // extracting the features found
              layer.open();
              for (int j = 0; j < results.numresults; j++)
              {
                  res = results.getResult(j);
                  feature = layer.getShape(res);
                  if (feature != null)
                  {
                      Console.WriteLine("  Feature: shapeindex=" + res.shapeindex + " tileindex=" + res.tileindex);
                      for (int k = 0; k < layer.numitems; k++)
                      {
                          Console.Write("     " + layer.getItem(k));
                          Console.Write(" = ");
                          Console.Write(feature.getValue(k));
                          Console.WriteLine();
                      }
                  }
              }
              layer.close();
          }
          }
    }
示例#8
0
        /// <summary>
        /// Let the editor to update the modified values to the underlying object.
        /// </summary>
        public void UpdateValues()
        {
            if (map == null)
            {
                return;
            }

            if (dirtyFlag)
            {
                dirtyFlag = false;
                // general tab
                if (map.name != this.textBoxName.Text)
                {
                    map.name = this.textBoxName.Text;
                }
                if (map.shapepath != this.textBoxShapePath.Text)
                {
                    map.shapepath = this.textBoxShapePath.Text;
                }
                if (map.web.imagepath != this.textBoxImagepath.Text)
                {
                    map.web.imagepath = this.textBoxImagepath.Text;
                }
                if (map.fontset.filename != this.textBoxFontset.Text)
                {
                    if (this.textBoxFontset.Text != "" &&
                        File.Exists(this.textBoxFontset.Text))
                    {
                        map.setFontSet(this.textBoxFontset.Text);
                    }
                    else
                    {
                        map.setFontSet(null);
                    }
                }
                if (map.symbolset.filename != this.textBoxSymbolset.Text)
                {
                    if (this.textBoxSymbolset.Text != "" &&
                        File.Exists(this.textBoxSymbolset.Text))
                    {
                        try
                        {
                            map.setSymbolSet(this.textBoxSymbolset.Text);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Invalid symbol file, " + ex.Message,
                                            "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            map.setSymbolSet(null);
                        }
                    }
                    else
                    {
                        map.setSymbolSet(null);
                    }
                }

                // image details tab
                this.colorPickerBackColor.ApplyTo(map.imagecolor);
                if (map.imagetype != comboBoxImageType.Text)
                {
                    map.selectOutputFormat(comboBoxImageType.Text);
                }

                map.resolution = Convert.ToDouble(this.textBoxResolution.Text);
                // coordinate space
                // need to recalculate the extent to point to the same visible area
                try
                {
                    // setting up the projection if it have been changed
                    if (map.getProjection() != this.textBoxProjection.Tag.ToString())
                    {
                        if (map.getProjection() != "" && this.textBoxProjection.Tag.ToString() != "" &&
                            map.extent.minx < map.extent.maxx && map.extent.miny < map.extent.maxy)
                        {
                            using (projectionObj oldProj = new projectionObj(map.getProjection()))
                            {
                                using (projectionObj newProj = new projectionObj(this.textBoxProjection.Tag.ToString()))
                                {
                                    using (rectObj rect = new rectObj(map.extent.minx, map.extent.miny, map.extent.maxx, map.extent.maxy, 0))
                                    {
                                        rect.project(oldProj, newProj);
                                        map.units = (MS_UNITS)this.comboBoxUnits.SelectedItem;
                                        if (rect.minx < rect.maxx && rect.miny < rect.maxy)
                                        {
                                            map.setExtent(rect.minx, rect.miny, rect.maxx, rect.maxy);
                                            dirtyFlagExtent = true;
                                            UpdateExtentValues();
                                        }
                                    }
                                }
                            }
                        }

                        if (this.textBoxProjection.Tag.ToString().Trim().StartsWith("+"))
                        {
                            map.setProjection(this.textBoxProjection.Tag.ToString());
                            map.setMetaData("coordsys_name", this.textBoxProjection.Text);
                        }
                        else
                        {
                            map.setProjection("+AUTO");
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to set projection value, " + ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (checkBoxTransparent.Checked)
                {
                    map.outputformat.transparent = mapscript.MS_TRUE;
                    if (map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGB)
                    {
                        map.outputformat.imagemode = (int)MS_IMAGEMODE.MS_IMAGEMODE_RGBA;
                    }
                }
                else
                {
                    map.outputformat.transparent = mapscript.MS_FALSE;
                    if (map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGBA)
                    {
                        map.outputformat.imagemode = (int)MS_IMAGEMODE.MS_IMAGEMODE_RGB;
                    }
                }

                if (target != null && !dirtyFlagExtent)
                {
                    target.RaisePropertyChanged(this);
                }
                SetDirty(false);
            }
            if (dirtyFlagExtent)
            {
                ApplyExtent();
                dirtyFlagExtent = false;
            }
        }
示例#9
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;
        }
示例#10
0
        /// <summary>
        /// Adding the selected layer to map
        /// </summary>
        void AddLayerToMap()
        {
            // trying to open the layer
            layerObj layer = new layerObj(map);

            layer.connection     = textBoxServer.Text.Trim();
            layer.connectiontype = MS_CONNECTION_TYPE.MS_WMS;
            layer.type           = MS_LAYER_TYPE.MS_LAYER_RASTER;
            layer.status         = mapscript.MS_ON;

            // set up authentication
            NetworkCredential cred = (NetworkCredential)resolver.GetCredentials();

            if (cred != null)
            {
                layer.metadata.set("wms_auth_username", cred.UserName);
                layer.metadata.set("wms_auth_password", cred.Password);
                layer.metadata.set("wms_auth_type", "any");
            }
            WebProxy proxy = (WebProxy)resolver.Proxy;

            if (proxy != null)
            {
                layer.metadata.set("wms_proxy_host", proxy.Address.Host);
                layer.metadata.set("wms_proxy_port", proxy.Address.Port.ToString());
                layer.metadata.set("wms_proxy_auth_type", "any");
                layer.metadata.set("wms_proxy_type", resolver.ProxyType);
                cred = (NetworkCredential)resolver.GetProxyCredentials();
                if (cred != null)
                {
                    layer.metadata.set("wms_proxy_username", cred.UserName);
                    layer.metadata.set("wms_proxy_password", cred.Password);
                }
            }

            // setting up the selected layer
            selected = new MapObjectHolder(layer, target);

            // set queryable flag
            if (wms_queryable == "1")
            {
                layer.template = "query.html";
            }

            // setting up the layer metadata section
            layer.metadata.set("wms_name", wms_name);
            layer.metadata.set("wms_format", comboBoxImageFormat.Text.Trim());

            layer.metadata.set("wms_server_version", wms_server_version);

            if (!colorPickerLayerColor.Value.IsEmpty)
            {
                colorObj color = new colorObj(colorPickerLayerColor.Value.R,
                                              colorPickerLayerColor.Value.G, colorPickerLayerColor.Value.B, 0);
                layer.metadata.set("wms_bgcolor", "0x" + color.toHex().Substring(1));
            }

            if (!checkBoxTransparent.Checked)
            {
                layer.metadata.set("wms_transparent", "FALSE");
            }

            // wms_style
            if (comboBoxStyle.Text != "")
            {
                layer.metadata.set("wms_style", comboBoxStyle.Text);
            }

            // title
            if (wms_title != null)
            {
                layer.name = MapUtils.GetUniqueLayerName(map, wms_title, 0);
            }
            else
            {
                layer.name = MapUtils.GetUniqueLayerName(map, "Layer", 0);
            }

            // scale denom
            if (wms_maxscaledenom > 0)
            {
                layer.maxscaledenom = wms_maxscaledenom;
            }
            if (wms_minscaledenom > 0)
            {
                layer.maxscaledenom = wms_minscaledenom;
            }

            // get bbox parameters
            if (wms_bbox != null && map.numlayers == 1)
            {
                // this is the first layer, set the extent of the map
                map.setExtent(wms_bbox.minx, wms_bbox.miny, wms_bbox.maxx, wms_bbox.maxy);
            }

            // setting up the selected projection
            KeyValuePair <string, string> current = (KeyValuePair <string, string>)bs.Current;
            string wms_srs = current.Key;

            // mapping not EPSG systems to the EPSG variants
            if (string.Compare(wms_srs, "CRS:84", true) == 0)
            {
                wms_srs = "EPSG:4326";
            }
            else if (string.Compare(wms_srs, "CRS:83", true) == 0)
            {
                wms_srs = "EPSG:4369";
            }
            else if (string.Compare(wms_srs, "CRS:27", true) == 0)
            {
                wms_srs = "EPSG:4267";
            }

            if (wms_srs.StartsWith("EPSG", StringComparison.InvariantCultureIgnoreCase))
            {
                layer.metadata.set("wms_srs", wms_srs);
            }
            layer.setProjection(wms_srs);
        }
示例#11
0
 /// <summary>
 /// Creating a new map.
 /// </summary>
 /// <returns>The wrapper containing the newly created map object.</returns>
 public static MapObjectHolder CreateMap()
 {
     mapObj map = new mapObj(null);
     map.setExtent(0, 0, 100, 100);
     return new MapObjectHolder(map, null);
 }
示例#12
0
        /// <summary>
        /// Export a legend image with specific requirements (bug 1015)
        /// </summary>
        /// <param name="map">The map object</param>
        /// <param name="width">The desired legend width</param>
        /// <param name="height">The desired legend height</param>
        /// <returns></returns>
        public static byte[] ExportLegend(mapObj map)
        {
            int width = 10;
            int height = 10;
            Bitmap bmp = null;
            Graphics g = null;
            for (int phase = 0; phase < 2; phase++)
            {
                if (phase == 0)
                    bmp = new Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                else
                    bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                g = Graphics.FromImage(bmp);

                Stack groupPositions = new Stack(); // for storing the group text positions

                Font legendFont = new Font("MS Sans Sherif", 8); // set default font

                g.Clear(Color.White); // clear the background

                int xPos = 5; // padding
                int yPos = 5;
                int xOffset = 24; // legend indent in pixels
                int yOffset = 18; // item height in pixels

                // force the recalculation of the current scale
                map.setExtent(map.extent.minx, map.extent.miny, map.extent.maxx, map.extent.maxy);

                // start drawing the legend in reverse layer order
                using (intarray ar = map.getLayersDrawingOrder())
                {
                    for (int i = map.numlayers - 1; i >= 0; i--)
                    {
                        layerObj layer = map.getLayer(ar.getitem(i));

                        if (layer.name == "__embed__scalebar" || layer.name == "__embed__legend"
                            || layer.status == mapscript.MS_OFF || layer.name.StartsWith("~"))
                            continue;

                        if (map.scaledenom > 0)
                        {
                            if (layer.maxscaledenom > 0 && map.scaledenom > layer.maxscaledenom)
                                continue;
                            if (layer.minscaledenom > 0 && map.scaledenom <= layer.minscaledenom)
                                continue;
                        }

                        if (layer.maxscaledenom <= 0 && layer.minscaledenom <= 0)
                        {
                            if (layer.maxgeowidth > 0 && ((map.extent.maxx - map.extent.minx) > layer.maxgeowidth))
                                continue;
                            if (layer.mingeowidth > 0 && ((map.extent.maxx - map.extent.minx) < layer.mingeowidth))
                                continue;
                        }

                        // draw raster or WMS layers
                        if (layer.type == MS_LAYER_TYPE.MS_LAYER_RASTER)
                        {
                            if (phase == 1)
                            {
                                g.DrawIcon(global::MapLibrary.Properties.Resources.raster, xPos, yPos);
                                g.DrawString(layer.name, legendFont, Brushes.Black, xPos + 30, yPos + 2);
                            }

                            SizeF size = g.MeasureString(layer.name, legendFont);
                            if (xPos + 30 + size.Width + 5 > width)
                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);

                            yPos += yOffset;
                            continue;
                        }

                        int numClasses = 0;
                        Image legendImage = null;
                        string legendText = null;

                        for (int j = 0; j < layer.numclasses; j++)
                        {
                            classObj layerclass = layer.getClass(j);

                            if (layerclass.name == "EntireSelection" || layerclass.name == "CurrentSelection")
                                continue;

                            if (layerclass.status == mapscript.MS_OFF)
                                continue;

                            if (map.scaledenom > 0)
                            {  /* verify class scale here */
                                if (layerclass.maxscaledenom > 0 && (map.scaledenom > layerclass.maxscaledenom))
                                    continue;
                                if (layerclass.minscaledenom > 0 && (map.scaledenom <= layerclass.minscaledenom))
                                    continue;
                            }

                            if (numClasses == 1)
                            {
                                // draw subclasses
                                xPos += xOffset;

                                if (phase == 1)
                                {
                                    // drawing the first class item (same as the layer)
                                    g.DrawImage(legendImage, xPos, yPos);
                                    g.DrawString(legendText, legendFont,
                                               Brushes.Black, xPos + 30, yPos + 2);
                                }

                                SizeF size = g.MeasureString(legendText, legendFont);
                                if (xPos + 30 + size.Width + 5 > width)
                                    width = Convert.ToInt32(xPos + 30 + size.Width + 5);

                                yPos += yOffset;
                            }

                            ++numClasses; // number of visible classes

                            // creating the treeicons
                            using (classObj def_class = new classObj(null)) // for drawing legend images
                            {
                                using (imageObj image = def_class.createLegendIcon(map, layer, 30, 20))
                                {
                                    // drawing the class icons
                                    layerclass.drawLegendIcon(map, layer, 20, 10, image, 5, 5);
                                    byte[] img = image.getBytes();
                                    using (MemoryStream ms = new MemoryStream(img))
                                    {
                                        legendImage = Image.FromStream(ms);
                                        legendText = layerclass.name;

                                        if (phase == 1)
                                            g.DrawImage(legendImage, xPos, yPos);
                                        if (numClasses > 1)
                                        {
                                            // draw the class item
                                            if (phase == 1)
                                                g.DrawString(layerclass.name, legendFont,
                                                       Brushes.Black, xPos + 30, yPos + 3);

                                            SizeF size = g.MeasureString(layerclass.name, legendFont);
                                            if (xPos + 30 + size.Width + 5 > width)
                                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                        }
                                        else
                                        {
                                            // draw the layer item
                                            if (phase == 1)
                                                g.DrawString(layer.name, legendFont,
                                                       Brushes.Black, xPos + 30, yPos + 3);

                                            SizeF size = g.MeasureString(layer.name, legendFont);
                                            if (xPos + 30 + size.Width + 5 > width)
                                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);

                                            if (string.Compare(layer.styleitem, "AUTO", true) == 0)
                                            {
                                                yPos += yOffset;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            yPos += yOffset;
                        }

                        if (numClasses > 1)
                            xPos -= xOffset;
                    }
                }
                height = yPos + 5;
            }

            g.Flush();
            MemoryStream ms2 = new MemoryStream();
            bmp.Save(ms2, System.Drawing.Imaging.ImageFormat.Png);
            return ms2.ToArray();
        }
示例#13
0
    public static void Main(string[] args)
    {
        if (args.Length < 2)
        {
            usage();
        }

        // creating a new map from scratch
        mapObj map = new mapObj(null);
        // adding a layer
        layerObj layer = new layerObj(map);

        layer.type           = MS_LAYER_TYPE.MS_LAYER_POINT;
        layer.status         = mapscript.MS_ON;
        layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
        // define the attribute names from the inline layer
        layer.addProcessing("ITEMS=attribute1,attribute2,attribute3");
        // define the class
        classObj classobj = new classObj(layer);

        classobj.template = "query"; // making the layer queryable
        // setting up the text based on multiple attributes
        classobj.setText("('Shape:' + '[attribute1]' + ' Color:' + '[attribute2]' + ' Size:' + '[attribute3]')");
        // define the label
        classobj.label.outlinecolor = new colorObj(255, 255, 255, 0);
        classobj.label.force        = mapscript.MS_TRUE;
        classobj.label.size         = (double)MS_BITMAP_FONT_SIZES.MS_MEDIUM;
        classobj.label.position     = (int)MS_POSITIONS_ENUM.MS_LC;
        classobj.label.wrap         = ' ';
        // set up attribute binding
        classobj.label.setBinding((int)MS_LABEL_BINDING_ENUM.MS_LABEL_BINDING_COLOR, "attribute2");
        // define the style
        styleObj style = new styleObj(classobj);

        style.color = new colorObj(0, 255, 255, 0);
        style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_COLOR, "attribute2");
        style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_SIZE, "attribute3");

        Random rand = new Random((int)DateTime.Now.ToFileTime());;

        // creating the shapes
        for (int i = 0; i < 10; i++)
        {
            shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT);

            // setting the shape attributes
            shape.initValues(4);
            shape.setValue(0, Convert.ToString(i));
            shape.setValue(1, new colorObj(rand.Next(255), rand.Next(255), rand.Next(255), 0).toHex());
            shape.setValue(2, Convert.ToString(rand.Next(25) + 5));

            lineObj line = new lineObj();
            line.add(new pointObj(rand.Next(400) + 25, rand.Next(400) + 25, 0, 0));
            shape.add(line);
            layer.addFeature(shape);
        }

        map.width  = 500;
        map.height = 500;
        map.setExtent(0, 0, 450, 450);
        map.selectOutputFormat(args[0]);
        imageObj image = map.draw();

        image.save(args[1], map);

        //perform a query
        layer.queryByRect(map, new rectObj(0, 0, 450, 450, 0));

        resultObj res;
        shapeObj  feature;

        using (resultCacheObj results = layer.getResults())
        {
            if (results != null && results.numresults > 0)
            {
                // extracting the features found
                layer.open();
                for (int j = 0; j < results.numresults; j++)
                {
                    res     = results.getResult(j);
                    feature = layer.getShape(res);
                    if (feature != null)
                    {
                        Console.WriteLine("  Feature: shapeindex=" + res.shapeindex + " tileindex=" + res.tileindex);
                        for (int k = 0; k < layer.numitems; k++)
                        {
                            Console.Write("     " + layer.getItem(k));
                            Console.Write(" = ");
                            Console.Write(feature.getValue(k));
                            Console.WriteLine();
                        }
                    }
                }
                layer.close();
            }
        }
    }