### Example: Tooltip Configuration
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
Configure tooltips to show on click and render HTML content.
```javascript
new Mapkick.Map("map", data, {
tooltips: {
hover: false, // click to show
html: true // allow HTML
}
})
```
--------------------------------
### Clone Repository and Install Dependencies
Source: https://github.com/ankane/mapkick.js/blob/master/README.md
This snippet outlines the steps to set up the development environment for Mapkick.js. It includes cloning the repository, navigating to the directory, and installing npm dependencies.
```sh
git clone https://github.com/ankane/mapkick.js.git
cd mapkick.js
npm install
npm run build-dev
```
--------------------------------
### NPM Installation for Mapkick.js
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/quick-start.md
Install Mapkick.js using npm. This command installs the package into your project's node_modules directory.
```bash
npm install mapkick
```
--------------------------------
### MapLibre Setup with Mapkick.js
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/quick-start.md
Use MapLibre GL JS for a free, token-less map setup with Mapkick.js. Configure the map style using Mapkick.options.
```html
```
--------------------------------
### Example: Trail Configuration
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
Set a maximum trail length and refresh rate when initializing a Mapkick map.
```javascript
new Mapkick.Map("map", data, {
trail: {len: 20},
refresh: 5
})
```
--------------------------------
### NPM Setup with Mapkick.js and Mapbox GL JS
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/quick-start.md
Import Mapkick and Mapbox GL JS when using NPM. Ensure you set your Mapbox access token.
```javascript
import Mapkick from "mapkick"
import mapboxgl from "mapbox-gl"
Mapkick.use(mapboxgl)
mapboxgl.accessToken = "YOUR-TOKEN"
new Mapkick.Map("map", [{latitude: 37.7829, longitude: -122.4190}])
```
--------------------------------
### Mapbox Setup with Mapkick.js
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/quick-start.md
Include Mapbox GL JS and Mapkick.js in your HTML to set up a map. Remember to replace 'YOUR-TOKEN' with your actual Mapbox access token.
```html
```
--------------------------------
### Example: Data Source Callback
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
Use a callback function with `fetch` to load data from an API, handling both successful responses and errors.
```javascript
new Mapkick.Map("map", function(success, fail) {
fetch("/api/locations")
.then(r => r.json())
.then(success)
.catch(() => fail("Unable to load data"))
})
```
--------------------------------
### Mapbox Installation
Source: https://github.com/ankane/mapkick.js/blob/master/README.md
Include Mapbox GL JS CSS and JavaScript files, along with Mapkick.js, in your HTML head. Set your Mapbox access token.
```html
```
--------------------------------
### Implement Live Tracking Map
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/README.md
Set up a live tracking map with auto-refresh and trail visualization. Provides an example of how to stop the refresh mechanism.
```javascript
const tracking = new Mapkick.Map("tracking-map", "/api/live", {
refresh: 5,
trail: {len: 50},
controls: true
})
// Stop when done
document.getElementById("stop-btn").onclick = function() {
tracking.stopRefresh()
}
```
--------------------------------
### ReplayFeature Example Data
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
An example array of ReplayFeature objects representing movement over time. Demonstrates tracking multiple IDs and their respective locations at different times.
```javascript
[
{
id: "bus-1",
latitude: 37.7829,
longitude: -122.4190,
time: "2024-01-01T10:00:00Z"
},
{
id: "bus-1",
latitude: 37.7830,
longitude: -122.4191,
time: "2024-01-01T10:01:00Z"
},
{
id: "bus-2",
latitude: 40.7128,
longitude: -74.0060,
time: "2024-01-01T10:00:00Z"
}
]
```
--------------------------------
### MapLibre Installation
Source: https://github.com/ankane/mapkick.js/blob/master/README.md
Include MapLibre GL JS CSS and JavaScript files, along with Mapkick.js, in your HTML head. Configure Mapkick options for MapLibre.
```html
```
--------------------------------
### PointFeature Example
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
An example of a PointFeature object with various properties set, including coordinates, label, tooltip, color, and icon.
```javascript
{
latitude: 37.7829,
longitude: -122.4190,
label: "San Francisco",
tooltip: "Main office",
color: "#f84d4d",
icon: "office"
}
```
--------------------------------
### TrailFeature Example Data
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
An example array of TrailFeature objects representing a path. Demonstrates tracking a single trail ID across multiple points.
```javascript
[
{id: "vehicle-1", latitude: 37.7829, longitude: -122.4190},
{id: "vehicle-1", latitude: 37.7830, longitude: -122.4191},
{id: "vehicle-1", latitude: 37.7831, longitude: -122.4192},
{id: "vehicle-2", latitude: 40.7128, longitude: -74.0060}
]
```
--------------------------------
### Polygon Geometry Example
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
An example of a Polygon geometry object with an outer boundary and an inner hole, demonstrating the coordinate structure.
```javascript
{
type: "Polygon",
coordinates: [
[[-122.4, 37.8], [-122.4, 37.7], [-122.3, 37.7], [-122.3, 37.8], [-122.4, 37.8]], // outer boundary
[[-122.35, 37.75], [-122.35, 37.72], [-122.32, 37.72], [-122.32, 37.75], [-122.35, 37.75]] // hole
]
}
```
--------------------------------
### AreaFeature Example
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
An example of an AreaFeature object, including a Polygon GeoJSON geometry, label, tooltip, and color.
```javascript
{
geometry: {
type: "Polygon",
coordinates: [[
[-122.4, 37.8],
[-122.4, 37.7],
[-122.3, 37.7],
[-122.3, 37.8],
[-122.4, 37.8]
]]
},
label: "Downtown District",
tooltip: "Central business zone",
color: "#0090ff"
}
```
--------------------------------
### Creating a Map with Instance Overrides
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/README.md
Instantiate a new Mapkick map, overriding global options with instance-specific ones. This example shows how an instance's zoom level takes precedence.
```javascript
new Mapkick.Map("map", data, {
zoom: 15 // overrides zoom: 13 from global options
})
```
--------------------------------
### Example: Custom Marker Color
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
Set a custom marker color when initializing a Mapkick map.
```javascript
new Mapkick.Map("map", data, {
markers: {color: "#3498db"}
})
```
--------------------------------
### Configuring Trail Visualization
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/README.md
Enable and configure trail visualization to display the movement history of objects on the map. This example limits the trail to the last 20 points per vehicle.
```javascript
new Mapkick.Map("map", "/api/vehicles", {
trail: {len: 20}, // keep last 20 points per vehicle
refresh: 5
})
```
--------------------------------
### MultiPolygon Geometry Example
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/types.md
An example of a MultiPolygon geometry object containing two distinct polygons, illustrating the nested coordinate structure.
```javascript
{
type: "MultiPolygon",
coordinates: [
[[[-122.4, 37.8], [-122.4, 37.7], [-122.3, 37.7], [-122.3, 37.8], [-122.4, 37.8]]], // polygon 1
[[[-122.2, 37.8], [-122.2, 37.7], [-122.1, 37.7], [-122.1, 37.8], [-122.2, 37.8]]] // polygon 2
]
}
```
--------------------------------
### Callback Error Handling with XMLHttpRequest
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/errors.md
This example shows how to manage errors using the XMLHttpRequest object within a Mapkick.js callback. It covers network errors, server errors (based on status codes), and issues with JSON parsing, all of which are reported using the `fail()` function.
```javascript
new Mapkick.Map("map", function(success, fail) {
const request = new XMLHttpRequest()
request.open("GET", "/api/locations")
request.onload = function() {
if (request.status === 200) {
try {
success(JSON.parse(request.responseText))
} catch (err) {
fail("Invalid JSON response")
}
} else {
fail("Server error: " + request.statusText)
}
}
request.onerror = function() {
fail("Network error")
}
request.send()
})
```
--------------------------------
### Open README.md
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/DELIVERY_SUMMARY.md
Use this command to open the main README.md file for the project.
```bash
Open: /workspace/home/output/README.md
```
--------------------------------
### Quick Navigation with INDEX.md
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/DELIVERY_SUMMARY.md
Utilize INDEX.md for efficient navigation through the documentation by task type, API component, data type, configuration option, or error message.
```bash
Use INDEX.md for quick navigation by:
- Task type
- API component
- Data type
- Configuration option
- Error message
```
--------------------------------
### Initialize Map for Replaying Data
Source: https://github.com/ankane/mapkick.js/blob/master/README.md
Use this snippet to create a map that can replay historical data. Set the 'replay' option to true and provide the data source.
```javascript
new Mapkick.Map("map", data, {replay: true})
```
--------------------------------
### Initialize Map with Live Updates
Source: https://github.com/ankane/mapkick.js/blob/master/README.md
Use this snippet to create a map that refreshes data from a remote source periodically. Specify the refresh interval in seconds.
```javascript
new Mapkick.Map("map", url, {refresh: 10}) // seconds
```
--------------------------------
### Initialize Map with URL Data
Source: https://github.com/ankane/mapkick.js/blob/master/README.md
Provide a URL that returns JSON data in the expected format to initialize the map.
```javascript
new Mapkick.Map("map", "/restaurants")
```
--------------------------------
### Create Map with Custom Styling
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/quick-start.md
Initialize a new map with custom Mapbox style, zoom level, controls, marker color, and tooltip behavior.
```javascript
new Mapkick.Map("map", data, {
style: "mapbox://styles/mapbox/dark-v11",
zoom: 13,
controls: true,
markers: {color: "#e74c3c"},
tooltips: {hover: true}
})
```
--------------------------------
### Initialize Map with Callback Data
Source: https://github.com/ankane/mapkick.js/blob/master/README.md
Use a callback function to fetch and provide data to the map. The callback should accept success and fail arguments.
```javascript
function fetchData(success, fail) {
success([{latitude: 37.7829, longitude: -122.4190}])
// or fail("Data not available")
}
new Mapkick.Map("map", fetchData)
```
--------------------------------
### Mapkick.js Missing Latitude Error Example
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/errors.md
Illustrates data that triggers a 'missing latitude' error. Use any latitude alias (latitude, lat) for correct data.
```javascript
// Error at index 1
new Mapkick.Map("map", [
{latitude: 37.7829, longitude: -122.4190},
{longitude: -122.4190} // missing latitude
])
// Correct: use any alias
[
{latitude: 37.7829, longitude: -122.4190},
{lat: 37.8000, longitude: -122.4200},
{latitude: 37.9000, lng: -122.4300}
]
```
--------------------------------
### Basic Map with Points using Mapkick.js
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/quick-start.md
Create a basic map with multiple points. Each point can have a label and a tooltip that appears on hover.
```javascript
new Mapkick.Map("map", [
{
latitude: 37.7829,
longitude: -122.4190,
label: "San Francisco",
tooltip: "Headquarters"
},
{
latitude: 40.7128,
longitude: -74.0060,
label: "New York",
tooltip: "East Coast Office"
}
])
```
--------------------------------
### Get Underlying Map Object
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/api-reference-areamap.md
Retrieves the Mapbox GL or MapLibre GL map instance. Use this for advanced customization beyond Mapkick's API.
```javascript
getMapObject()
```
```javascript
const areaMap = new Mapkick.AreaMap("map", data)
const glMap = areaMap.getMapObject()
glmMap.setPaintProperty("objects", "fill-opacity", 0.5)
```
--------------------------------
### API Development Reference
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/DELIVERY_SUMMARY.md
Reference specific documentation files for API development, including class/method signatures, data structures, configuration options, and error handling.
```bash
Reference:
- api-reference-*.md for class/method signatures
- types.md for data structures
- configuration.md for all options
- errors.md for error handling
```
--------------------------------
### Mapkick.js Missing Longitude Error Example
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/errors.md
Illustrates data that triggers a 'missing longitude' error. Use any longitude alias (longitude, lon, lng) for correct data.
```javascript
// Error at index 0
new Mapkick.Map("map", [
{latitude: 37.7829} // missing longitude
])
// Correct: use any alias
[
{latitude: 37.7829, longitude: -122.4190},
{lat: 37.8000, lon: -122.4200},
{latitude: 37.9000, lng: -122.4300}
]
```
--------------------------------
### Create a Simple Map
Source: https://github.com/ankane/mapkick.js/blob/master/examples/index.html
Instantiate a basic map with a single data point. Ensure the target element ID exists in your HTML.
```javascript
new Mapkick.Map("simple", [{latitude: 37.7829, longitude: -122.4190, tooltip: "Hello"}]);
```
--------------------------------
### Valid Color Formats in Mapkick.js
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/errors.md
Examples of valid color formats accepted by Mapkick.js, including 3-digit and 6-digit hex codes, and standard CSS color names.
```javascript
// Valid hex colors
{color: "#f84d4d"} // 6-digit
{color: "#f8d"} // 3-digit shorthand
{color: "#F84D4D"} // uppercase OK
// Valid CSS color names
{color: "red"}
{color: "darkblue"}
{color: "transparent"}
```
--------------------------------
### Map Constructor
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/api-reference-map.md
Initializes a new Mapkick.Map instance. This is the primary way to create and render a map on your webpage.
```APIDOC
## Map Constructor
### Description
Initializes a new Mapkick.Map instance.
### Signature
```javascript
new Mapkick.Map(element, data, options)
```
### Parameters
#### Path Parameters
- **element** (string | HTMLElement) - Required - DOM element ID or reference where the map will be rendered
- **data** (array | string | function) - Required - Map data: array of point objects, URL returning JSON, or callback function
- **options** (object) - Optional - Configuration object for the map instance
### Return Type
Returns a `Map` instance with methods to interact with the map.
### Throws
- **Error** "No element with id {elementId}" — if element is a string ID but no DOM element with that ID exists
- **Error** "No mapping library found" — if neither Mapbox GL JS nor MapLibre GL JS is loaded
- **Error** "Invalid color" — if marker color is not a valid hex color (#RGB or #RRGGBB) or CSS color name
- **Error** "missing latitude (index: {i})" — if latitude is missing from a point at the specified index
- **Error** "missing longitude (index: {i})" — if longitude is missing from a point at the specified index
### Examples
```javascript
// Basic point map
new Mapkick.Map("map", [
{latitude: 37.7829, longitude: -122.4190},
{latitude: 40.7128, longitude: -74.0060}
])
// Map with custom styling
new Mapkick.Map("map", [
{
latitude: 37.7829,
longitude: -122.4190,
label: "San Francisco",
tooltip: "5-star restaurant",
color: "#f84d4d",
icon: "restaurant"
}
], {
style: "mapbox://styles/mapbox/dark-v11",
zoom: 12,
controls: true
})
// Map from URL
new Mapkick.Map("map", "/api/locations")
// Map from callback
new Mapkick.Map("map", function(success, fail) {
fetch("/api/locations")
.then(r => r.json())
.then(success)
.catch(() => fail("Unable to fetch locations"))
})
// Live-updating map with trails
new Mapkick.Map("map", "/api/vehicles", {
refresh: 10,
trail: {len: 20}
})
// Replay historical data
new Mapkick.Map("map", [
{id: "bus-1", lat: 37.7829, lon: -122.4190, time: "2024-01-01T10:00:00Z"},
{id: "bus-1", lat: 37.7830, lon: -122.4191, time: "2024-01-01T10:01:00Z"}
], {replay: true})
```
```
--------------------------------
### Map Constructor
Source: https://github.com/ankane/mapkick.js/blob/master/_autodocs/README.md
Initializes a new Map object. This is the primary way to create a map instance.
```APIDOC
## Map(element, data, options)
### Description
Initializes a new Map object.
### Parameters
- **element** (HTMLElement | string) - The DOM element or its ID where the map will be rendered.
- **data** (Array