# OpenLayers
The OpenLayerView is a way of showing data point on a map. Often, it is used to show GPS data, or fixed position of any sensor. This View can also display path using the corresponding Layer.
The View is based on OpenLayers (opens new window) framework.
API Reference
# Properties configuration
The map property can override the default map. This is the Map (opens new window) OpenLayers object.
The initialView defines some properties for the creation of the inner View (opens new window).
The overlayLayers are TileLayer (opens new window) OpenLayers objects to use as overlay layer.
The baseLayers are TileLayer (opens new window) OpenLayers objects to use as base layer. The default OSM (opens new window) layer is provided
# Initial Map
The initial Map & View can be passed to override the default Map (opens new window) / View (opens new window).
Here is the corresponding code that initializes the initial-view if none is passed in parameter:
this.map = new Map();
this.map.addInteraction(new DragRotateAndZoom());
this.map.addInteraction(new MouseWheelZoom({
constrainResolution: true, // force zooming to a integer zoom,
duration: 200
}));
this.map.addControl(new FullScreen());
const layerSwitcher = new LayerSwitcher({
tipLabel: 'Legend', // Optional label for button
groupSelectStyle: 'children' // Can be 'children' [default], 'group' or 'none'
});
this.map.addControl(layerSwitcher);
this.map.addControl(new ZoomSlider());
# Supported layers
The view supports type layers:
- marker
- polyline
# Example
// create data source for Android phone GPS
import SosGetResultJson from 'osh-js/core/datasource/SosGetResultJson.js';
import PointMarkerLayer from 'osh-js/core/ui/layer/PointMarkerLayer.js';
import OpenLayerView from 'osh-js/core/ui/view/map/OpenLayerView.js';
// create data source for Android phone GPS
let gpsDataSource = new SosGetResultJson("android-GPS", {
protocol: "ws",
service: "SOS",
endpointUrl: "sensiasoft.net:8181/sensorhub/sos",
offeringID: "urn:android:device:060693280a28e015-sos",
observedProperty: "http://sensorml.com/ont/swe/property/Location",
startTime: "2015-02-16T07:58:32Z",
endTime: "2015-02-16T08:09:00Z",
replaySpeed: 2
});
// style it with a moving point marker
let pointMarker = new PointMarkerLayer({
dataSourceId: gpsDataSource.id,
getLocation: (rec) => ({
x: rec.location.lon,
y: rec.location.lat
}),
orientation: {
heading: 0
},
icon: 'images/car-location.png',
iconAnchor: [16, 64],
iconSize: [32, 64],
name: "Android Phone GPS"
});
// #region snippet_ol_location_view
// create Cesium view
let olView = new OpenLayerView({
container: 'ol-map',
layers: [pointMarker],
autoZoomOnFirstMarker: true
});
// #endregion snippet_ol_location_view
// start streaming
gpsDataSource.connect();