I want to insert trajectories (feature collection of linestrings) in my OSM using Leaflet extracted by a Java application. Starting the server, I want to compute those trajectories and transmit them to my OSM. For using geo positions I am working with the GeoJson library from filosganga: https://github.com/filosganga/geogson
Currently, I need a hint how to do that as my following approach leads to an 404 error message saying:
http://localhost:8080/function (data) { linestrings = L.geoJSON([ data ], { style : function(feature) { //console.log(feature); return feature.properties && feature.properties.style; } }); linestrings.addTo(map); }
My html file looks like the following:
var linestrings;
function reqListener(){
// var url="/test";
$.getJSON(function(data) {
linestrings = L.geoJSON([ data ], {
style : function(feature) {
//console.log(feature);
return feature.properties && feature.properties.style;
}
});
linestrings.addTo(map);
});
}
reqListener();
My Java based server application is the following:
public void TestClass(){
get("/test", (request, responce) -> {return Trajectories.writeTestClass(request, responce);});
}
It already worked for applications where an OSM based event (mouse click or change of boundary) triggered the extraction and further transmission of geo data to OSM. But this time the Java application should trigger the transmission of those trajectories to OSM.
Any help or hint would be wonderful. Thanks
Related
I have created a Google Geochart widget some time ago with an older Google JS library version. Nowadays Google advised to upgrade to update to the loader api instead of the jsapi. No matter how I load the libraries, for me the visualization library doesn't load properly, hence I get an undefined when trying to instantiate a GeoChart object. Did anybody else encounter this issue as well?
(The JS code is in the form of Dojo widget functions)
update : function(obj, callback){
this._contextObj = obj;
this._resetSubscriptions();
if (this.apiAccessKey && this.apiAccessKey !== "") {
google.charts.load('current', {
'packages':['geochart'],
// Note: you will need to get a mapsApiKey for your project.
// See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
'mapsApiKey': this.apiAccessKey
});
google.charts.setOnLoadCallback(this.drawChart(callback));
} else {
var message = " Google Geochart needs an active API key to work!";
console.error(this._logNode + message);
alert(message);
}
},
drawChart : function (callback) {
// Run this as soon as google charts is loaded.
// Create map and its container.
if (!this.geoMap) {
this.geoMap = new google.visualization.GeoChart(this.geoMapContainer);
}
if (this._contextObj){
this._getObjects(this._contextObj.getGuid,callback);
} else {
this._getObjects(null,callback);
}
this._executeCallback(callback);
},
setOnLoadCallback expects a reference to a function --> this.drawChart
not the result of a function --> this.drawChart(callback)
try as follows...
google.charts.setOnLoadCallback(function () {
this.drawChart(callback);
});
I have added a feature map to my Open Layers 2 map, by using the following code. When I click a spot on the map, it correctly retrieves the feature name for that place according to the feature layer.
Code:
featureControl = new OpenLayers.Control.WMSGetFeatureInfo({
url: featureLayer.url,
title: '',
layers: [featureLayer],
infoFormat: 'text/xml',
queryVisible: true
});
featureControl.events.register('getfeatureinfo', this, function (event) {
var xml = new window.DOMParser().parseFromString(event.text, 'application/xml'),
path = featureLayer.$featureInfoXPath,
featureName;
try {
featureName = xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null).iterateNext().value;
console.log('got the feature:', featureName)
} catch (error) {
console.log('error', error);
}
});
map.addControl(featureControl);
featureControl.activate();
However, I would like to trigger this retrieval of the feature name on other events as well, such as when I type in an address in an input field. So I am looking for a mechanism to trigger the getfeatureinfo event by something other than "click". Is this possible? And if so, how?
I have an Openlayers map with several WMS layers from which I want to request feature information through "getGetFeatureInfoUrl". Visibility of layers can be turned on/off in the layer tree. I'd like to, upon clicking somewhere in the map:
Get Feature Info ONLY for layers that are currently visible
and, if there are more than one layers at the chosen location, get the Feature Info for all of them.
I used the sample code from the OpenLayers website. I tried variants of this code bit
var url = layers[2].getSource().getGetFeatureInfoUrl(
evt1.coordinate, viewResolution, 'EPSG:3857', {
'INFO_FORMAT': 'text/html',
'FEATURE_COUNT': '300'
});
like
var url = layers[].getSource().getGetFeatureInfoUrl( or
var url = layers[1,2].getSource().getGetFeatureInfoUrl(, but either no Feature Info is delivered, or merely for the last layer - regardless of whether it is visible or not.
I created a JSFiddle with two sample layers here: http://jsfiddle.net/kidalex/j34xzaa3/5/
Similar questions were asked before, like here: https://gis.stackexchange.com/questions/114297/querying-multiple-wms-layers-in-ol3-and-adding-to-a-single-popup-window; but I cannot fathom how to apply the solutions (JS/OL newbie here).
You should iterate over your layers and only call getFeatureInfo if they are visible and not the base layer, try something like:
map.on('singleclick', function (evt1) {
document.getElementById('info').innerHTML = '';
var viewResolution = /** #type {number} */
(view.getResolution());
var url = '';
document.getElementById('info').innerHTML ='';
layers.forEach(function (layer, i, layers) {
if (layer.getVisible() && layer.get('name')!='Basemap') {
url = layer.getSource().getGetFeatureInfoUrl(evt1.coordinate, viewResolution, 'EPSG:3857', {
'INFO_FORMAT': 'text/html',
'FEATURE_COUNT': '300'
});
if (url) {
document.getElementById('info').innerHTML +=
'<iframe seamless src="' + url + '"></iframe>';
}
}
});
});
EDIT: grammar
I am rendering GeoJSON containing LineStrings on a Leaflet map. For some reason the end points of each path are connected like in a circle (see blue line in the screenshot).
Here is the relevant portion of code ..
renderGeoJson = function(link) {
var url = $(link).attr("href");
$.getJSON(url, function(data) {
var feature = data.features[0];
var color = nameToColor(feature.properties.name);
var geojson = L.geoJson(data, {
style: {
type: "LineString",
color: color,
weight: 3,
opacity: 0.75
}
});
geojson.addTo(map);
});
}
It may that the originial GeoJSON file has errors - it may be some option on Leaflet - please tell me.
Pointing to the specific GeoJSON file would make this answerable - would guess that it's an issue with the data since other data in that repository has issues.
I have a web page that loads a kml file for viewing using the Google Earth ge plugin. The file loads and displays fine. However, I can get the plugin to move to a lat/lon at the end of the file. The load always leaves the camera at the lat/lon that corresponds to the end point of the kml file.
Here's the code:
var ge;
google.load("earth", "1");
google.load("maps", "2");
function init() {
google.earth.createInstance('map3d', initCallback, failureCallback);
}
function initCallback(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
var url = 'http://rallyroadie.org/wordpress/ge/vladi_finish.kml';
google.earth.fetchKml(ge, url, finished);
}
function finished(object) {
if (!object) {
setTimeout(function() {
alert('Bad or null KML.');
}, 0);
return;
}
ge.getFeatures().appendChild(object);
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
// Set new latitude and longitude values.
lookAt.setLatitude(43.023157);
lookAt.setLongitude(131.853040);
// Update the view in Google Earth.
ge.getView().setAbstractView(lookAt);
}
function failureCallback(errorCode) {
}
google.setOnLoadCallback(init);
You can see the page at http://rallyroadie.org/wordpress/ge/vladi.html
TIA,
Paul
Are you wanting to know how to set the initial view? If so:
You are currently setting it with this code -
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
// Set new latitude and longitude values.
lookAt.setLatitude(43.023157);
lookAt.setLongitude(131.853040);
// Update the view in Google Earth.
ge.getView().setAbstractView(lookAt);
Try playing with different Latitude and Longitude numbers and you will see the difference.
You can also use stuff like lookAt.setRange, lookAt.setTilt and lookAt.setAltitude
See this link for more details
It has nothing to do with the .kml file you loaded.