Git Product home page Git Product logo

glmap's Introduction

THIS REPOSITORY IS NO LONGER MAINTAINED

Functionality is now fully integrated in OSM Buildings viewer. https://github.com/OSMBuildings/OSMBuildings

GLMap

A very basic map engine. Mostly provides events and layer handling. This is used for OSM Buildings (http://osmbuildings.org/).

Documentation

All geo coordinates are in EPSG:4326.

Quick integration

Link all required libraries in your HTML head section. Files are provided in folder /dist.

<head>
  <link rel="stylesheet" href="GLMap/GLMap.css">
  <script src="GLMap/GLMap.js"></script>
</head>

<body>
  <div id="map"></div>

In a script section initialize the map and add a map tile layer.

  var map = new GLMap('map', {
    position: { latitude:52.52000, longitude:13.41000 },
    zoom: 16
  });

GLMap Options

option value description
position object geo position of map center
zoom float map zoom
rotation float map rotation
tilt float map tilt
bend float map bend
disabled boolean disables user input, default false
minZoom float minimum allowed zoom
maxZoom float maximum allowed zoom
attribution string attribution, optional
state boolean stores map position/rotation in url, default false
bounds object n, e, s, w coordinates of bounds where the map can be moved within

GLMap methods

method parameters description
on type, function add an event listener, types are: change, resize, pointerdown, pointermove, pointerup
off type, fn remove event listener
setDisabled  boolean disables any user input
isDisabled check wheether user input is disabled
project latitude, longitude, worldSize transforms geo coordinates to world pixel coordinates (tile size << zoom)
unproject x, y, worldSize transforms world (tile size << zoom) pixel coordinates to geo coordinates (EPSG:4326)
transform latitude, longitude, elevation transforms a geo coordinate + elevation to screen position
getBounds returns geocordinates of current map view, respects tilt and rotation but ignores perspective
setZoom float sets current zoom
getZoom   gets current zoom
setPosition object sets current geo position of map center
getPosition gets current geo position of map center
setSize object {width,height} sets current map size in pixels
getSize gets current map size in pixels
setRotation float sets current rotation
getRotation gets current rotation
setTilt float sets current tilt
getTilt gets current tilt
setBend float sets current bend
getBend gets current bend

Examples

Map control buttons

<div class="control tilt">
  <button class="dec">&#8601;</button>
  <button class="inc">&#8599;</button>
</div>

<div class="control rotation">
  <button class="inc">&#8630;</button>
  <button class="dec">&#8631;</button>
</div>

<div class="control zoom">
  <button class="dec">-</button>
  <button class="inc">+</button>
</div>

<div class="control bend">
  <button class="dec">B-</button>
  <button class="inc">B+</button>
</div>
var controlButtons = document.querySelectorAll('.control button');

for (var i = 0; i < controlButtons.length; i++) {
  controlButtons[i].addEventListener('click', function(e) {
    var button = this;
    var parentClassList = button.parentNode.classList;
    var direction = button.classList.contains('inc') ? 1 : -1;
    var increment;
    var property;

    if (parentClassList.contains('tilt')) {
      property = 'Tilt';
      increment = direction*10;
    }
    if (parentClassList.contains('rotation')) {
      property = 'Rotation';
      increment = direction*10;
    }
    if (parentClassList.contains('zoom')) {
      property = 'Zoom';
      increment = direction*1;
    }
    if (parentClassList.contains('bend')) {
      property = 'Bend';
      increment = direction*1;
    }
    if (property) {
      map['set'+ property](map['get'+ property]()+increment);
    }
  });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.