Code Monkey home page Code Monkey logo

map-site's Introduction

Map Site templates from MapBox are a way to jumpstart building a map-based web feature. The map-site templates bundles common HTML and CSS formatting with integration to the MapBox Javascript API.

To build a project based on this template, fork this repository, edit the HTML content and CSS, and alter the configuration script.

Using this template

Edit the content by adjusting, removing, or adding to index.html. This is the main markup document with the content and layout for the map-site.

Adjust the design by editing the style.css file and adding any additional supporting structure to index.html.

Set the map features by writing a configuration script at the bottom of index.html.

HTML layout

The html markup for the template is in index.html. It's a simple HTML5 page layout. Generally, there are three things to change in this document:

  1. Content elements like the title, h1, and div#about elements
  2. Add new container elements for features like maps, layer switchers, and geocoders
  3. Layout structure, as controlled by the class attribute on the body element

There are three layout classes that can be applied to the body element:

  • right A full screen map with a header and right content sidebar (default)
  • left A similar full screen map with a centered header and left content sidebar
  • hero An inline map hero with a header and full-width, scrollable content section

CSS styles

Most of the hard work on a microsite build is template design implemented through CSS. This template by default is simple and clean, and it's based on the tiles.mapbox.com full map view. This design and be completely overridden by applying new CSS styles. style.css contains all the layout and typographic styles as well as some overridden styles for map controls, as well as a reset stylesheet. Implement your design by editing this file.

Javascript interaction

The map is configured in script.js and takes advantage of many MapBox Javascript API features - so the documentation for the MapBox Javascript API applies to every part of this site.

Additional integration is added with mapbox.jquery.js, which automatically binds links that control the map - see the navigation links for examples.

All the following controls require that the id of the element containing the map be specified using the data-control attribute. In this case it is data-control="map". This attribute may be placed in any of the controls' parent elements.

Address search

To search for an address, we need a geocoding service that converts a plain-text address query into a geographic location. This template uses MapQuest Open search, which is free to use for noncommercial and commercial applications alike. If you'd like to use another service, edit the geocode function in script.js.

To add an address search to your page, build a simple html form to gather user input:

<div data-control="geocode" id="search">
    <form class="geocode">
        <input placeholder="Search for an address" type="text">
        <input type="submit" />
        <div id="geocode-error"></div>
    </form>
</div>

By specifying data-control="gecode" on the div containing your form, mapbox.jquery.geocoder.js will bind a function that handles address searches and repositions the map accordingly. If the geocoder has a successful response to a search, it will center the map and zoom it to show the bounding box extent of that response. If the bounding box is small enough to zoom the map to its maximum zoom, the geocoder will also place a pin with a star over the response's exact location.

Easing links

To link to a geographic location add at least one of the following data attributes:

  • data-lat: The latitude of the location.
  • data-lon: The longitude of the location.
  • data-zoom: The zoom level.
<a data-lat="39" data-lon"77" data-zoom="10" href="#">

If you specify any of these, the link will be automatically bound to the map.

Layer Switcher

Use data-control="switcher" to bind all links in child elements to the layer switcher function. Specify the layer by setting the href attribute of anchors to the layer's name. There are two optional layer attributes:

  • data-group: Specifies the group, defaulting to 0. Only one layer per group can be enabled at any time.
  • data-toggle="true": Allow a layer to be toggled off.
<div data-control="switcher">
    <a data-group="0" href="#streets">Streets</a>
    <a data-group="1" href="#construction">Construction projects</a>
    <a data-group="1" href="#building">Building permits</a>
</div>

Easing links can be used together with the layer switcher.

map-site's People

Contributors

ansis avatar dhcole avatar michael avatar tmcw avatar wildintellect avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

map-site's Issues

Better support for custom controls

Beyond the 'control' array, little tweaks like having movetips on one layer and tooltips on another require users to hack the core, which is something this should strongly aim to avoid.

Options: providing functions instead of strings that can be executed
...

Weird legend code

Seeing the code

MM_map.legend.content(' ');

What is going on here? @dhcole can you file a ticket at Wax if there is a bug here (and if there are any other bugs this code is working around)

Persistent inline tooltips are broken

Once triggered, persistent tooltips become absolute positioned, and don't move with the map:

Is there a way to make these move relative to the map, or should we disable persistence on click?

Include source sprite

For a user wishing to change colours, add additional elements to the sprite or even alter the presentation of the magnifying glass as the search icon it would be nice if an .svg file was included.

Refactor link-to-layer

The way that this does links to layers is a bit suboptimal, it won't handle multiple links and you can't decide whether you want a layer & ease or just one or the other. It might be useful to have a slightly better hash layout like #mapid/12/37.7706/-122.3782 and a class on links to decide whether to ease or not.

active layout state and title alignment.

I'd like to run a couple ideas before implementation

  1. I feel like the icon and title just doesn't sit right when entire site is fluid and the header is fixed aligned. This should remain 20px off the left side of the screen.
  2. To make it clear the links at the top right alter the presentation of the layout I think the should be centered vertically and have an active button state implying which state is turned on.

Tooltips don't get updated when switching layers if using movetips

Tooltips don't switch to the new layer if you are using both movetips and tooltips.

A separate wax.mm.interaction() object is created for both movetips and tooltips, and the reference to the movetip one overwrites the tooltip one. This means the tooltips don't get updated when setting an overlay

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.