protected bool LoadNutiteqMapCommon() { // Set base projection EPSG3857 proj = new EPSG3857(); _mapViewer.Options.BaseProjection = proj; // note: EPSG3857 is the default, so this is actually not required // Set initial location and other parameters, don't animate _mapViewer.FocusPos = proj.FromWgs84(new MapPos(-0.8164, 51.2383)); // Berlin _mapViewer.Zoom = 2; _mapViewer.MapRotation = 0; _mapViewer.Tilt = 90; // Start package manager var packageManager = new NutiteqPackageManager("nutiteq.mbstreets", _downloadPackagePath); packageManager.Start(); // Import initial package if (packageManager.GetLocalPackage("world0_4") == null) { packageManager.StartPackageImport("world0_4", 1, _importPackagePath); } // Set bounding box String bbox = "bbox(-0.8164,51.2382,0.6406,51.7401)"; // London (about 30MB) if (packageManager.GetLocalPackage(bbox) == null) { packageManager.StartPackageDownload(bbox); } // Now can add vector map as layer // define styling for vector map UnsignedCharVector styleBytes = AssetUtils.LoadBytes("osmbright.zip"); MBVectorTileDecoder vectorTileDecoder = null; if (styleBytes != null) { // Create style set MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes); vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet); } else { Log.Error("Failed to load style data"); } // Create online base layer (no package download needed then). Use vector style from assets (osmbright.zip) // comment in to use online map. Packagemanager stuff is not needed then // VectorTileLayer baseLayer = new NutiteqOnlineVectorTileLayer("osmbright.zip"); var baseLayer = new VectorTileLayer(new PackageManagerTileDataSource(packageManager), vectorTileDecoder); _mapViewer.Layers.Add(baseLayer); return(true); }
private InverseDistanceWeightingFunction GetIDWFunction(ContourQuery contourQuery, List <TrendingDataLocation> locations = null) { CoordinateReferenceSystem crs = new EPSG3857(); List <double> xList = new List <double>(); List <double> yList = new List <double>(); List <double> valueList = new List <double>(); if ((object)locations == null) { locations = GetFrameFromDailySummary(contourQuery); } locations .Select(location => { GeoCoordinate Coordinate = new GeoCoordinate(location.Latitude, location.Longitude); double?Value = (contourQuery.DataType == "Average") ? location.Average : (contourQuery.DataType == "Minimum") ? location.Minimum : (contourQuery.DataType == "Maximum") ? location.Maximum : null; return(new { Coordinate, Value }); }) .Where(obj => (object)obj.Value != null) .ToList() .ForEach(obj => { xList.Add(obj.Coordinate.Longitude); yList.Add(obj.Coordinate.Latitude); valueList.Add(obj.Value.GetValueOrDefault()); }); if (valueList.Count == 0) { xList.Add(0.0D); yList.Add(0.0D); using (AdoDataConnection connection = new AdoDataConnection(connectionstring, typeof(SqlConnection), typeof(SqlDataAdapter))) { valueList.Add(connection.ExecuteScalar <double>("SELECT NominalValue FROM ContourColorScale WHERE Name = {0}", contourQuery.ColorScaleName)); } } return(new InverseDistanceWeightingFunction() .SetXCoordinates(xList.ToArray()) .SetYCoordinates(yList.ToArray()) .SetValues(valueList.ToArray()) .SetDistanceFunction((x1, y1, x2, y2) => { GeoCoordinate coordinate1 = new GeoCoordinate(y1, x1); GeoCoordinate coordinate2 = new GeoCoordinate(y2, x2); return crs.Distance(coordinate1, coordinate2); })); }
protected bool LoadNutiteqMapCommon() { // Set base projection EPSG3857 proj = new EPSG3857(); _mapViewer.Options.BaseProjection = proj; // note: EPSG3857 is the default, so this is actually not required // Set initial location and other parameters, don't animate _mapViewer.FocusPos = proj.FromWgs84(new MapPos(-0.8164, 51.2383)); // Berlin _mapViewer.Zoom = 2; _mapViewer.MapRotation = 0; _mapViewer.Tilt = 90; // Start package manager var packageManager = new NutiteqPackageManager("nutiteq.mbstreets", _downloadPackagePath); packageManager.Start(); // Import initial package if (packageManager.GetLocalPackage("world0_4") == null) { packageManager.StartPackageImport("world0_4", 1, _importPackagePath); } // Set bounding box String bbox = "bbox(-0.8164,51.2382,0.6406,51.7401)"; // London (about 30MB) if (packageManager.GetLocalPackage(bbox) == null) { packageManager.StartPackageDownload(bbox); } // Now can add vector map as layer // define styling for vector map UnsignedCharVector styleBytes = AssetUtils.LoadBytes("osmbright.zip"); MBVectorTileDecoder vectorTileDecoder = null; if (styleBytes != null) { // Create style set MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes); vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet); } else { Log.Error("Failed to load style data"); } // Create online base layer (no package download needed then). Use vector style from assets (osmbright.zip) // comment in to use online map. Packagemanager stuff is not needed then // VectorTileLayer baseLayer = new NutiteqOnlineVectorTileLayer("osmbright.zip"); var baseLayer = new VectorTileLayer(new PackageManagerTileDataSource(packageManager), vectorTileDecoder); _mapViewer.Layers.Add(baseLayer); return true; }
public override void ViewDidLoad() { base.ViewDidLoad(); MapView = new MapView(); View = MapView; BaseProjection = new EPSG3857(); // Initialize map var styleAsset = AssetUtils.LoadAsset("nutibright-v3.zip"); var baseLayer = new CartoOnlineVectorTileLayer("nutiteq.osm", new ZippedAssetPackage(styleAsset)); MapView.Layers.Add(baseLayer); Title = Name; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(ViewResource); MapView = (MapView)FindViewById(MapViewResource); BaseProjection = new EPSG3857(); // Initialize map var baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault); MapView.Layers.Add(baseLayer); Title = GetType().GetTitle(); ActionBar.SetDisplayHomeAsUpEnabled(true); }
public static void addJosnLayer(IMapView mapView, String json) { var features = Newtonsoft.Json.Linq.JObject.Parse(json)["features"]; var geoJsonParser = new GeoJSONGeometryReader(); var proj = new EPSG3857(); var balloonPopupStyleBuilder = new BalloonPopupStyleBuilder(); // Create overlay layer for markers var dataSource = new LocalVectorDataSource(proj); var overlayLayer = new ClusteredVectorLayer(dataSource, new MyClusterElementBuilder()); overlayLayer.MinimumClusterDistance = 80; // in pixels mapView.Layers.Add(overlayLayer); foreach (var feature in features) { var featureType = feature ["type"]; var geometry = feature ["geometry"]; var ntGeom = geoJsonParser.ReadGeometry(Newtonsoft.Json.JsonConvert.SerializeObject(geometry)); var popup = new BalloonPopup( ntGeom, balloonPopupStyleBuilder.BuildStyle(), (string)feature ["properties"]["Capital"], (string)feature ["properties"]["Country"]); var properties = (JObject)feature ["properties"]; foreach (var property in properties) { var key = (string)property.Key; var value = (string)property.Value; popup.SetMetaDataElement(key, value); } dataSource.Add(popup); } }
/// <summary> /// Queries Grafana data source for location data offsetting duplicate coordinates using a radial distribution. /// </summary> /// <param name="radius">Radius of overlapping coordinate distribution.</param> /// <param name="zoom">Zoom level.</param> /// <param name="request"> Query request.</param> /// <param name="cancellationToken">Propagates notification from client that operations should be canceled.</param> /// <returns>JSON serialized location metadata for specified targets.</returns> public Task <string> GetLocationData(double radius, double zoom, List <Target> request, CancellationToken cancellationToken) { if (double.IsNaN(radius) || radius <= 0.0D) { return(GetLocationData(request, cancellationToken)); } return(Task.Factory.StartNew(() => { // Get location data, sorted by longitude and latitude DataTable targetMeasurements = GetLocationDataTable(request, true, cancellationToken); if (targetMeasurements.Rows.Count > 0) { int longitude = targetMeasurements.Columns["Longitude"].Ordinal; int latitude = targetMeasurements.Columns["Latitude"].Ordinal; bool coordinateIsValid(DataRow row, int column) => row[column] is decimal; bool coordinatesAreValid(DataRow row) => coordinateIsValid(row, longitude) && coordinateIsValid(row, latitude); bool coordinateMatches(DataRow left, DataRow right, int column) => left[column] is decimal leftValue && right[column] is decimal rightValue && leftValue.Equals(rightValue); bool coordinatesMatch(DataRow first, DataRow current) => coordinateMatches(first, current, longitude) && coordinateMatches(first, current, latitude); List <DataRow[]> groupedRows = new List <DataRow[]>(); List <DataRow> matchingRows = new List <DataRow> { targetMeasurements.Rows[0] }; DataRow firstGroupRow = matchingRows.First(); bool firstGroupRowValid = coordinatesAreValid(firstGroupRow); // Organize metadata rows with overlapped coordinates into groups for (int i = 1; i < targetMeasurements.Rows.Count; i++) { DataRow row = targetMeasurements.Rows[i]; if (firstGroupRowValid && coordinatesMatch(firstGroupRow, row)) { matchingRows.Add(row); } else { if (matchingRows.Count > 1) { groupedRows.Add(matchingRows.ToArray()); } matchingRows = new List <DataRow> { row }; firstGroupRow = matchingRows.First(); firstGroupRowValid = coordinatesAreValid(firstGroupRow); } } if (matchingRows.Count > 1) { groupedRows.Add(matchingRows.ToArray()); } // Create radial distribution for overlapped coordinates, leaving one item at center EPSG3857 coordinateReference = new EPSG3857(); foreach (DataRow[] rows in groupedRows) { int count = rows.Length; double interval = 2.0D * Math.PI / (count - 1); for (int i = 1; i < count; i++) { DataRow row = rows[i]; Point point = coordinateReference.Translate(new GeoCoordinate((double)row.Field <decimal>(latitude), (double)row.Field <decimal>(longitude)), zoom); double theta = interval * i; double x = point.X + radius * Math.Cos(theta); double y = point.Y + radius * Math.Sin(theta); GeoCoordinate coordinate = coordinateReference.Translate(new Point(x, y), zoom); row[longitude] = (decimal)coordinate.Longitude; row[latitude] = (decimal)coordinate.Latitude; } } } return JsonConvert.SerializeObject(targetMeasurements); }, cancellationToken)); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // enable Nutiteq SDK logging Log.EnableAll(); // get MapView MapView view = FindViewById <MapView> (Resource.Id.mapView); // define mandatory parameters // Components keeps internal state and parameters for MapView view.Components = new Components(); // define base projection, almost always EPSG3857, but others can be defined also EPSG3857 proj = new EPSG3857(); // set online base layer with MapQuest Open Tiles view.Layers.BaseLayer = new TMSMapLayer(proj, 0, 18, 0, "http://otile1.mqcdn.com/tiles/1.0.0/osm/", "/", ".png"); /* * //set offline base layer from MBTiles file * //TODO: set path properly * String MbTilePath = "/sdcard/europe-tilemill-mbtiles.sqlite"; * * view.Layers.BaseLayer = new MBTilesMapLayer (proj, 0, 5, 1, MbTilePath, this); */ // start map view.StartMapping(); // add a marker // define marker style (image, size, color) Bitmap pointMarker = UnscaledBitmapLoader.DecodeResource(Resources, Resource.Drawable.olmarker); MarkerStyle.Builder markerStyleBuilder = new MarkerStyle.Builder(); markerStyleBuilder.SetBitmap(pointMarker); markerStyleBuilder.SetColor(NutiteqComponents.Color.White); markerStyleBuilder.SetSize(0.5f); MarkerStyle markerStyle = markerStyleBuilder.Build(); // define label what is shown when you click on marker Label markerLabel = new DefaultLabel("San Francisco", "Here is a marker"); // define location of the marker, it must be converted to base map coordinate system MapPos SanFrancisco = view.Layers.BaseLayer.Projection.FromWgs84(-122.416667f, 37.766667f); MapPos London = view.Layers.BaseLayer.Projection.FromWgs84(0.0f, 51.0f); // create layer and add object to the layer, finally add layer to the map. // All overlay layers must be same projection as base layer, so we reuse it MarkerLayer markerLayer = new MarkerLayer(view.Layers.BaseLayer.Projection); markerLayer.Add(new Marker(SanFrancisco, markerLabel, markerStyle, markerLayer)); view.Layers.AddLayer(markerLayer); // 3d building layer Polygon3DStyle.Builder nml3dStyleBuilder = new Polygon3DStyle.Builder(); Polygon3DStyle nml3dStyle = nml3dStyleBuilder.Build(); StyleSet nmlStyleSet = new StyleSet(); nmlStyleSet.SetZoomStyle(14, nml3dStyle); NMLModelOnlineLayer Online3dLayer = new NMLModelOnlineLayer(view.Layers.BaseLayer.Projection, "http://aws-lb.nutiteq.ee/nml/nmlserver2.php?data=demo&", nmlStyleSet); // persistent caching settings for the layer Online3dLayer.SetMemoryLimit(20 * 1024 * 1024); // 20 MB Online3dLayer.SetPersistentCacheSize(50 * 1024 * 1024); // 50 MB Online3dLayer.SetPersistentCachePath("/sdcard/nmlcache.db"); // mandatory to be set view.Layers.AddLayer(Online3dLayer); // OSM Polygon3D layer Polygon3DStyle.Builder poly3dStyleBuilder = new Polygon3DStyle.Builder(); poly3dStyleBuilder.SetColor(NutiteqComponents.Color.White); Polygon3DStyle poly3dStyle = poly3dStyleBuilder.Build(); StyleSet polyStyleSet = new StyleSet(); polyStyleSet.SetZoomStyle(16, poly3dStyle); Roof DefaultRoof = new FlatRoof(); Polygon3DOSMLayer Poly3DLayer = new Polygon3DOSMLayer(view.Layers.BaseLayer.Projection, 0.3f, DefaultRoof, unchecked ((int)0xffffffff) /* white */, unchecked ((int)0xff888888) /* gray */, 1500, polyStyleSet); view.Layers.AddLayer(Poly3DLayer); // set map center and zoom view.FocusPoint = SanFrancisco; view.Zoom = 5.0f; // set listener for map events MapListener listener = new MyMapListener(); view.Options.MapListener = listener; }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // enable Nutiteq SDK logging Log.EnableAll (); // get MapView MapView view = FindViewById<MapView> (Resource.Id.mapView); // define mandatory parameters // Components keeps internal state and parameters for MapView view.Components = new Components (); // define base projection, almost always EPSG3857, but others can be defined also EPSG3857 proj = new EPSG3857 (); // set online base layer with MapQuest Open Tiles view.Layers.BaseLayer = new TMSMapLayer(proj, 0, 18, 0, "http://otile1.mqcdn.com/tiles/1.0.0/osm/", "/", ".png"); /* //set offline base layer from MBTiles file //TODO: set path properly String MbTilePath = "/sdcard/europe-tilemill-mbtiles.sqlite"; view.Layers.BaseLayer = new MBTilesMapLayer (proj, 0, 5, 1, MbTilePath, this); */ // start map view.StartMapping (); // add a marker // define marker style (image, size, color) Bitmap pointMarker = UnscaledBitmapLoader.DecodeResource(Resources, Resource.Drawable.olmarker); MarkerStyle.Builder markerStyleBuilder = new MarkerStyle.Builder (); markerStyleBuilder.SetBitmap (pointMarker); markerStyleBuilder.SetColor (NutiteqComponents.Color.White); markerStyleBuilder.SetSize (0.5f); MarkerStyle markerStyle = markerStyleBuilder.Build (); // define label what is shown when you click on marker Label markerLabel = new DefaultLabel ("San Francisco", "Here is a marker"); // define location of the marker, it must be converted to base map coordinate system MapPos SanFrancisco = view.Layers.BaseLayer.Projection.FromWgs84 (-122.416667f, 37.766667f); MapPos London = view.Layers.BaseLayer.Projection.FromWgs84 (0.0f, 51.0f); // create layer and add object to the layer, finally add layer to the map. // All overlay layers must be same projection as base layer, so we reuse it MarkerLayer markerLayer = new MarkerLayer(view.Layers.BaseLayer.Projection); markerLayer.Add(new Marker(SanFrancisco, markerLabel, markerStyle, markerLayer)); view.Layers.AddLayer(markerLayer); // 3d building layer Polygon3DStyle.Builder nml3dStyleBuilder = new Polygon3DStyle.Builder (); Polygon3DStyle nml3dStyle = nml3dStyleBuilder.Build (); StyleSet nmlStyleSet = new StyleSet (); nmlStyleSet.SetZoomStyle (14, nml3dStyle); NMLModelOnlineLayer Online3dLayer = new NMLModelOnlineLayer (view.Layers.BaseLayer.Projection, "http://aws-lb.nutiteq.ee/nml/nmlserver2.php?data=demo&", nmlStyleSet); // persistent caching settings for the layer Online3dLayer.SetMemoryLimit (20*1024*1024); // 20 MB Online3dLayer.SetPersistentCacheSize (50*1024*1024); // 50 MB Online3dLayer.SetPersistentCachePath ("/sdcard/nmlcache.db"); // mandatory to be set view.Layers.AddLayer(Online3dLayer); // OSM Polygon3D layer Polygon3DStyle.Builder poly3dStyleBuilder = new Polygon3DStyle.Builder (); poly3dStyleBuilder.SetColor (NutiteqComponents.Color.White); Polygon3DStyle poly3dStyle = poly3dStyleBuilder.Build (); StyleSet polyStyleSet = new StyleSet (); polyStyleSet.SetZoomStyle (16, poly3dStyle); Roof DefaultRoof = new FlatRoof (); Polygon3DOSMLayer Poly3DLayer = new Polygon3DOSMLayer (view.Layers.BaseLayer.Projection, 0.3f, DefaultRoof, unchecked((int) 0xffffffff) /* white */, unchecked((int) 0xff888888) /* gray */, 1500, polyStyleSet); view.Layers.AddLayer (Poly3DLayer); // set map center and zoom view.FocusPoint = SanFrancisco; view.Zoom = 5.0f; // set listener for map events MapListener listener = new MyMapListener (); view.Options.MapListener = listener; }