Equivalent of the old OpenLayers.Layer.Text - openstreetmap

I have in the OpenLayers 2 project this construct:
var pois = new OpenLayers.Layer.Text( "Románské kostely", {
location:"./kostely.tsv",
projection: map.displayProjection
});
map.addLayer(pois);
Actually, the ease with which I can create a new layer from just TSV file was one of the reasons why I started to play OpenLayers in the first place.
I have now this as a port to OpenLayers 3:
new ol.layer.Vector({
title: "Románské kostely",
source: ol.source.Vector({
format: new ol.format.TextTSV(),
url: "kostely.tsv"
}),
style: new ol.style.Style({
image: new ol.style.Icon({
src: "Ol_icon_blue.png"
})
})
})
Except, obviously, there is no ol.format.TextTSV(). The best what I can find in API are a way more complicated constructs like GeoJSON etc.
Did anybody created an equivalent function for the OpenLayers 3 API? Or is there a convertor somewhere from the old TSV file to some supported format?

It should work by using csv2geojson library provided by MapBox (to convert CSV/TSV to GeoJSON), combined with a ol.source.Vector using ol.format.GeoJSON.
I produced an example to illustrate this use case (more complicated than the solution you expected). I didn't bother with the style for the demo and I also use only Vanilla JS (it means "pure JavaScript", no third party library) for Ajax calls.
If you really need a new ol.format.TextTSV(), you will need to make your own extension to the core library. You can also ask on the mailing list if it's on the project roadmap.

Have you tried it in WKT format
var format = new ol.format.WKT();
http://openlayers.org/en/v3.4.0/apidoc/ol.format.WKT.html

Related

How to use an existing Mapbox GL "template" but add elevation/fog to it?

I have this:
var map = new mapboxgl.Map
({
container: 'map',
style: 'mapbox://styles/mapbox/satellite-streets-v11',
});
It works. But I also want elevation/fog added to it. Reading the manual for many hours, it seems to me that you either have to specify a URL, like I have done, to a "pre-made style", OR specify an absolutely massive style object full of cryptic and incomprehensible sub-objects such as specific layers and stuff.
There doesn't seem to be a way to simply use that style "template" URL, and add elevation/fog on top of it. I really hope that I'm wrong about this.
Downloading the JSON object representing their "pre-made style", I was presented with a massive ocean of data, impossible to manage in any sensible manner. They cannot possibly mean that you should try to edit/adapt/extend that.
I must be missing something. Is there really no way to do what I do now, but enable the "terrain" and "fog" features?
https://docs.mapbox.com/mapbox-gl-js/style-spec/terrain/
https://docs.mapbox.com/mapbox-gl-js/style-spec/fog/
Naturally, I tried adding them to the Map object at first, assuming this was how it was done, but it was just ignored.
Again, if I were to make my own style object, it would be required to contain all sorts of scary and incomprehensible stuff: https://docs.mapbox.com/mapbox-gl-js/style-spec/root/
To be frank, I have no idea who would ever want a 3D map which can support elevation/height differences and realistic fog/lights, yet not use those features. To me, this seems like it would be a simple boolean setting that you turn on/off, and which is enabled by default.
I have not tried this, but you should be able to set fog dynamically like this:
var map = new mapboxgl.Map
({
container: 'map',
style: 'mapbox://styles/mapbox/satellite-streets-v11',
});
map.on('load', () => {
map.setStyle({
...map.getStyle(),
"fog": {
"range": [-0.5, 3],
"color": "white",
"horizon-blend": 0.1
}
})
});
See the documentation here.

Bing Maps API v8 mutipolyline (multiple segment line) support?

I have several hours trying to find information about support of multipolylines (or multiple segment lines) on Bing Maps API v8, to no avail. I need to have lines made of several segments, in the same way sql server supports it, i.e.
geography::STMLineFromText ('MULTILINESTRING((-84.6725847 31.7707373, -84.6556331 31.7698178)(-93.3023304 33.9048702, -93.3022956 33.9048486))', 4326)
Here, SQL constructs a line made of 2 separate segments.
Leaflet support multipolylines via several arrays of lat/lngs inside an array. i.e. (illustrative purposes)
var polyline = L.polyline([[31.7707373 -84.6725847,31.7698178 -84.6556331] [33.9048702 -93.3023304, 33.9048486 -93.3022956]], { color: 'red', interactive: true, bubblingMouseEvents: false })
How can achieve this under Bing Maps API v8? ideas/suggestions are welcomed!
Thanks!
Yes, you can use MultiLineString's in Bing Maps. If your data is in Well Known Text format, there is a module for that in Bing Maps. Here is a sample: https://bingmapsv8samples.azurewebsites.net/#WKT_Read_Write_Paste (looks like you have to pan/zoom the map to the area of the shape in this sample, but trying your MultiLineString in this sample, it did render).
Here is a code block:
//Load the Well Known Text module.
Microsoft.Maps.loadModule('Microsoft.Maps.WellKnownText', function () {
//Parse well known text string.
var line = Microsoft.Maps.WellKnownText.read('MULTILINESTRING((-84.6725847 31.7707373, -84.6556331 31.7698178)(-93.3023304 33.9048702, -93.3022956 33.9048486))');
//Add parsed shape to the map.
map.entities.push(line);
});

Mapbox WMTS support in OpenLayers

I have created a Mapbox style using Mapbox Studio and set it to be used over WMTS. The URL of the style is:
https://api.mapbox.com/styles/v1/username/styleId/wmts?access_token=token
where styleId, username and token are variable fields.
When I try to create a WMTS layer in OpenLayers using the url above, the tileGrid is created successfully using createFromCapabilitiesMatrixSet but I get a response error Invalid query param layer from Mapbox.
After some investigation, I noticed that:
The response error persists for all query parameters that are appended from OpenLayers when creating the tile load function. It looks like that Mapbox does not recognise them properly.
OpenLayers website and Mapbox also give examples on using XYZ layers for integration between them.
So, is this some kind of unsupported feature of OpenLayers or do I need to configure anything additional when creating the WMTS OpenLayers?
It's much simpler to set up as a standard OpenLayers XYZ layer using
url: 'https://api.mapbox.com/styles/v1/username/styleId/tiles/{z}/{x}/{y}?access_token=token'
as in the examples.
Mapbox provides WMTS support for compatibility with some other systems. It can also be used in OpenLayers, the setup would be
var parser = new ol.format.WMTSCapabilities();
fetch('https://api.mapbox.com/styles/v1/username/styleId/wmts?access_token=token').then(function(response) {
return response.text();
}).then(function(text) {
var layer = new ol.layer.Tile({
source: new ol.source.WMTS(
ol.source.WMTS.optionsFromCapabilities(parser.read(text), {
layer: 'styleId',
matrixSet: 'EPSG:3857'
})
)
});
....
....
....
....
});
Both methods will ultimately load the same tile urls, so there's no advantage in using WMTS where XYZ is supported.

Use topoJSON in Leaflet map

I'm learning how to use Leaflet to make online interactive maps for public health purposes (experienced ArcGIS user, Mapbox TileMill). I'm taking it slow so I understand each piece of code, and I'm working from the Leaflet choropleth example as I want to make choropleth maps. The current task I'm stuck on is how to correctly add topoJSON data to a Leaflet map. I've tried the following code to convert the us states geoJSON to topoJSON, but it hasn't worked. Any suggestions?
var geojson;
var test = topojson.feature(us-states-topo, us-states-topo.objects.layer1 );
geojson = L.geoJson(test, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
I've reviewed the topoJSON API reference, but I'm sure I must be making a simple error as I am a beginner to JavaScript in general. Thank you all for your help!
Best
Eli
I'd recommend using your browser debug tools to start through debugging this.
var test = topojson.feature(us-states-topo, us-states-topo.objects.layer1 );
This is not valid JavaScript: us-states-topo is not a valid variable name, since -s are not permitted.

Code First TVF in 6.1.0-alpha1-30113

EF People,
My understanding is that the newly made public APIs for metadata will allow us to add enough metadata in to the model so that TVF can be called and be composable.
If anyone can point me in the right direction I would greatly appreciate it. Without Composable TVF I have to jump through some major work a rounds.
From looking at the unit test it looks like something a long this line of thought:
var functionImport = EdmFunction.Create()
"Foo", "Bar", DataSpace.CSpace,
new EdmFunctionPayload
{
IsComposable = true,
IsFunctionImport = true,
ReturnParameters = new[]
{
FunctionParameter.Create("functionname", EdmType.GetBuiltInType()
EdmConstants.ReturnType,
TypeUsage.Create(collectionTypeMock.Object),
ParameterMode.ReturnValue),
}
});
...
entityContainer.AddFunctionImport(functionImport);
Thanks,
Brian F
Yes, it is now possible in EF6.1. I actually created a custom model convention which allows using store functions in CodeFirst using the newly opened mapping API. The convention is available on NuGet http://www.nuget.org/packages/EntityFramework.CodeFirstStoreFunctions. Here is the link to the blogpost containing all the details: http://blog.3d-logic.com/2014/04/09/support-for-store-functions-tvfs-and-stored-procs-in-entity-framework-6-1/. The project is open source and you can get sources here: https://codefirstfunctions.codeplex.com/