angular2之地图

import { Injectable } from ‘@angular/core‘;

import { Http } from ‘@angular/http‘;

import { Observable } from ‘rxjs/Rx‘;

import { DITU_SERVER_URL } from ‘../app.constants‘;

import * as ol from ‘openlayers‘;

@Injectable()

export class MapService {

map: ol.Map;

constructor(private http: Http) { }

// methods

init(lines, points, guiJiLines, guiJiPoints, centerP) {

// let url = ‘http://10.172.71.206:6080/arcgis/rest/services/hzz/hzzditu/MapServer‘;

// let url = ‘http://192.168.0.148:6080/arcgis/rest/services/hzz/hzzditu/MapServer‘;

let url = `${DITU_SERVER_URL}`;

if ((!centerP) || centerP == null || centerP.longitude == null) {

centerP.longitude = 106.499258;

centerP.latitude = 29.535594;

}

let lineStyle = new ol.style.Style({

stroke: new ol.style.Stroke({

color: ‘red‘,

width: 10

})

});

let pointStyle = new ol.style.Style({

image: new ol.style.Icon(/** @type {olx.style.IconOptions} */({

color: ‘#8959A8‘,

crossOrigin: ‘anonymous‘,

src: ‘https://openlayers.org/en/v4.1.1/examples/data/dot.png‘

}))

});

let guiJiLinesStyle = new ol.style.Style({

stroke: new ol.style.Stroke({

color: ‘blue‘,

width: 10

})

});

let guiJiPointsStyle = new ol.style.Style({

image: new ol.style.Icon(/** @type {olx.style.IconOptions} */({

color: ‘#8959A8‘,

crossOrigin: ‘anonymous‘,

src: ‘https://openlayers.org/en/v4.1.1/examples/data/dot.png‘

}))

});

let features = [];

for (let i = 0; i < lines.length; i++) {

let arr = lines[i];

let pointList = [];

for (let j = 0; j < arr.length; j++) {

let p = arr[j];

pointList.push(ol.proj.fromLonLat([new Number(p.longitude), new Number(p.latitude)]));

}

let feature = new ol.Feature(new ol.geom.LineString(pointList));

feature.setStyle(lineStyle);

features.push(feature);

}

for (let i = 0; i < points.length; i++) {

let point = points[i];

let pointFea = new ol.Feature({

geometry: new ol.geom.Point(ol.proj.fromLonLat([new Number(point.longitude), new Number(point.latitude)]))

});

pointFea.setStyle(pointStyle);

features.push(pointFea);

}

let source = new ol.source.Vector({

features: features

});

let layer = new ol.layer.Vector({

source: source

});

//巡河轨迹

let features2 = [];

for (let i = 0; i < guiJiLines.length; i++) {

let arr = guiJiLines[i];

let pointList = [];

for (let j = 0; j < arr.length; j++) {

let p = arr[j];

pointList.push(ol.proj.fromLonLat([new Number(p.longitude), new Number(p.latitude)]));

}

let feature = new ol.Feature(new ol.geom.LineString(pointList));

feature.setStyle(guiJiLinesStyle);

features2.push(feature);

}

for (let i = 0; i < guiJiPoints.length; i++) {

let point = guiJiPoints[i];

let pointFea = new ol.Feature({

geometry: new ol.geom.Point(ol.proj.fromLonLat([new Number(point.longitude), new Number(point.latitude)]))

});

pointFea.setStyle(guiJiPointsStyle);

features2.push(pointFea);

}

let source2 = new ol.source.Vector({

features: features2

});

let layer2 = new ol.layer.Vector({

source: source2

});

if (this.map) {

this.map.getTargetElement().innerHTML = ‘‘;

this.map = null;

}

this.map = new ol.Map({

target: ‘map‘,

layers: [

// new ol.layer.Tile({

// source: new ol.source.OSM()

// }),

new ol.layer.Tile({

source: new ol.source.XYZ({

url: url

})

}),

layer,

layer2

],

view: new ol.View({

center: ol.proj.fromLonLat([new Number(centerP.longitude), new Number(centerP.latitude)]),

// center: ol.proj.fromLonLat([106.499258, 29.535594]),

zoom: 14

})

});

}

}

export const DITU_SERVER_URL = ‘http://webrd03.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=8‘; // 高德

时间: 2024-10-09 02:36:22

angular2之地图的相关文章

Ionic2使用百度地图API(JS)出现白屏解决方案

最近自学ionic2,写了一个内嵌百度地图JS的demo,实际跑起来之后出现了大家常见的白屏问题.. 最初的实现是这样的: 首先主页内嵌了一个百度地图插件 <div id="Bmap" style="width: 100%;height: 100%"> 之后menu中一个引导的子页面也内嵌了一个百度地图 <div id="Bmap" style="width: 100%;height: 100%"> 然

Angular2 和TypeScript

Angular2 和TypeScript 原文链接:https://www.infoq.com/articles/Angular2-TypeScript-High-Level-Overview 作者:  Yakov Fain Posted on  Apr 26, 2016 -----------------------------------------------------------------------------------------------------------------

百度地图跟angular的结合

我现在做的一个项目是angular,但是我用直接引用百度地图的方法引进js,写html,js代码,发现,我去,报错了,我一开始还以为是百度地图跟angular有冲突,然后我就去搜索啊,发现angular也有一个百度地图插件,无奈我用了报错了,网上说要用angular2版本才能兼容,但是我又不会下载2版本,所以我就放弃了,然后呢,我又去解决我一开始的那个错误了,发现,玛德我傻逼了,首先来说一下百度地图怎么用吧,很简单,上代码 首先引入js <script type="text/javascr

[译]Angular2 和TypeScript -- 一次简要的预览

原文链接:https://www.infoq.com/articles/Angular2-TypeScript-High-Level-Overview 作者:  Yakov Fain Posted on  Apr 26, 2016 ------------------------------------------------------------------------------------------------------------------------------ Angular

百度地图API实现批量地址解析

1.前言 写这篇文章的原因是最近做一个GIS项目在网上爬取了一些数据,无奈只有地址的文字信息没有坐标信息,如何把信息显现在地图上呢?很纠结啊,查看了一下百度地图API惊奇的发现百度提供了地址解析的API,然后查看了他的Demo后豁然开朗,所以动手将自己的文字信息数据进行解析坐标信息.下面开始讲解. 2.方案 (1)自己数据库中的数据 (2)百度地图API Demo <!DOCTYPE html> <html> <head> <meta http-equiv=&qu

【API】高德地图API JS实现获取坐标和回显点标记

1.搜索+选择+获取经纬度和详细地址 2.回显数据并点标记 3.实现 第一步:引入资源文件 <!--引入高德地图JSAPI --><script src="//webapi.amap.com/maps?v=1.3&key=在官网申请一个key"></script><!--引入UI组件库(1.0版本) --><script src="//webapi.amap.com/ui/1.0/main.js">

js中实现高德地图坐标经纬度转百度地图坐标

1 function tobdMap(x, y) { 2 var x_pi = 3.14159265358979324 * 3000.0 / 180.0; 3 var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); 4 var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); 5 var bd_lon = z * Math.cos(theta) + 0.00

DEDE5.7如何制作网站地图?

DEDE用的人很多,可能大家在使用的过程中会碰到一些问 题,这很正常的,今天我们来讲讲DEDE5.7如何制作网站地图,其实网站地图分两种,一种做给网友看的,方便网友可以方便地找到自己想浏览的内容,另外 一种是做给搜索引擎蜘蛛看,方便蜘蛛在你网站上面抓取内容.    当然,我们这里讲的主要是针对蜘蛛的,因为DEDE默认的就有针对用户的网站地图,主要是以栏目的形式展现,这个可以在DEDE后台自行生成.其实大家印象当中的网站地图是XML格式的,一般命名成sitemap.xml,接下来进入正题.    

baidu地图:实现多点连线渲染

<script type="text/javascript"> var points = [ {"Lng":120.17787645967861,"Lat":30.251826748722667}, {"Lng":120.17786646842835,"Lat":30.251826580357911} ]; </script> <!DOCTYPE html> <ht