Openlayer4 - 最好最强大的开源地图引擎

# github
https://github.com/openlayers/openlayers

# 官网
http://openlayers.org/

# API
http://openlayers.org/en/latest/apidoc/index.html

# 中文教程
http://weilin.me/ol3-primer/

 

坐标可以在这里查询

# 百度接口
http://api.map.baidu.com/lbsapi/getpoint/index.html

# openlayer 实现的deom
http://openlayers.org/en/latest/examples/mouse-position.html

 

npm install ol --save
https://github.com/openlayers/openlayers/tree/master/package   
 

一些非demo的收集和备注

# 加载地图时的进度条
http://openlayers.org/en/latest/examples/tile-load-events.html

 

 

demo 1 : 

清注意,这个demo中的大部分API都会在后续频繁使用的

const ol = require('js/ol.js');
require('css/ol.css');

/**
  坐标可以在这里查询 : 
  百度地图API : http://api.map.baidu.com/lbsapi/getpoint/index.html
  openlayer官方API : http://openlayers.org/en/latest/examples/mouse-position.html
*/

  var map = new ol.Map({
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      })
    ],
    target: 'map',
    view: new ol.View({
      projection: 'EPSG:4326',//'EPSG:3857', 
      center: [105.4265, 34.7782],
      zoom: 5,
      minZoom:4,
      maxZoom:6
    })
  });

 

demo2 : 结合jquery + bootstrap实现点击气泡 

http://openlayers.org/en/latest/examples/overlay.html

核心知识点:map.on绑定click事件、获取当前地理位置参数。

Openlayer4 - 最好最强大的开源地图引擎

 

const ol = require('js/ol.js');
const $ = require("jquery"); if ( typeof window === "object") {window.jQuery = $;};
require("bootstrap");
require('css/ol.css');
require('css/Overlay.css');


var layer = new ol.layer.Tile({
        source: new ol.source.OSM()
});

var map = new ol.Map({
  layers: [layer],
  target: 'map',
  view: new ol.View({
    center: [0, 0],
    zoom: 2
  })
});

var pos = ol.proj.fromLonLat([16.3725, 48.208889]);

// Vienna marker
var marker = new ol.Overlay({
  position: pos,
  positioning: 'center-center',
  element: document.getElementById('marker'),
  stopEvent: false
});
map.addOverlay(marker);

// Vienna label
var vienna = new ol.Overlay({
  position: pos,
  element: document.getElementById('vienna')
});
map.addOverlay(vienna);

// Popup showing the position the user clicked
var popup = new ol.Overlay({
  element: document.getElementById('popup')
});
map.addOverlay(popup);

map.on('click', function(evt) {
  var element = popup.getElement();
  var coordinate = evt.coordinate;
  var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
      coordinate, 'EPSG:3857', 'EPSG:4326'));

  $(element).popover('destroy');
  popup.setPosition(coordinate);
  // the keys are quoted to prevent renaming in ADVANCED mode.
  $(element).popover({
    'placement': 'top',
    'animation': false,
    'html': true,
    'content': '<p>The location you clicked was:</p><code>' + hdms + '</code>'
  });
  $(element).popover('show');
});
View Code

相关文章:

  • 2023-03-23
  • 2021-11-13
  • 2021-07-10
  • 2021-04-09
  • 2021-11-29
  • 2021-07-11
  • 2022-02-18
猜你喜欢
  • 2021-08-20
  • 2021-12-12
  • 2021-12-07
  • 2022-01-12
相关资源
相似解决方案