I have a VectorLayer over my OSM and I have successfully plotted a polygon on my Map.However what is happening is that the polygon is getting too large in size as I zoom in or getting small in size as I zoom out. Is there a way to keep the size of the polygon independent of zoom?
Here is my code for plotting the circle
map = new OpenLayers.Map("container");
var mapnik = new OpenLayers.Layer.OSM();
epsg4326 = new OpenLayers.Projection("EPSG:4326");
var zoom = 6;
map.addLayer(mapnik);
map.addControl(new OpenLayers.Control.DragPan());
projectTo = map.getProjectionObject();
var lonLat = new OpenLayers.LonLat(-82.56,43.67611).transform(epsg4326, projectTo);
map.setCenter(lonLat, zoom);
var styleMap = new OpenLayers.StyleMap(OpenLayers.Util.applyDefaults(
{fillColor: "black", fillOpacity: 0.5, strokeColor: "black"},
OpenLayers.Feature.Vector.style["default"]));
var vectorLayer = new OpenLayers.Layer.Vector("Overlay", {styleMap: styleMap});
var point = new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat);
var mycircle = OpenLayers.Geometry.Polygon.createRegularPolygon
(
point,
50000,
50,
0
);
var featurecircle = new OpenLayers.Feature.Vector(mycircle);
vectorLayer.addFeatures([featurecircle]);
map.addLayer(vectorLayer);
Related
I am new into OpenLayers and setting my hands on it. I have added baselayer (osm). But i have noticed that the OpenLayers base layer is not as smooth as org.com. When I try to zoom in and out there is step zooming and osm.org has just 18 zoom level and OpenLayers has more than that. I want exact same smoothness and less zoom level.
var gridsetName = "EPSG:900913";
var gridNames = ['EPSG:900913:0', 'EPSG:900913:1', 'EPSG:900913:2', 'EPSG:900913:3', 'EPSG:900913:4', 'EPSG:900913:5', 'EPSG:900913:6', 'EPSG:900913:7', 'EPSG:900913:8', 'EPSG:900913:9', 'EPSG:900913:10', 'EPSG:900913:11', 'EPSG:900913:12', 'EPSG:900913:13', 'EPSG:900913:14', 'EPSG:900913:15', 'EPSG:900913:16', 'EPSG:900913:17', 'EPSG:900913:18', 'EPSG:900913:19', 'EPSG:900913:20', 'EPSG:900913:21', 'EPSG:900913:22', 'EPSG:900913:23', 'EPSG:900913:24', 'EPSG:900913:25', 'EPSG:900913:26', 'EPSG:900913:27', 'EPSG:900913:28', 'EPSG:900913:29', 'EPSG:900913:30'];
var baseUrl = "http://localhost:8080/geoserver/gwc/service/wmts";
var style = "";
var format = "application/vnd.mapbox-vector-tile";
var projection = new Projection({
code: "EPSG:900913",
units: "m",
axisOrientation: "neu",
});
var layerCache = {};
var resolutions = [156543.03390625, 78271.516953125, 39135.7584765625, 19567.87923828125, 9783.939619140625, 4891.9698095703125, 2445.9849047851562, 1222.9924523925781, 611.4962261962891, 305.74811309814453, 152.87405654907226, 76.43702827453613, 38.218514137268066, 19.109257068634033, 9.554628534317017, 4.777314267158508, 2.388657133579254, 1.194328566789627, 0.5971642833948135, 0.2985821416974068, 0.1492910708487034, 0.0746455354243517, 0.0373227677121758, 0.0186613838560879, 0.009330691928044, 0.004665345964022, 0.002332672982011, 0.0011663364910055, 5.831682455027E-4, 2.915841227514E-4, 1.457920613757E-4];
var view = new View({
center: [0, 0],
zoom: 2,
resolution: resolutions,
projection: projection,
extent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
});
var map = new Map({
layers: [
new TileLayer({
preload: Infinity,
source: new OSM({ cacheSize: 20000 }),
}),
],
target: "map",
loadTilesWhileAnimating: true,
loadTilesWhileInteracting: true,
view: view,
});
map
.getView()
.fit([-20037508.34, -20037508.34, 20037508.34, 20037508.34], map.getSize());
To restrict the zoom to 18 levels you will need to specify maxZoom in the view options, and in OpenLayers 6 you will need to specify multiWorld: true to get to zoom 0. You can also constrain to integer zoom levels, etc.
var view = new View({
center: [0, 0],
zoom: 2,
maxZoom: 18,
multiWorld: true,
constrainResolution: true,
smoothResolutionConstraint: false,
});
You can also set options for the map interactions to vary the duration of the zoom animation, for example:
interactions: defaultInteractions({zoomDuration: 100}),
I'm coding a terrain generator in Godot. I generate the Mesh using SurfaceTool and triangle strips. The geometry works fine — but the UV mapping doesn't, as each triangle repeats the texture instead of the full mesh covering the texture once:
Normalizing the UV-Coordinates to fit into the 0,0 - 1,1 dimensions is what should work, but doesn't, as it makes only one pair of triangles have the full texture and the rest is blank:
extends MeshInstance
export var terrain_width = 16
export var terrain_depth = 16
export var terrain_height = 1
export var terrain_scale = 1
#Noise Generation
var terrain_noise = OpenSimplexNoise.new()
var terrain_heightmap = ImageTexture.new()
var terrain_texture = Texture.new()
var terrain_material = SpatialMaterial.new()
var terrain_mesh = Mesh.new()
var surfacetool = SurfaceTool.new()
func _ready():
generate_heightmap()
generate_mesh()
func generate_heightmap():
#Setup the noise
terrain_noise.seed = randi()
terrain_noise.octaves = 4
terrain_noise.period = 20.0
terrain_noise.persistence = 0.8
#Make the texture
terrain_heightmap.create_from_image(terrain_noise.get_image(terrain_width+1, terrain_depth+1))
terrain_texture = terrain_heightmap
func generate_mesh():
#Set the material texture to the heightmap
terrain_material.albedo_texture = terrain_texture
# This is where the uv-mapping occurs, via the add_uv function
for z in range(0,terrain_depth):
surfacetool.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
for x in range(0,terrain_width):
surfacetool.add_uv(Vector2((terrain_width-x)/terrain_width,z/terrain_depth))
surfacetool.add_vertex(Vector3((terrain_width-x)*terrain_scale, terrain_noise.get_noise_2d(x,z)*terrain_height*terrain_scale, z*terrain_scale))
surfacetool.add_uv(Vector2((terrain_width-x)/terrain_width,(z+1)/terrain_depth))
surfacetool.add_vertex(Vector3((terrain_width-x)*terrain_scale, terrain_noise.get_noise_2d(x,z+1)*terrain_height*terrain_scale, (z+1)*terrain_scale))
surfacetool.generate_normals()
surfacetool.index()
surfacetool.commit(terrain_mesh)
#Set the texture and mesh on the MeshInstance
self.material_override = terrain_material
self.set_mesh(terrain_mesh)
self.set_surface_material(0, terrain_texture)
I expect each triangle to cover only the corresponding coordinates in the texture.
It seems as if each triangle is considered as a separate surface.
You have lots of integer divisions there. There are many ways to fix that. Here's a quick one: Just add .0 after your exported variable's default values:
export var terrain_width = 16.0
export var terrain_depth = 16.0
export var terrain_height = 1.0
export var terrain_scale = 1.0
And here's a more explicit way:
export(float) var terrain_width = 16
export(float) var terrain_depth = 16
export(float) var terrain_height = 1
export(float) var terrain_scale = 1
Assuming you don't have any other bugs, this should fix the issue.
new to createjs here:
Created this fiddle: example. I would like the rect to grow from the center and not from the top left corner. I couldn't find any help, I don't know what to search for.
Code:
const PAGE_WIDTH = 150,
PAGE_HEIGHT = 75;
var stage = new createjs.Stage("canvas");
createjs.Ticker.setFPS(60);
createjs.Ticker.on("tick", tick);
var page = new createjs.Shape();
page.regX = PAGE_WIDTH/2;
page.regY = PAGE_HEIGHT/2;
page.x = 50;
page.y = 50;
stage.addChild(page);
var pageCommand = page.graphics
.beginFill('red')
.drawRect(0, 0, 1, 1).command;
createjs.Tween.get(pageCommand)
.to({w:PAGE_WIDTH, h: PAGE_HEIGHT}, 700, createjs.Ease.elasticOut)
function tick() {
stage.update();
}
Thanks.
The best way is to change the registration point of your graphics so it grows from the center.
Your code:
.drawRect(0, 0, 1, 1).command;
.to({w:PAGE_WIDTH, h: PAGE_HEIGHT})
Instead:
.drawRect(-1.-1, 2, 2);
.to({x:-PAGE_WIDTH/2, y:-PAGE_WIDTH/2, w:PAGE_WIDTH, h: PAGE_HEIGHT})
Fiddle: http://jsfiddle.net/1kjkqo2v/
[edit: I said 2 options initially, but the second (using regX and regY) wouldn't work well, since you have to tween that value as well as your size changes.]
The code below is what I am using. Basically modified from the polygons I was drawing, but the lines arent showing up...
// Construct the Venue Line.
theVenue = new google.maps.LineString({
paths: outlineCoords,
strokeColor: '#ffba20',
strokeOpacity: 1,
strokeWeight: 2,
fillColor: '#ffba20',
fillOpacity: 1
});
// ...
theVenue.setMap(map);
// outline the venue
var theVenue;
// Define the LatLng coordinates for the polygon's path.
var outlineCoords = [new google.maps.LatLng(39.9066747476479, -75.2781808376312),
new google.maps.LatLng(39.9083124955562, -75.2793931961059),
new google.maps.LatLng(39.910123025565, -75.2808094024658),
How to draw a triangle in a math graph which displays X and Y axis.
To draw shapes using ActionScript2, you can use the moveTo() and lineTo() methods of the MovieClip object. You can specify line colour and thickness with lineStyle(), or make a solid shape using beginFill() and endFill().
So to draw your graph and triangle you could do the following steps:
Make a movieClip named "graph"
Define how big your graph should be (using the flash.geom.Rectangle object)
Draw a grey background using graph.beginFill(grey) and then moveTo() and lineTo()
Draw some blue lines at regular intervals for a grid
Draw the X and Y axes on the side and bottom of your grid
Make a second movieClip named "shape"
Pick 3 random points: moveTo(point1), lineTo(point2), lineTo(point3), lineTo(point1)
Here's how the code might look:
import flash.geom.Point;
import flash.geom.Rectangle;
function drawGraph(mc:MovieClip, rect:Rectangle):Void {
//this is a function to draw the graph
//draw the background
mc.beginFill(0xF8F8F8);
mc.moveTo(rect.left, rect.bottom);
mc.lineTo(rect.left, rect.top);
mc.lineTo(rect.right, rect.top);
mc.lineTo(rect.right, rect.bottom);
mc.lineTo(rect.left, rect.bottom);
mc.endFill();
//draw a grid
var unit:Number = 20;
mc.lineStyle(1, 0x0000FF, 20, true, "none", "round", "round");
var i:Number=rect.x;
do {
i=i+unit;
mc.moveTo(i, rect.bottom);
mc.lineTo(i, rect.top);
} while (i<rect.right);
i=rect.bottom;
do {
i=i-unit;
mc.moveTo(rect.left, i);
mc.lineTo(rect.right,i);
} while (i>rect.top);
//draw the axes
mc.lineStyle(2, 0x808080, 100, true, "none", "round", "round");
mc.moveTo(rect.left, rect.bottom);
mc.lineTo(rect.left, rect.top);
mc.moveTo(rect.left, rect.bottom);
mc.lineTo(rect.right, rect.bottom);
}
function randomPoint(rect:Rectangle):Point {
//this is a function which returns a random point within rect
var p:Point = new Point(rect.x+Math.random()*rect.width, rect.y+Math.random()*rect.height);
return p;
}
function drawTriangle(mc:MovieClip, rect:Rectangle):Void {
//this is a function to draw the triangle
// pick 3 random points within rect
var p1:Point = randomPoint(rect);
var p2:Point = randomPoint(rect);
var p3:Point = randomPoint(rect);
//connect the points to make a triangle
mc.lineStyle(3, 0xFF0000, 100, true, "none", "round", "round");
mc.moveTo(p1.x, p1.y);
mc.lineTo(p2.x, p2.y);
mc.lineTo(p3.x, p3.y);
mc.lineTo(p1.x, p1.y);
}
//make the 'graph' clip:
var myGraph:MovieClip = this.createEmptyMovieClip("myGraph", this.getNextHighestDepth());
//define the graph size:
var myRect:Rectangle = new Rectangle(50,50,300,300);
drawGraph(myGraph,myRect);//draw the graph
var myShape:MovieClip = this.createEmptyMovieClip("myShape", this.getNextHighestDepth());//make the 'shape' clip
drawTriangle(myShape,myRect);//draw a random triangle
//add a function to draw a new triangle when the graph is clicked:
myGraph.onRelease = function() {
myShape.clear();//erase the old triangle
drawTriangle(myShape,myRect);//draw a new one
}
You can click the graph to generate a new random triangle.
(source: webfactional.com)
It sounds like you need to know how the drawing API works in Flash. Your question is kind of vague, but this might help to get you started - google "Flash Drawing API" for more information.
var point1:Point = new Point (0, 0);
var point2:Point = new Point (25, -50);
var point3:Point = new Point (50, 0);
var s:Sprite = new Sprite();
s.graphics.lineStyle(1, 0xff0000);
s.graphics.beginFill(0x000000);
s.graphics.moveTo(point1.x, point1.y);
s.graphics.lineTo(point2.x, point2.y);
s.graphics.lineTo(point3.x, point3.y);
s.graphics.lineTo(point1.x, point1.y);
s.graphics.endFill();
s.graphics.lineStyle(0);
s.x = (stage.stageWidth - s.width) / 2;
s.y = ((stage.stageHeight - s.height) / 2) + 50;
addChild(s);
I hope that helps, let me know if you have any questions.
NOTE: This solution is using ActionScript 3. If you need AS2 this won't work, and off the top of my head I don't know how to help but you might just try googling "AS2 Drawing API" or something to that effect.