Commit 62d739fc authored by Sebastian's avatar Sebastian

merge.

parents 39000f0a 003fadab
......@@ -17,7 +17,7 @@ import OlVectorLayer from 'ol/layer/vector';
import { fromLonLat } from 'ol/proj';
import { transformExtent } from 'ol/proj';
import OlPoint from 'ol/geom/Point';
import OlLineString from 'ol/geom/LineString';
import OlLineString from 'ol/geom/LineString';
import { LogService } from './log.service';
import { OsmNode } from '../models/OsmNode';
import { defaults as OlDefaultControls } from 'ol/control.js';
......@@ -61,7 +61,7 @@ export class MapService {
this.coordinates = [7.147,51.26];
this.changeText();
this.zoom = 12;
this.iconLayer = new OlVectorLayer({
style: function(feature) {
......@@ -79,7 +79,10 @@ export class MapService {
this.source = new OlXYZ({
url: 'http://tile.osm.org/{z}/{x}/{y}.png'
//url:'https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png'
//url:'https://stamen-tiles.a.ssl.fastly.net/{z}/{x}/{y}.png'
//url: 'http://tile.stamen.com/terrain/{z}/{x}/{y}.png'
//url:'https://maps.wikimedia.org/osm-intl/${z}/${x}/${y}.png'
//url: 'http://tile.thunderforest.com/landscape/${z}/${x}/${y}.png'
});
this.mapLayer = new OlTileLayer({
......@@ -91,12 +94,14 @@ export class MapService {
zoom: this.zoom
});
}
createElement(coords,node,setId?:string){
if(!setId){
setId='default';
}
if(node.mapId== -1){
node.mapId = parseInt(node.osmId)+""+(Math.floor(Math.random()*100000)+1);
}
......@@ -141,16 +146,16 @@ export class MapService {
}))
});
}
fitView(){
this.map.getView().fit(this.iconLayer.getSource().getExtent());
this.logger.debug("Fitting view around "+this.icons.length+ " elements.");
this.coordinates = this.getCenter();
this.zoom = this.map.getView().getZoom();
if(this.zoom > 18){
this.zoom = 18;
}
......@@ -162,12 +167,12 @@ export class MapService {
}));
}
addNode(node:OsmNode,setId?:string){
if(!setId){
setId='default';
}
this.icons.push(this.createElement([(node.lon),(node.lat)],node,setId));
this.map.removeLayer(this.iconLayer);
this.iconLayer = new OlVectorLayer({
style: function(feature) {
......@@ -185,7 +190,7 @@ export class MapService {
this.nodeSets.get(setId).push(node);
}
}
showConnections(){
this.connections.length = 0;
this.nodeSets.forEach( (nodeSet: Array<OsmNode>,key:string)=>{
......@@ -351,7 +356,6 @@ export class MapService {
}
removeNode(node:OsmNode,setId?:string){
if(!setId){
setId='default';
......@@ -372,7 +376,7 @@ export class MapService {
}
togglePeerVisibility(parent: OsmNode,peer: OsmNode){
if(peer.mapId == -1){
this.addNode(peer);
this.showConnections();
......@@ -416,13 +420,13 @@ export class MapService {
stroke: new OlStroke({color: '#cdcdcd',width: 3})
});
}
createLine(lhs: OsmNode, rhs:OsmNode){
let lhsCoords = fromLonLat( [lhs.lon,lhs.lat] );
let rhsCoords = fromLonLat( [rhs.lon,rhs.lat] );
let lineString = new OlLineString([lhsCoords,rhsCoords]);
let feature = new OlFeature( {geometry: lineString});
feature.set('style',this.createLineStyle());
......@@ -430,8 +434,8 @@ export class MapService {
//;
//feature.set('style', this.createStyle('assets/img/map-marker.png', undefined));
//feature.set('style', this.createLineStyle());
}
showLine(lhs: OsmNode, rhs:OsmNode){
let feature = this.createLine(lhs,rhs);
......@@ -453,20 +457,20 @@ export class MapService {
view: this.view,
controls:null
});
let handler = this.clickHandler;
this.map.on('click', this.clickHandler);
}
hasNode(node:OsmNode){
for(let feature of this.icons){
if(feature.getId() == node.mapId){
return true;
}
}
}
return false;
}
internalClickHandler(ev: OlMapBrowserEvent){
console.log(this.router.url);
......@@ -484,7 +488,7 @@ export class MapService {
let map=this.map;
let pixel = ev.pixel;
let features = map.getFeaturesAtPixel(pixel);
let data=features;
let clickedElement:OsmNode;
if(data && data.length > 0){
......@@ -511,7 +515,7 @@ export class MapService {
}
getCenter(){
let bbox=new Rectangle(this.getBoundingBox(null));
return [ 0.5*(bbox.minX+bbox.maxX) , 0.5*(bbox.minY+bbox.maxY)]
}
clickHandler(ev: OlMapBrowserEvent){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment