Esempio n. 1
0
        /// <summary>
        /// Creates map object from <see cref="CartoProject"/>
        /// </summary>
        /// <param name="project"></param>
        /// <param name="definitions"></param>
        /// <param name="env"></param>
        /// <param name="cartoTranslator"></param>
        /// <returns></returns>
        private static Map CreateMap(CartoProject project, List <CartoDefinition> definitions, Env env, ICartoTranslator cartoTranslator)
        {
            Map map = new Map(project.Name);

            map.Size         = new SizeF(700, 500);
            map.MinimumScale = ConvertUtility.ToScaleDenominator(project.MinZoom);
            map.MaximumScale = ConvertUtility.ToScaleDenominator(project.MaxZoom);

            // if (project.Bounds != null)
            //   map.WGS84Bounds = project.Bounds[0] + "," + project.Bounds[1] + "," + project.Bounds[2] + "," + project.Bounds[3];
            map.CRS = cartoTranslator.ToCoordinateSystem(string.IsNullOrEmpty(project.Srs) ? project.SrsName : project.Srs, !string.IsNullOrEmpty(project.SrsName));

            SetMapProperties(map, GetProperties(definitions, env, "Map"), cartoTranslator);
            SetFontSets(map, definitions, env, cartoTranslator);

            if (project.Center != null)
            {
                if (map.CoordinateSystem == null)
                {
                    CoordinateSystemFactory csFactory = new CoordinateSystemFactory();
                    map.CoordinateSystem = (CoordinateSystem)csFactory.CreateSphericalMercatorCoordinateSystem();
                }

                double cx = Convert.ToDouble(project.Center[0]);
                double cy = Convert.ToDouble(project.Center[1]);
                double cz = Convert.ToDouble(project.Center[2]);

                double scale = MapSurfer.Utilities.MapUtility.GetTileMapResolution(cz);
                GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation trans = CoordinateTransformationFactory.CreateCoordinateTransformation(GeographicCoordinateSystem.WGS84, map.CoordinateSystem);
                trans.MathTransform.Transform(ref cx, ref cy, ref cz);
                map.SetCenterAndZoom(cx, cy, scale);
            }

            return(map);
        }
Esempio n. 2
0
        /// <summary>
        /// Create styled layer
        /// </summary>
        /// <param name="cartoLayer"></param>
        /// <param name="cartoTranslator"></param>
        /// <returns></returns>
        private static StyledLayer CreateStyledLayer(CartoLayer cartoLayer, Map map, ICartoTranslator cartoTranslator)
        {
            ParameterCollection parameters = cartoTranslator.ToDatasourceParameters(cartoLayer);
            StyledLayer         layer      = new StyledLayer(cartoLayer.Name, parameters);

            layer.FeaturesCaching.Enabled = true;

            if (cartoLayer.Properties != null)
            {
                if (cartoLayer.Properties.ContainsKey("minzoom"))
                {
                    layer.MinimumScale = ConvertUtility.ToScaleDenominator(Convert.ToInt32(cartoLayer.Properties["minzoom"]));
                }
                if (cartoLayer.Properties.ContainsKey("maxzoom"))
                {
                    layer.MaximumScale = ConvertUtility.ToScaleDenominator(Convert.ToInt32(cartoLayer.Properties["maxzoom"]));
                }
                if (cartoLayer.Properties.ContainsKey("queryable"))
                {
                    layer.Queryable = Convert.ToBoolean(cartoLayer.Properties["queryable"]);
                }
                if (cartoLayer.Properties.ContainsKey("cache-features")) // Extension
                {
                    layer.FeaturesCaching.Enabled = Convert.ToBoolean(cartoLayer.Properties["cache-features"]);
                }
            }

            layer.Enabled = cartoLayer.Status != "off";

            string providerName = parameters.GetValue("Type");

            if (string.IsNullOrEmpty(providerName))
            {
                LogFactory.WriteLogEntry(Logger.Default, new IOException(string.Format("Unable to detect the type of a data source provider for the layer '{0}'.", cartoLayer.Name)));
            }

            if (!string.IsNullOrEmpty(cartoLayer.Srs))
            {
                layer.CRS = cartoTranslator.ToCoordinateSystem(string.IsNullOrEmpty(cartoLayer.Srs) ? cartoLayer.SrsName : cartoLayer.Srs, !string.IsNullOrEmpty(cartoLayer.SrsName));
            }

            return(layer);
        }
    /// <summary>
    /// Create styled layer
    /// </summary>
    /// <param name="cartoLayer"></param>
    /// <param name="cartoTranslator"></param>
    /// <returns></returns>
    private static StyledLayer CreateStyledLayer(CartoLayer cartoLayer, Map map, ICartoTranslator cartoTranslator)
    {
      ParameterCollection parameters = cartoTranslator.ToDatasourceParameters(cartoLayer);
      StyledLayer layer = new StyledLayer(cartoLayer.Name, parameters);
      layer.FeaturesCaching.Enabled = true;

      if (cartoLayer.Properties != null)
      {
        if (cartoLayer.Properties.ContainsKey("minzoom"))
          layer.MinimumScale = ConvertUtility.ToScaleDenominator(Convert.ToInt32(cartoLayer.Properties["minzoom"]));
        if (cartoLayer.Properties.ContainsKey("maxzoom"))
          layer.MaximumScale = ConvertUtility.ToScaleDenominator(Convert.ToInt32(cartoLayer.Properties["maxzoom"]));
        if (cartoLayer.Properties.ContainsKey("queryable"))
          layer.Queryable = Convert.ToBoolean(cartoLayer.Properties["queryable"]);
        if (cartoLayer.Properties.ContainsKey("cache-features")) // Extension
          layer.FeaturesCaching.Enabled = Convert.ToBoolean(cartoLayer.Properties["cache-features"]);
      }

      layer.Enabled = cartoLayer.Status != "off";

      string providerName = parameters.GetValue("Type");
      if (string.IsNullOrEmpty(providerName))
        LogFactory.WriteLogEntry(Logger.Default, new IOException(string.Format("Unable to detect the type of a data source provider for the layer '{0}'.", cartoLayer.Name)));

      if (!string.IsNullOrEmpty(cartoLayer.Srs))
        layer.CRS = cartoTranslator.ToCoordinateSystem(string.IsNullOrEmpty(cartoLayer.Srs) ? cartoLayer.SrsName : cartoLayer.Srs, !string.IsNullOrEmpty(cartoLayer.SrsName));

      return layer;
    }
    /// <summary>
    /// Creates map object from <see cref="CartoProject"/>
    /// </summary>
    /// <param name="project"></param>
    /// <param name="definitions"></param>
    /// <param name="env"></param>
    /// <param name="cartoTranslator"></param>
    /// <returns></returns>
    private static Map CreateMap(CartoProject project, List<CartoDefinition> definitions, Env env, ICartoTranslator cartoTranslator)
    {
      Map map = new Map(project.Name);
      map.Size = new SizeF(700, 500);
      map.MinimumScale = ConvertUtility.ToScaleDenominator(project.MinZoom);
      map.MaximumScale = ConvertUtility.ToScaleDenominator(project.MaxZoom);

      // if (project.Bounds != null)
      //   map.WGS84Bounds = project.Bounds[0] + "," + project.Bounds[1] + "," + project.Bounds[2] + "," + project.Bounds[3];
      map.CRS = cartoTranslator.ToCoordinateSystem(string.IsNullOrEmpty(project.Srs) ? project.SrsName : project.Srs, !string.IsNullOrEmpty(project.SrsName));

      SetMapProperties(map, GetProperties(definitions, env, "Map"), cartoTranslator);
      SetFontSets(map, definitions, env, cartoTranslator);

      if (project.Center != null)
      {
        if (map.CoordinateSystem == null)
        {
          CoordinateSystemFactory csFactory = new CoordinateSystemFactory();
          map.CoordinateSystem = (CoordinateSystem)csFactory.CreateSphericalMercatorCoordinateSystem();
        }

        double cx = Convert.ToDouble(project.Center[0]);
        double cy = Convert.ToDouble(project.Center[1]);
        double cz = Convert.ToDouble(project.Center[2]);

        double scale = MapSurfer.Utilities.MapUtility.GetTileMapResolution(cz);
        GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation trans = CoordinateTransformationFactory.CreateCoordinateTransformation(GeographicCoordinateSystem.WGS84, map.CoordinateSystem);
        trans.MathTransform.Transform(ref cx, ref cy, ref cz);
        map.SetCenterAndZoom(cx, cy, scale);
      }

      return map;
    }