OCAD Internet Map scripting

From OCAD 12 Wiki - English
Revision as of 12:06, 6 June 2012 by Mfw (talk | contribs) (Created page with "OCAD Internet Map can be custom scripted with addition JavaScript code. ==Hide/Show layers== Layers can be shown or hidden with the layer command setVisibility. All Layers ar...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

OCAD Internet Map can be custom scripted with addition JavaScript code.

Hide/Show layers

Layers can be shown or hidden with the layer command setVisibility. All Layers are expored in the order they are shown in the _poiLayers array.

Example:

	function ShowLayer() {
		_poiLayers[0].setVisibility(true);
	}

	function HideLayer() {
		_poiLayers[0].setVisibility(false);
	}

The Javascript functions can be called with an external link from the same page.

Jump to a certain point

In order to go to a certain location on the map the following function can be called.

	
        function JupToPointOfInterest() {
		var point = new OpenLayers.LonLat(136733, 6667650);
		map.zoomTo(map.numZoomLevels-1);
		map.panTo(point);
	}

The variable map.numZoomLevels must always be decreased by one in order to get the maximum zoom level.

Add additional vector points for locations

In order to achieve additional vector points this can be done with

	function ShowPointOfInterest() {
		var point1 = new OpenLayers.Geometry.Point(149667,6680327);
		var point2 = new OpenLayers.Geometry.Point(150386,6678682);
			
		var feature_point = new OpenLayers.Feature.Vector(point1, {},{fillOpacity : 0.4, pointRadius: 45, fillColor: "#ff0000" });
		var feature_point2 = new OpenLayers.Feature.Vector(point2, {},{pointRadius: 15, fillColor: "#ff0000"});
		
		highlight_layer.addFeatures([feature_point, feature_point2]);
	}

Therefore an additional layer must be introduced in the init script with the following lines:

    highlight_layer = new OpenLayers.Layer.Vector('Highlight Layer');
    map.addLayer(highlight_layer);

The two lines must be placed between the "addControl" commands and "XMLInitPois" command.

For the vector styling the options can be seen in the OpenLayers documentation http://dev.openlayers.org/apidocs/files/OpenLayers/Feature/Vector-js.html#OpenLayers.Feature.Vector.style